main.dart 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import 'package:dynamic_theme/dynamic_theme.dart';
  2. import 'package:flutter/material.dart';
  3. import 'data/theme.dart';
  4. import 'screens/home.dart';
  5. /// Initializes flutter and starts app
  6. void main() {
  7. WidgetsFlutterBinding.ensureInitialized();
  8. setThemeAndRun();
  9. }
  10. /// Loads app theme and runs the app
  11. setThemeAndRun() async {
  12. TupleTheme savedTheme = (await getCurrentTheme());
  13. print("setTheme home " + savedTheme.name);
  14. runApp(MyApp(
  15. theme: savedTheme.theme,
  16. ));
  17. }
  18. /// Main app class
  19. class MyApp extends StatefulWidget {
  20. final ThemeData theme;
  21. MyApp({Key key, this.theme}) : super(key: key);
  22. @override
  23. _AppState createState() => _AppState(theme);
  24. }
  25. /// State for main class
  26. class _AppState extends State<MyApp> {
  27. _AppState(ThemeData theme) {
  28. chosenTheme = theme;
  29. }
  30. ThemeData chosenTheme;
  31. @override
  32. void initState() {
  33. super.initState();
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. return DynamicTheme(
  38. defaultBrightness: chosenTheme.brightness,
  39. data: (brightness) => chosenTheme,
  40. themedWidgetBuilder: (context, theme) {
  41. return new MaterialApp(
  42. title: 'Notes app',
  43. theme: theme,
  44. home: HomeScreen(),
  45. );
  46. });
  47. }
  48. }