You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.6 KiB
63 lines
1.6 KiB
3 years ago
|
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<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||
|
|
||
|
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<ThemeData> 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;
|
||
|
}
|
||
|
}
|