buildView method

  1. @override
Widget buildView(
  1. BuildContext context,
  2. HomeUIState state,
  3. HomeUIStateNotifier notifier
)
override

Implementation

@override
Widget buildView(
  BuildContext context,
  HomeUIState state,
  HomeUIStateNotifier notifier,
) {
  return Scaffold(
    appBar: AppBar(
      title: const AppText.large('FSA Todo List'),
    ),
    body: state.when(
      initial: () => Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const AppText.medium('No todos loaded.'),
            const SizedBox(height: 16),
            AppButton.primary(
              label: 'Fetch from Repository',
              onPressed: notifier.fetchTodos,
            ),
          ],
        ),
      ),
      loading: () => const Center(child: CircularProgressIndicator()),
      error: (message) => Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            AppText.medium('Error: $message'),
            const SizedBox(height: 16),
            AppButton.primary(label: 'Retry', onPressed: notifier.fetchTodos),
          ],
        ),
      ),
      success: (todos) => ListView.separated(
        itemCount: todos.length,
        separatorBuilder: (context, index) => const Divider(height: 1),
        itemBuilder: (context, index) {
          final todo = todos[index];
          return TodoTile(
            todo: todo,
            onToggle: () => notifier.toggleTodo(todo.id),
            onTap: () => AppRoute.details.push(context, arguments: todo),
          );
        },
      ),
    ),
    floatingActionButton: state.maybeWhen(
      success: (_) => FloatingActionButton(
        onPressed: () => AddTodoDialog.show(context, notifier),
        child: const Icon(Icons.add),
      ),
      orElse: () => null,
    ),
  );
}