♿ Make theme switcher easier to use
This commit is contained in:
30
lib/providers/theme_switcher.dart
Normal file
30
lib/providers/theme_switcher.dart
Normal file
@ -0,0 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:solian/theme.dart';
|
||||
|
||||
class ThemeSwitcher extends ChangeNotifier {
|
||||
ThemeData lightThemeData;
|
||||
ThemeData darkThemeData;
|
||||
|
||||
ThemeSwitcher({
|
||||
required this.lightThemeData,
|
||||
required this.darkThemeData,
|
||||
});
|
||||
|
||||
Future<void> restoreTheme() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (prefs.containsKey('global_theme_color')) {
|
||||
final value = prefs.getInt('global_theme_color')!;
|
||||
final color = Color(value);
|
||||
lightThemeData = SolianTheme.build(Brightness.light, seedColor: color);
|
||||
darkThemeData = SolianTheme.build(Brightness.dark, seedColor: color);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void setTheme(ThemeData light, dark) {
|
||||
lightThemeData = light;
|
||||
darkThemeData = dark;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user