import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:teso/util/consts.dart'; class AppProvider extends ChangeNotifier { AppProvider() { checkTheme(); } ThemeData theme = Constants.lightTheme; Key key = UniqueKey(); GlobalKey navigatorKey = GlobalKey(); void setKey(value) { key = value; notifyListeners(); } void setNavigatorKey(value) { navigatorKey = value; notifyListeners(); } void setTheme(value, c) { theme = value; SharedPreferences.getInstance().then((prefs) { prefs.setString("theme", c).then((val) { SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values); SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( statusBarColor: c == "dark" ? Constants.darkPrimary : Constants.lightPrimary, statusBarIconBrightness: c == "dark" ? Brightness.light : Brightness.dark, )); }); }); notifyListeners(); } ThemeData getTheme(value) { return theme; } Future checkTheme() async { SharedPreferences prefs = await SharedPreferences.getInstance(); ThemeData t; String r = prefs.getString("theme") == null ? "light" : prefs.getString("theme"); if (r == "light") { t = Constants.lightTheme; setTheme(Constants.lightTheme, "light"); } else { t = Constants.darkTheme; setTheme(Constants.darkTheme, "dark"); } return t; } }