12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import 'package:flutter/material.dart';
- import '../common/LocalData.dart';
- class ThemeProvider extends ChangeNotifier {
- int? currentIndex;
- MaterialColor? currentMaterialColor;
- Brightness? currentBrightness;
- late List<Color> otherColors;
- ThemeProvider() {
- currentIndex = 0;
- currentMaterialColor = Colors.amber;
- currentBrightness = Brightness.light;
- otherColors = [];
- }
- void init() {
- int? index = LocalData.getInstance()!.getInt("theme");
- if (index == null) {
- index = 0;
- LocalData.getInstance()!.setInt("theme", index);
- }
- changeTheme(index);
- debugPrint(
- "init ThemeProvider to: $currentMaterialColor, $currentBrightness");
- }
- void changeTheme(int index) {
- if (index == themeColors.length) {
- currentMaterialColor = Colors.teal;
- currentBrightness = Brightness.dark;
- } else {
- currentMaterialColor = themeColors[index];
- currentBrightness = Brightness.light;
- }
- currentIndex = index;
- LocalData.getInstance()!.setInt("theme", index);
- otherColors = List<Color>.of(themeColors);
- otherColors.remove(currentMaterialColor);
- notifyListeners();
- }
- }
- List<MaterialColor> themeColors = [
- Colors.amber,
- Colors.pink,
- Colors.green,
- Colors.purple,
- Colors.blue,
- Colors.cyan,
- Colors.brown,
- ];
|