fnotes/lib/main.dart
Marco a52a50d4d1 Persist theme
Persist theme in sqlite database.
A new table was created for this.

Add migration to add table for persisted theme
2024-04-04 20:38:12 +02:00

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(),
);
},
),
);
}
}