Marco
a52a50d4d1
Persist theme in sqlite database. A new table was created for this. Add migration to add table for persisted theme
39 lines
1.1 KiB
Dart
39 lines
1.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:fnotes/notes_app.dart';
|
|
import 'package:fnotes/persisted_brightness.dart';
|
|
import 'package:fnotes/persistent_notes_bloc.dart';
|
|
import 'package:fnotes/theme_bloc.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized(); //for drift
|
|
|
|
PersistedBrightness persistedBrightness =
|
|
await PersistedThemeBloc.getPersistedBrightness();
|
|
|
|
runApp(MainApp(brightness: persistedBrightness.toFlutterBrightness()));
|
|
}
|
|
|
|
class MainApp extends StatelessWidget {
|
|
final Brightness brightness;
|
|
const MainApp({super.key, required this.brightness});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MultiBlocProvider(
|
|
providers: [
|
|
BlocProvider(create: (context) => PersistedThemeBloc(brightness)),
|
|
BlocProvider(create: (context) => PersistentNotesBloc()),
|
|
],
|
|
child: BlocBuilder<PersistedThemeBloc, ThemeState>(
|
|
builder: (context, state) {
|
|
return MaterialApp(
|
|
theme: state.theme,
|
|
home: const NotesApp(),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|