2024-06-19 19:31:18 +02:00
|
|
|
import 'package:cofounderella/constants.dart';
|
2024-04-30 19:25:16 +02:00
|
|
|
import 'package:cofounderella/themes/dark_mode.dart';
|
|
|
|
import 'package:cofounderella/themes/light_mode.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2024-06-19 19:31:18 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2024-04-30 19:25:16 +02:00
|
|
|
|
|
|
|
class ThemeProvider extends ChangeNotifier {
|
2024-06-19 19:31:18 +02:00
|
|
|
ThemeData _themeData;
|
|
|
|
|
|
|
|
ThemeProvider({required bool initialIsDarkMode})
|
|
|
|
: _themeData = initialIsDarkMode ? darkMode : lightMode;
|
2024-04-30 19:25:16 +02:00
|
|
|
|
|
|
|
ThemeData get themeData => _themeData;
|
|
|
|
|
|
|
|
bool get isDarkMode => _themeData == darkMode;
|
2024-06-19 19:31:18 +02:00
|
|
|
|
2024-04-30 19:25:16 +02:00
|
|
|
set themeData(ThemeData themeData) {
|
|
|
|
_themeData = themeData;
|
|
|
|
notifyListeners();
|
2024-06-19 19:31:18 +02:00
|
|
|
_saveTheme();
|
2024-04-30 19:25:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void toggleTheme() {
|
2024-06-19 19:31:18 +02:00
|
|
|
if (_themeData == lightMode) {
|
2024-04-30 19:25:16 +02:00
|
|
|
themeData = darkMode;
|
|
|
|
} else {
|
|
|
|
themeData = lightMode;
|
|
|
|
}
|
|
|
|
}
|
2024-06-19 19:31:18 +02:00
|
|
|
|
|
|
|
void _saveTheme() async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
prefs.setBool(Constants.prefKeyThemeDarkMode, isDarkMode);
|
|
|
|
}
|
|
|
|
}
|