From 55957b04db37bbb482a71ba535c6e6bf17739fd4 Mon Sep 17 00:00:00 2001 From: Marco Date: Sun, 17 Mar 2024 18:38:57 +0100 Subject: [PATCH] Set groundwork for persisting notes --- lib/main.dart | 8 ++++++-- lib/persistence_bloc.dart | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 lib/persistence_bloc.dart diff --git a/lib/main.dart b/lib/main.dart index 95dc1fb..95ad6f6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:fnotes/notes.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:fnotes/persistence_bloc.dart'; import 'package:fnotes/theme_bloc.dart'; void main() { @@ -12,8 +13,11 @@ class MainApp extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocProvider( - create: (context) => ThemeBloc(), + return MultiBlocProvider( + providers: [ + BlocProvider(create: (context) => ThemeBloc()), + BlocProvider(create: (context) => PersistenceBloc()) + ], child: BlocBuilder( builder: (context, state) { return MaterialApp( diff --git a/lib/persistence_bloc.dart b/lib/persistence_bloc.dart new file mode 100644 index 0000000..539536c --- /dev/null +++ b/lib/persistence_bloc.dart @@ -0,0 +1,27 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; + +class PersistenceBloc extends Bloc { + PersistenceBloc() : super(PersistenceState.init()) { + on(storeAllNotes); + on(loadAllNotes); + } + + void storeAllNotes(PersistenceEvent event, Emitter emit) {} + void loadAllNotes(PersistenceEvent event, Emitter emit) {} +} + +class PersistenceEvent {} + +class LoadNotesEvent extends PersistenceEvent {} + +class StoreNotesEvent extends PersistenceEvent {} + +class PersistenceState { + int lastIndex; + + PersistenceState({required this.lastIndex}); + + factory PersistenceState.init() { + return PersistenceState(lastIndex: 0); + } +}