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 notes = ref.model(NoteModel.collection())..load();
  final adapter =
      MasamuneAdapterScope.of<SimpleBlogModuleMasamuneAdapter>(context);

  // Describes the structure of the page.
  return UniversalScaffold(
    appBar: UniversalAppBar(
      title: Text(adapter!.title),
      actions: [
        IconButton(
          onPressed: () async {
            await adapter.auth.signOut().showIndicator(context);
            adapter.router.resetAndPush(NotePage.query());
          },
          icon: const Icon(Icons.logout),
        ),
      ],
    ),
    body: UniversalListView(
      onRefresh: () {
        return notes.reload();
      },
      children: [
        ...notes.mapListenable(
          (item) {
            return ListTile(
              title: Text(item.value?.title ?? ""),
              subtitle: Text(
                item.value?.time.value.yyyyMMddHHmm() ?? "",
              ),
              onTap: () {
                adapter.router.push(NoteEditPage.query(editId: item.uid));
              },
            );
          },
        ),
      ],
    ),
    floatingActionButton: FloatingActionButton.extended(
      icon: const Icon(Icons.add),
      label: Text(ml().add),
      onPressed: () {
        adapter.router.push(NoteAddPage.query());
      },
    ),
  );
}