2026-05-31 18:55:35 -04:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
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';
|
2026-06-07 15:33:06 -04:00
|
|
|
import 'package:frontend/utils/local_network_permission.dart';
|
2026-03-02 13:59:50 -05:00
|
|
|
import 'package:frontend/utils/pref_utils.dart';
|
2026-06-09 11:51:28 -04:00
|
|
|
import 'package:frontend/utils/push_service.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
|
|
|
|
2026-05-31 18:55:35 -04:00
|
|
|
void main() {
|
|
|
|
|
runZonedGuarded(
|
|
|
|
|
() async {
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
|
|
FlutterError.onError = (details) {
|
|
|
|
|
FlutterError.presentError(details);
|
|
|
|
|
debugPrint('FlutterError: ${details.exceptionAsString()}');
|
|
|
|
|
};
|
|
|
|
|
PlatformDispatcher.instance.onError = (error, stack) {
|
|
|
|
|
debugPrint('Uncaught platform error: $error\n$stack');
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await PrefUtil.init();
|
|
|
|
|
} catch (e, stack) {
|
2026-06-06 16:07:05 -04:00
|
|
|
debugPrint(
|
|
|
|
|
'PrefUtil.init failed, continuing with defaults: $e\n$stack',
|
|
|
|
|
);
|
2026-05-31 18:55:35 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-09 11:51:28 -04:00
|
|
|
// Initialize Firebase at launch so the firebase_messaging plugin's iOS
|
|
|
|
|
// APNs swizzling has a configured app to forward the device token to;
|
|
|
|
|
// without this getAPNSToken() never resolves and enabling push fails.
|
|
|
|
|
try {
|
|
|
|
|
await initFirebaseForPush();
|
|
|
|
|
} catch (e, stack) {
|
|
|
|
|
debugPrint('Firebase init for push failed, continuing: $e\n$stack');
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-07 15:33:06 -04:00
|
|
|
// Settle iOS's local-network permission now, at launch, so it isn't
|
|
|
|
|
// still being decided when the user first taps "Test" in settings.
|
|
|
|
|
unawaited(requestLocalNetworkPermission());
|
|
|
|
|
|
2026-05-31 18:55:35 -04:00
|
|
|
runApp(const MainApp());
|
|
|
|
|
},
|
|
|
|
|
(error, stack) {
|
|
|
|
|
debugPrint('Uncaught zone error: $error\n$stack');
|
|
|
|
|
},
|
|
|
|
|
);
|
2026-02-11 14:07:27 -05:00
|
|
|
}
|
|
|
|
|
|
2026-02-27 12:28:16 -05:00
|
|
|
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() {
|
2026-06-04 09:38:23 -04:00
|
|
|
final saved = PrefUtil.getValue('theme', 'gruvbox_dark') as String;
|
|
|
|
|
_themeKey = _themes.containsKey(saved) ? saved : 'gruvbox_dark';
|
2026-05-27 11:38:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
late String _themeKey;
|
|
|
|
|
String get themeKey => _themeKey;
|
|
|
|
|
ThemeData get theme => _themes[_themeKey]!;
|
|
|
|
|
|
2026-05-31 18:43:46 -04:00
|
|
|
Future<bool> setTheme(String key) async {
|
|
|
|
|
if (!_themes.containsKey(key)) return false;
|
|
|
|
|
if (key == _themeKey) return true;
|
2026-05-27 11:38:16 -04:00
|
|
|
_themeKey = key;
|
|
|
|
|
notifyListeners();
|
2026-05-31 18:43:46 -04:00
|
|
|
return PrefUtil.setValue('theme', key);
|
2026-05-27 11:38:16 -04:00
|
|
|
}
|
2026-02-11 14:07:27 -05:00
|
|
|
}
|