build method

  1. @override
Widget build(
  1. BuildContext context,
  2. PageRef ref
)
override

Build the internal widget.

The context used during the build is passed as is.

Also, WidgetRef is passed to ref to update the state.

内部のウィジェットをビルドします。

ビルド中に使用されるcontextがそのまま渡されます。

また、refに状態を更新するためのPageRefが渡されます。

Implementation

@override
Widget build(BuildContext context, PageRef ref) {
  // Describes the process of loading
  // and defining variables required for the page.
  final read = appPrefs.read.get();
  final notes = ref.model(NoteModel.collection())..load();
  final adapter =
      MasamuneAdapterScope.of<SimpleBlogModuleMasamuneAdapter>(context);

  ref.page.on(initOrUpdate: () async {
    await notes.loading;
    final unread = notes.where((e) => !read.contains(e.uid)).toList();
    if (unread.isNotEmpty) {
      // ignore: use_build_context_synchronously
      Modal.alert(
        context,
        submitText: ml().ok,
        title: ml().confirmation,
        text: ml()
            .thereAre
            .$(unread.length)
            .unread
            .$(adapter?.words.article ?? ml().article),
      );
    }
  });

  // Describes the structure of the page.
  return UniversalScaffold(
    appBar: UniversalAppBar(
      title: Text(adapter!.title),
      actions: [
        IconButton(
          onPressed: () {
            adapter.router.push(AdminPage.query());
          },
          icon: const Icon(Icons.settings),
        )
      ],
    ),
    body: FutureBuilder(
      future: notes.loading,
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.waiting) {
          return const Center(
            child: CircularProgressIndicator(),
          );
        }

        return UniversalListView(
          onRefresh: () {
            return notes.reload();
          },
          children: [
            ...notes.mapListenable(
              (item) {
                return ListTile(
                  title: Text(item.value?.title ?? ""),
                  subtitle: Text(
                    item.value?.time.value.yyyyMMddHHmm() ?? "",
                  ),
                  trailing: read.contains(item.uid)
                      ? Icon(
                          Icons.check_circle,
                          color: adapter.theme?.color.primary ??
                              Theme.of(context).colorScheme.primary,
                        )
                      : null,
                  onTap: () {
                    context.router
                        .push(NoteDetailPage.query(viewId: item.uid));
                  },
                );
              },
            ),
          ],
        );
      },
    ),
  );
}