mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Adds a dropdown in the settings page to switch between available themes (Catppuccin Mocha, Gruvbox Dark). The selected theme is applied immediately on save and persisted across restarts via SharedPreferences. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
54 lines
1.4 KiB
Dart
54 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:frontend/theme/catppuccin_mocha_theme.dart';
|
|
import 'package:frontend/utils/pref_utils.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'navigation.dart';
|
|
import 'theme/gruvbox_theme.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await PrefUtil.init();
|
|
runApp(const MainApp());
|
|
}
|
|
|
|
final class MainApp extends StatelessWidget {
|
|
const MainApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ChangeNotifierProvider(
|
|
create: (context) => AppState(),
|
|
child: Consumer<AppState>(
|
|
builder: (context, appState, _) => MaterialApp.router(
|
|
title: 'OOTT',
|
|
theme: appState.theme,
|
|
routerConfig: router,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
final _themes = {
|
|
'catppuccin_mocha': catppuccinMochaDarkTheme,
|
|
'gruvbox_dark': gruvboxDarkTheme,
|
|
};
|
|
|
|
class AppState extends ChangeNotifier {
|
|
AppState() {
|
|
final saved = PrefUtil.getValue('theme', 'catppuccin_mocha') as String;
|
|
_themeKey = _themes.containsKey(saved) ? saved : 'catppuccin_mocha';
|
|
}
|
|
|
|
late String _themeKey;
|
|
String get themeKey => _themeKey;
|
|
ThemeData get theme => _themes[_themeKey]!;
|
|
|
|
void setTheme(String key) {
|
|
if (!_themes.containsKey(key) || key == _themeKey) return;
|
|
_themeKey = key;
|
|
PrefUtil.setValue('theme', key);
|
|
notifyListeners();
|
|
}
|
|
}
|