fnotes/lib/main.dart

39 lines
1.1 KiB
Dart
Raw Permalink Normal View History

2024-03-17 13:15:50 +00:00
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';
2024-03-17 13:15:50 +00:00
import 'package:fnotes/theme_bloc.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized(); //for drift
PersistedBrightness persistedBrightness =
await PersistedThemeBloc.getPersistedBrightness();
runApp(MainApp(brightness: persistedBrightness.toFlutterBrightness()));
2024-03-17 13:15:50 +00:00
}
class MainApp extends StatelessWidget {
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: [
BlocProvider(create: (context) => PersistedThemeBloc(brightness)),
BlocProvider(create: (context) => PersistentNotesBloc()),
2024-03-17 17:38:57 +00:00
],
child: BlocBuilder<PersistedThemeBloc, ThemeState>(
2024-03-17 13:15:50 +00:00
builder: (context, state) {
return MaterialApp(
theme: state.theme,
home: const NotesApp(),
2024-03-17 13:15:50 +00:00
);
},
),
);
}
}