2024-03-17 13:15:50 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2024-03-29 12:52:28 +00:00
|
|
|
import 'package:fnotes/notes_app.dart';
|
2024-04-04 16:29:09 +00:00
|
|
|
import 'package:fnotes/persisted_brightness.dart';
|
|
|
|
import 'package:fnotes/persistent_notes_bloc.dart';
|
2024-03-17 13:15:50 +00:00
|
|
|
import 'package:fnotes/theme_bloc.dart';
|
|
|
|
|
2024-04-04 16:29:09 +00:00
|
|
|
void main() async {
|
2024-03-29 12:52:28 +00:00
|
|
|
WidgetsFlutterBinding.ensureInitialized(); //for drift
|
2024-04-04 16:29:09 +00:00
|
|
|
|
|
|
|
PersistedBrightness persistedBrightness =
|
|
|
|
await PersistedThemeBloc.getPersistedBrightness();
|
|
|
|
|
|
|
|
runApp(MainApp(brightness: persistedBrightness.toFlutterBrightness()));
|
2024-03-17 13:15:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MainApp extends StatelessWidget {
|
2024-04-04 16:29:09 +00:00
|
|
|
final Brightness brightness;
|
|
|
|
const MainApp({super.key, required this.brightness});
|
2024-03-17 13:15:50 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-03-17 17:38:57 +00:00
|
|
|
return MultiBlocProvider(
|
|
|
|
providers: [
|
2024-04-04 16:29:09 +00:00
|
|
|
BlocProvider(create: (context) => PersistedThemeBloc(brightness)),
|
|
|
|
BlocProvider(create: (context) => PersistentNotesBloc()),
|
2024-03-17 17:38:57 +00:00
|
|
|
],
|
2024-04-04 16:29:09 +00:00
|
|
|
child: BlocBuilder<PersistedThemeBloc, ThemeState>(
|
2024-03-17 13:15:50 +00:00
|
|
|
builder: (context, state) {
|
|
|
|
return MaterialApp(
|
|
|
|
theme: state.theme,
|
2024-03-29 12:52:28 +00:00
|
|
|
home: const NotesApp(),
|
2024-03-17 13:15:50 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|