Set groundwork for persisting notes

This commit is contained in:
Marco 2024-03-17 18:38:57 +01:00
parent 12940beab7
commit 55957b04db
2 changed files with 33 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fnotes/notes.dart'; import 'package:fnotes/notes.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fnotes/persistence_bloc.dart';
import 'package:fnotes/theme_bloc.dart'; import 'package:fnotes/theme_bloc.dart';
void main() { void main() {
@ -12,8 +13,11 @@ class MainApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider( return MultiBlocProvider(
create: (context) => ThemeBloc(), providers: [
BlocProvider(create: (context) => ThemeBloc()),
BlocProvider(create: (context) => PersistenceBloc())
],
child: BlocBuilder<ThemeBloc, ThemeState>( child: BlocBuilder<ThemeBloc, ThemeState>(
builder: (context, state) { builder: (context, state) {
return MaterialApp( return MaterialApp(

27
lib/persistence_bloc.dart Normal file
View File

@ -0,0 +1,27 @@
import 'package:flutter_bloc/flutter_bloc.dart';
class PersistenceBloc extends Bloc<PersistenceEvent, PersistenceState> {
PersistenceBloc() : super(PersistenceState.init()) {
on<StoreNotesEvent>(storeAllNotes);
on<LoadNotesEvent>(loadAllNotes);
}
void storeAllNotes(PersistenceEvent event, Emitter<PersistenceState> emit) {}
void loadAllNotes(PersistenceEvent event, Emitter<PersistenceState> 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);
}
}