fApp/lib/providers/ThemeProvider.dart
Flummi 1cd10b3809 v1.1.5+35
- overlay buttons
- encrypted storage
- downloadbutton (wip)
2025-06-07 20:32:24 +02:00

241 lines
7.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
class ThemeNotifier extends StateNotifier<ThemeData> {
final FlutterSecureStorage secureStorage;
ThemeNotifier({required this.secureStorage}) : super(f0ckTheme) {
_loadTheme();
}
Future<void> _loadTheme() async {
String? savedThemeName = await secureStorage.read(key: 'theme');
if (savedThemeName != null) {
final customTheme = themes.firstWhere(
(t) => t.name == savedThemeName,
orElse: () => CustomTheme(name: 'f0ck', theme: f0ckTheme),
);
state = customTheme.theme;
}
}
Future<void> updateTheme(String themeName) async {
await secureStorage.write(key: 'theme', value: themeName);
final newTheme = themes.firstWhere(
(t) => t.name == themeName,
orElse: () => CustomTheme(name: 'f0ck', theme: f0ckTheme),
);
state = newTheme.theme;
}
}
final themeNotifierProvider = StateNotifierProvider<ThemeNotifier, ThemeData>((
ref,
) {
return ThemeNotifier(
secureStorage: FlutterSecureStorage(
aOptions: AndroidOptions(encryptedSharedPreferences: true),
),
);
});
class CustomTheme {
final String name;
final ThemeData theme;
CustomTheme({required this.name, required this.theme});
}
final List<CustomTheme> themes = [
CustomTheme(name: 'f0ck', theme: f0ckTheme),
CustomTheme(name: 'Paper', theme: paperTheme),
CustomTheme(name: 'Orange', theme: orangeTheme),
CustomTheme(name: 'Amoled', theme: amoledTheme),
CustomTheme(name: 'f0ck95', theme: f0ck95Theme),
CustomTheme(name: 'f0ck95d', theme: f0ck95dTheme),
];
final ThemeData f0ckTheme = ThemeData(
brightness: Brightness.dark,
primaryColor: const Color(0xFF9FFF00),
scaffoldBackgroundColor: const Color(0xFF000000),
colorScheme: const ColorScheme.dark(
primary: Color(0xFF9FFF00),
secondary: Color(0xFF262626),
surface: Color(0xFF232323),
onPrimary: Color(0xFF000000),
onSecondary: Colors.white,
onSurface: Colors.white,
),
appBarTheme: const AppBarTheme(
backgroundColor: Color(0xFF2B2B2B),
foregroundColor: Color(0xFF9FFF00),
elevation: 2,
),
textTheme: const TextTheme(
bodyLarge: TextStyle(color: Colors.white),
bodyMedium: TextStyle(color: Colors.white),
),
buttonTheme: ButtonThemeData(
buttonColor: const Color(0xFF9FFF00),
textTheme: ButtonTextTheme.primary,
),
scrollbarTheme: ScrollbarThemeData(
thumbColor: WidgetStatePropertyAll<Color>(Color(0xFF2B2B2B)),
trackColor: WidgetStatePropertyAll<Color>(Color(0xFF424242)),
),
);
final ThemeData paperTheme = ThemeData(
brightness: Brightness.light,
primaryColor: const Color(0xFF000000),
scaffoldBackgroundColor: const Color(0xFFFFFFFF),
colorScheme: const ColorScheme.light(
primary: Color(0xFF000000),
secondary: Color(0xFF262626),
surface: Color(0xFFFFFFFF),
onPrimary: Colors.white,
onSecondary: Colors.white,
onSurface: Color(0xFF000000),
),
appBarTheme: const AppBarTheme(
backgroundColor: Color(0xFFFFFFFF),
foregroundColor: Color(0xFF000000),
elevation: 0,
),
textTheme: const TextTheme(
bodyLarge: TextStyle(color: Color(0xFF000000)),
bodyMedium: TextStyle(color: Color(0xFF000000)),
),
buttonTheme: ButtonThemeData(
buttonColor: const Color(0xFF000000),
textTheme: ButtonTextTheme.primary,
),
);
final ThemeData orangeTheme = ThemeData(
brightness: Brightness.dark,
primaryColor: const Color(0xFFFF6F00),
scaffoldBackgroundColor: const Color(0xFF171717),
colorScheme: const ColorScheme.dark(
primary: Color(0xFFFF6F00),
secondary: Color(0xFF262626),
surface: Color(0xFF232323),
onPrimary: Colors.white,
onSecondary: Colors.white,
onSurface: Colors.white,
),
appBarTheme: const AppBarTheme(
backgroundColor: Color(0xFF2B2B2B),
foregroundColor: Color(0xFFFF6F00),
elevation: 2,
),
textTheme: const TextTheme(
bodyLarge: TextStyle(color: Colors.white),
bodyMedium: TextStyle(color: Colors.white),
),
buttonTheme: ButtonThemeData(
buttonColor: const Color(0xFFFF6F00),
textTheme: ButtonTextTheme.primary,
),
scrollbarTheme: ScrollbarThemeData(
thumbColor: WidgetStatePropertyAll<Color>(Color(0xFF2B2B2B)),
trackColor: WidgetStatePropertyAll<Color>(Color(0xFF424242)),
),
);
final ThemeData amoledTheme = ThemeData(
brightness: Brightness.dark,
primaryColor: const Color(0xFFFFFFFF),
scaffoldBackgroundColor: const Color(0xFF000000),
canvasColor: const Color(0xFF000000),
cardColor: const Color(0xFF000000),
colorScheme: const ColorScheme.dark(
primary: Color(0xFFFFFFFF),
secondary: Color(0xFF1F1F1F),
surface: Color(0xFF000000),
onPrimary: Color(0xFF000000),
onSecondary: Colors.white,
onSurface: Colors.white,
),
appBarTheme: const AppBarTheme(
backgroundColor: Color(0xFF000000),
foregroundColor: Colors.white,
elevation: 2,
),
textTheme: const TextTheme(
bodyLarge: TextStyle(color: Colors.white),
bodyMedium: TextStyle(color: Colors.white),
),
buttonTheme: ButtonThemeData(
buttonColor: const Color(0xFFFFFFFF),
textTheme: ButtonTextTheme.primary,
),
scrollbarTheme: ScrollbarThemeData(
thumbColor: WidgetStateProperty.all<Color>(const Color(0xFF1D1C1C)),
trackColor: WidgetStateProperty.all<Color>(const Color(0xFF000000)),
),
);
final ThemeData f0ck95Theme = ThemeData(
brightness: Brightness.light,
primaryColor: const Color(0xFFC0C0C0),
scaffoldBackgroundColor: const Color(0xFF008080),
colorScheme: const ColorScheme.light(
primary: Color(0xFFC0C0C0),
secondary: Color(0xFF808080),
surface: Color(0xFFC0C0C0),
onPrimary: Colors.black,
onSecondary: Colors.white,
),
appBarTheme: const AppBarTheme(
backgroundColor: Color(0xFFC0C0C0),
foregroundColor: Colors.black,
elevation: 2,
),
textTheme: const TextTheme(
bodyLarge: TextStyle(color: Colors.black),
bodyMedium: TextStyle(color: Colors.black),
),
buttonTheme: ButtonThemeData(
buttonColor: Colors.black,
textTheme: ButtonTextTheme.primary,
),
scrollbarTheme: ScrollbarThemeData(
thumbColor: WidgetStatePropertyAll<Color>(Color(0xFF2B2B2B)),
trackColor: WidgetStatePropertyAll<Color>(Color(0xFF424242)),
),
);
final ThemeData f0ck95dTheme = ThemeData(
brightness: Brightness.dark,
primaryColor: const Color(0xFFFFFFFF),
scaffoldBackgroundColor: const Color(0xFF0E0F0F),
colorScheme: const ColorScheme.dark(
primary: Color(0xFFFFFFFF),
secondary: Color(0xFFC0C0C0),
surface: Color(0xFF333131),
onPrimary: Colors.black,
onSecondary: Colors.white,
),
appBarTheme: const AppBarTheme(
backgroundColor: Color(0xFF0B0A0A),
foregroundColor: Colors.white,
elevation: 2,
),
textTheme: const TextTheme(
bodyLarge: TextStyle(color: Colors.white),
bodyMedium: TextStyle(color: Colors.white),
),
buttonTheme: ButtonThemeData(
buttonColor: Colors.white,
textTheme: ButtonTextTheme.primary,
),
scrollbarTheme: ScrollbarThemeData(
thumbColor: WidgetStatePropertyAll<Color>(Color(0xFF2B2B2B)),
trackColor: WidgetStatePropertyAll<Color>(Color(0xFF424242)),
),
);