mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-08-07 05:32:26 -04:00
scaffolding
This commit is contained in:
parent
6def7a9eee
commit
c22d6fcff8
21 changed files with 1037 additions and 117 deletions
57
lib/theme/theme_service.dart
Normal file
57
lib/theme/theme_service.dart
Normal file
|
@ -0,0 +1,57 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '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,
|
||||
'pink': pinkTheme,
|
||||
'darkBlue': darkBlueTheme,
|
||||
'halloween': halloweenTheme,
|
||||
};
|
||||
|
||||
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]!;
|
||||
}
|
||||
}
|
37
lib/theme/themes.dart
Normal file
37
lib/theme/themes.dart
Normal file
|
@ -0,0 +1,37 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
ThemeData lightTheme = ThemeData.light();
|
||||
|
||||
ThemeData darkTheme = ThemeData.dark();
|
||||
|
||||
ThemeData pinkTheme = lightTheme.copyWith(
|
||||
primaryColor: const Color(0xFFF49FB6),
|
||||
scaffoldBackgroundColor: const Color(0xFFFAF8F0),
|
||||
floatingActionButtonTheme: const FloatingActionButtonThemeData(
|
||||
foregroundColor: Color(0xFF24737c),
|
||||
backgroundColor: Color(0xFFA6E0DE),
|
||||
),
|
||||
textTheme: const TextTheme(
|
||||
bodyText1: TextStyle(
|
||||
color: Colors.black87,
|
||||
),
|
||||
));
|
||||
|
||||
ThemeData halloweenTheme = lightTheme.copyWith(
|
||||
primaryColor: const Color(0xFF55705A),
|
||||
scaffoldBackgroundColor: const Color(0xFFE48873),
|
||||
floatingActionButtonTheme: const FloatingActionButtonThemeData(
|
||||
foregroundColor: Color(0xFFea8e71),
|
||||
backgroundColor: Color(0xFF2b2119),
|
||||
),
|
||||
);
|
||||
|
||||
ThemeData darkBlueTheme = ThemeData.dark().copyWith(
|
||||
primaryColor: const Color(0xFF1E1E2C),
|
||||
scaffoldBackgroundColor: const Color(0xFF2D2D44),
|
||||
textTheme: const TextTheme(
|
||||
bodyText1: TextStyle(
|
||||
color: Color(0xFF33E1Ed),
|
||||
),
|
||||
),
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue