Files
oott/frontend/lib/main.dart
T

54 lines
1.4 KiB
Dart
Raw Normal View History

2026-02-11 14:07:27 -05:00
import 'package:flutter/material.dart';
2026-05-27 11:38:16 -04:00
import 'package:frontend/theme/catppuccin_mocha_theme.dart';
import 'package:frontend/utils/pref_utils.dart';
2026-02-11 14:07:27 -05:00
import 'package:provider/provider.dart';
import 'navigation.dart';
2026-05-27 11:38:16 -04:00
import 'theme/gruvbox_theme.dart';
2026-02-11 14:07:27 -05:00
void main() async {
2026-05-27 11:38:16 -04:00
WidgetsFlutterBinding.ensureInitialized();
await PrefUtil.init();
2026-02-11 14:07:27 -05:00
runApp(const MainApp());
}
final class MainApp extends StatelessWidget {
2026-02-11 14:07:27 -05:00
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => AppState(),
2026-05-27 11:38:16 -04:00
child: Consumer<AppState>(
builder: (context, appState, _) => MaterialApp.router(
title: 'OOTT',
theme: appState.theme,
routerConfig: router,
2026-02-11 14:07:27 -05:00
),
),
);
}
}
2026-05-27 11:38:16 -04:00
final _themes = {
'catppuccin_mocha': catppuccinMochaDarkTheme,
'gruvbox_dark': gruvboxDarkTheme,
};
2026-02-11 14:07:27 -05:00
class AppState extends ChangeNotifier {
2026-05-27 11:38:16 -04:00
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();
}
2026-02-11 14:07:27 -05:00
}