diff --git a/lib/database.dart b/lib/database.dart index 31471f5..afa006a 100644 --- a/lib/database.dart +++ b/lib/database.dart @@ -8,6 +8,8 @@ import 'package:sqlite3_flutter_libs/sqlite3_flutter_libs.dart'; part 'database.g.dart'; +var database = AppDatabase(); //global, since we should only use one instance + class PersistentNote extends Table { TextColumn get id => text()(); TextColumn get content => text()(); diff --git a/lib/main.dart b/lib/main.dart index e8becf4..d58b464 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,9 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:fnotes/database.dart'; import 'package:fnotes/notes_app.dart'; import 'package:fnotes/persistent_notes_bloc.dart'; import 'package:fnotes/theme_bloc.dart'; +var database = AppDatabase(); + void main() { WidgetsFlutterBinding.ensureInitialized(); //for drift runApp(const MainApp()); @@ -17,7 +20,7 @@ class MainApp extends StatelessWidget { return MultiBlocProvider( providers: [ BlocProvider(create: (context) => ThemeBloc()), - BlocProvider(create: (context) => PersistentNotesBloc()) + BlocProvider(create: (context) => PersistentNotesBloc()), ], child: BlocBuilder( builder: (context, state) { diff --git a/lib/persistent_notes_bloc.dart b/lib/persistent_notes_bloc.dart index 2172aee..f7b4464 100644 --- a/lib/persistent_notes_bloc.dart +++ b/lib/persistent_notes_bloc.dart @@ -4,8 +4,6 @@ import 'package:fnotes/note.dart'; class PersistentNotesBloc extends Bloc { - static final database = AppDatabase(); - PersistentNotesBloc() : super(PersistentNotesState.init()) { on(loadAllNotes); on(storeNote); diff --git a/lib/theme_bloc.dart b/lib/theme_bloc.dart index 9640687..3d2c23e 100644 --- a/lib/theme_bloc.dart +++ b/lib/theme_bloc.dart @@ -4,8 +4,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fnotes/database.dart'; class ThemeBloc extends Bloc { - static final database = AppDatabase(); - ThemeBloc() : super(ThemeState.init()) { on(switchTheme); on(loadTheme); diff --git a/pubspec.lock b/pubspec.lock index 831f385..4241fa3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -513,7 +513,7 @@ packages: source: hosted version: "1.5.1" provider: - dependency: transitive + dependency: "direct main" description: name: provider sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c diff --git a/pubspec.yaml b/pubspec.yaml index b52d3a0..0ace492 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,6 +17,7 @@ dependencies: sqlite3_flutter_libs: ^0.5.20 uuid: ^4.3.3 sqlite3: ^2.4.0 + provider: ^6.1.2 dev_dependencies: flutter_test: