mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-07-29 01:08:36 -04:00
clean up build
This commit is contained in:
parent
b54868cc55
commit
5703da0802
30 changed files with 377 additions and 74 deletions
54
lib/theming/theme_service.dart
Normal file
54
lib/theming/theme_service.dart
Normal file
|
@ -0,0 +1,54 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'themes/themes.dart';
|
||||
|
||||
class ThemeService {
|
||||
ThemeService._();
|
||||
static late SharedPreferences prefs;
|
||||
static ThemeService? _instance;
|
||||
|
||||
static Future<ThemeService> get instance async {
|
||||
if (_instance == null) {
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
_instance = ThemeService._();
|
||||
}
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
final allThemes = <String, ThemeData>{
|
||||
'dark': darkTheme,
|
||||
'light': lightTheme,
|
||||
};
|
||||
|
||||
String get previousThemeName {
|
||||
String? themeName = prefs.getString('previousThemeName');
|
||||
if (themeName == null) {
|
||||
final isPlatformDark =
|
||||
WidgetsBinding.instance.window.platformBrightness == Brightness.dark;
|
||||
themeName = isPlatformDark ? 'light' : 'dark';
|
||||
}
|
||||
return themeName;
|
||||
}
|
||||
|
||||
get initial {
|
||||
String? themeName = prefs.getString('theme');
|
||||
if (themeName == null) {
|
||||
final isPlatformDark =
|
||||
WidgetsBinding.instance.window.platformBrightness == Brightness.dark;
|
||||
themeName = isPlatformDark ? 'dark' : 'light';
|
||||
}
|
||||
return allThemes[themeName];
|
||||
}
|
||||
|
||||
save(String newThemeName) {
|
||||
var currentThemeName = prefs.getString('theme');
|
||||
if (currentThemeName != null) {
|
||||
prefs.setString('previousThemeName', currentThemeName);
|
||||
}
|
||||
prefs.setString('theme', newThemeName);
|
||||
}
|
||||
|
||||
ThemeData getByName(String name) {
|
||||
return allThemes[name]!;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue