You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.4 KiB

import 'package:flutter/material.dart';
import 'core/app_initializer.dart';
import 'core/app_services.dart';
import 'core/logger.dart';
import 'core/theme_notifier.dart';
import 'ui/navigation/main_navigation_scaffold.dart';
import 'ui/navigation/app_router.dart';
import 'core/service_locator.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// Determine environment
const String environment = String.fromEnvironment(
'ENV',
defaultValue: 'dev',
);
// Initialize all services
AppServices? appServices;
try {
appServices = await AppInitializer.initialize(environment: environment);
} catch (e, stackTrace) {
Logger.error('Failed to initialize application', e, stackTrace);
// App will show error state
}
runApp(MyApp(appServices: appServices));
}
/// The root widget of the application.
class MyApp extends StatefulWidget {
final AppServices? appServices;
const MyApp({super.key, this.appServices});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
ThemeNotifier? _themeNotifier;
@override
void initState() {
super.initState();
// Get theme notifier from ServiceLocator if available
_themeNotifier = ServiceLocator.instance.themeNotifier as ThemeNotifier?;
if (_themeNotifier != null) {
_themeNotifier!.addListener(_onThemeChanged);
}
}
@override
void dispose() {
// Remove listener and dispose of all services
_themeNotifier?.removeListener(_onThemeChanged);
widget.appServices?.dispose();
super.dispose();
}
void _onThemeChanged() {
setState(() {
// Rebuild when theme changes
});
}
@override
Widget build(BuildContext context) {
final appServices = widget.appServices;
final appRouter = appServices != null
? AppRouter(
sessionService: ServiceLocator.instance.sessionService,
localStorageService: ServiceLocator.instance.localStorageService,
nostrService: ServiceLocator.instance.nostrService,
syncEngine: ServiceLocator.instance.syncEngine,
firebaseService: ServiceLocator.instance.firebaseService,
)
: null;
final themeMode = _themeNotifier?.value ?? ThemeMode.light;
return MaterialApp(
title: 'App Boilerplate',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
darkTheme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.blue,
brightness: Brightness.dark,
).copyWith(
// Use a grayish background instead of pure black
surface: const Color(0xFF1E1E1E),
),
scaffoldBackgroundColor: const Color(0xFF121212), // Grayish dark background
useMaterial3: true,
),
themeMode: themeMode,
home: appServices != null
? const MainNavigationScaffold()
: const Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(height: 16),
Text('Initializing application...'),
],
),
),
),
onGenerateRoute: appRouter?.generateRoute,
);
}
}

Powered by TurnKey Linux.