2022-12-16 13:40:55 +00:00
|
|
|
import 'package:dynamic_color/dynamic_color.dart';
|
2021-02-02 14:33:23 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_translate/flutter_translate.dart';
|
2022-08-17 15:08:08 +00:00
|
|
|
import 'package:intl/date_symbol_data_local.dart';
|
2021-02-02 14:33:23 +00:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
2021-02-04 00:07:03 +00:00
|
|
|
import 'core/enums/refresh_event.dart';
|
2021-02-02 14:33:23 +00:00
|
|
|
import 'core/manager/dialog_manager.dart';
|
|
|
|
import 'core/manager/lifecycle_manager.dart';
|
|
|
|
import 'core/models/session.dart';
|
|
|
|
import 'core/services/dialog_service.dart';
|
|
|
|
import 'core/services/navigation_service.dart';
|
2021-02-04 00:07:03 +00:00
|
|
|
import 'core/services/refresh_service.dart';
|
2021-02-02 14:33:23 +00:00
|
|
|
import 'core/services/session_service.dart';
|
|
|
|
import 'locator.dart';
|
|
|
|
import 'ui/app_router.dart';
|
|
|
|
import 'ui/shared/app_colors.dart';
|
|
|
|
import 'ui/views/startup_view.dart';
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
2023-01-16 00:44:34 +00:00
|
|
|
static final _defaultLightColorScheme = ColorScheme.fromSwatch(
|
|
|
|
primarySwatch: myColor, brightness: Brightness.light);
|
|
|
|
static final _defaultDarkColorScheme = ColorScheme.fromSwatch(
|
|
|
|
primarySwatch: myColor, brightness: Brightness.dark);
|
2022-08-17 15:08:08 +00:00
|
|
|
|
2023-01-04 20:17:54 +00:00
|
|
|
MyApp({super.key}) {
|
2022-08-17 15:08:08 +00:00
|
|
|
initializeDateFormatting('en');
|
|
|
|
}
|
|
|
|
|
2021-02-02 14:33:23 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var localizationDelegate = LocalizedApp.of(context).delegate;
|
|
|
|
|
|
|
|
return LocalizationProvider(
|
|
|
|
state: LocalizationProvider.of(context).state,
|
2022-12-16 13:40:55 +00:00
|
|
|
child: StreamProvider<RefreshEvent?>(
|
2021-02-04 00:07:03 +00:00
|
|
|
initialData: null,
|
2023-01-16 00:44:34 +00:00
|
|
|
create: (context) =>
|
|
|
|
locator<RefreshService>().refreshEventController.stream,
|
2022-12-16 13:40:55 +00:00
|
|
|
child: StreamProvider<Session?>(
|
|
|
|
initialData: Session.initial(),
|
2023-01-16 00:44:34 +00:00
|
|
|
create: (context) =>
|
|
|
|
locator<SessionService>().sessionController.stream,
|
|
|
|
child: LifeCycleManager(child: DynamicColorBuilder(
|
|
|
|
builder: (lightColorScheme, darkColorScheme) {
|
2022-12-16 13:40:55 +00:00
|
|
|
return MaterialApp(
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
title: translate('app.title'),
|
|
|
|
builder: (context, child) => Navigator(
|
|
|
|
key: locator<DialogService>().dialogNavigationKey,
|
2023-01-16 00:44:34 +00:00
|
|
|
onGenerateRoute: (settings) => MaterialPageRoute(
|
|
|
|
builder: (context) => DialogManager(child: child)),
|
2022-12-16 13:40:55 +00:00
|
|
|
),
|
|
|
|
theme: ThemeData(
|
|
|
|
useMaterial3: true,
|
|
|
|
brightness: Brightness.light,
|
2023-01-16 00:44:34 +00:00
|
|
|
colorScheme:
|
|
|
|
lightColorScheme ?? _defaultLightColorScheme),
|
|
|
|
darkTheme: ThemeData(
|
|
|
|
useMaterial3: true,
|
|
|
|
colorScheme: darkColorScheme ?? _defaultDarkColorScheme),
|
2022-12-16 13:40:55 +00:00
|
|
|
onGenerateRoute: AppRouter.generateRoute,
|
|
|
|
navigatorKey: locator<NavigationService>().navigationKey,
|
2023-01-04 20:17:54 +00:00
|
|
|
home: const StartUpView(),
|
2022-12-16 13:40:55 +00:00
|
|
|
supportedLocales: localizationDelegate.supportedLocales,
|
|
|
|
locale: localizationDelegate.currentLocale,
|
|
|
|
);
|
|
|
|
})),
|
|
|
|
)));
|
2021-02-02 14:33:23 +00:00
|
|
|
}
|
|
|
|
}
|