fbmobile/lib/app.dart

72 lines
2.9 KiB
Dart
Raw Permalink Normal View History

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';
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';
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,
child: StreamProvider<RefreshEvent?>(
initialData: null,
2023-01-16 00:44:34 +00:00
create: (context) =>
locator<RefreshService>().refreshEventController.stream,
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) {
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)),
),
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),
onGenerateRoute: AppRouter.generateRoute,
navigatorKey: locator<NavigationService>().navigationKey,
2023-01-04 20:17:54 +00:00
home: const StartUpView(),
supportedLocales: localizationDelegate.supportedLocales,
locale: localizationDelegate.currentLocale,
);
})),
)));
2021-02-02 14:33:23 +00:00
}
}