Constant Dark Theme
This commit is contained in:
45
lib/theme_manager.dart
Normal file
45
lib/theme_manager.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:witl/storage_manager.dart';
|
||||
|
||||
class ThemeNotifier with ChangeNotifier {
|
||||
final darkTheme = ThemeData(
|
||||
primaryColor: Colors.black,
|
||||
brightness: Brightness.dark,
|
||||
dividerColor: Colors.black12, colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.grey).copyWith(background: const Color(0xFF212121)),
|
||||
);
|
||||
|
||||
final lightTheme = ThemeData(
|
||||
primaryColor: Colors.white,
|
||||
brightness: Brightness.light,
|
||||
dividerColor: Colors.white54, colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.grey).copyWith(background: const Color(0xFFE5E5E5)),
|
||||
);
|
||||
|
||||
late ThemeData _themeData;
|
||||
ThemeData getTheme() => _themeData;
|
||||
|
||||
ThemeNotifier() {
|
||||
StorageManager.readData('themeMode').then((value) {
|
||||
'value read from storage: ' + value.toString();
|
||||
var themeMode = value ?? 'light';
|
||||
if (themeMode == 'light') {
|
||||
_themeData = lightTheme;
|
||||
} else {
|
||||
'setting dark theme';
|
||||
_themeData = darkTheme;
|
||||
}
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
|
||||
void setDarkMode() async {
|
||||
_themeData = darkTheme;
|
||||
StorageManager.saveData('themeMode', 'dark');
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setLightMode() async {
|
||||
_themeData = lightTheme;
|
||||
StorageManager.saveData('themeMode', 'light');
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user