import 'dart:io'; import 'package:dynamic_color/dynamic_color.dart'; import 'package:fluent_ui/fluent_ui.dart' as f; import 'package:flutter/cupertino.dart' as c; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart' as m; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:info_tren/models.dart'; import 'package:info_tren/pages/about/about_page.dart'; import 'package:info_tren/pages/main/main_page.dart'; import 'package:info_tren/pages/settings/setings_page.dart'; import 'package:info_tren/pages/station_arrdep_page/select_station/select_station.dart'; import 'package:info_tren/pages/station_arrdep_page/view_station/view_station.dart'; import 'package:info_tren/pages/train_info_page/view_train/train_info.dart'; import 'package:info_tren/pages/train_info_page/select_train/select_train.dart'; import 'package:info_tren/providers.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:timezone/data/latest.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); initializeTimeZones(); final sharedPreferences = await SharedPreferences.getInstance(); runApp( ProviderScope( overrides: [ sharedPreferencesProvider.overrideWithValue(sharedPreferences), ], child: const StartPoint(), ), ); } Map get routes => { Navigator.defaultRouteName: (context) { return const MainPage(); }, AboutPage.routeName: (context) { return const AboutPage(); }, SettingsPage.routeName: (context) { return const SettingsPage(); }, SelectTrainPage.routeName: (context) { return const SelectTrainPage(); }, TrainInfo.routeName: (context) { final args = ModalRoute.of(context)!.settings.arguments as TrainInfoArguments; return ProviderScope( overrides: [ trainInfoArgumentsProvider.overrideWithValue(args), ], child: const TrainInfo(), ); }, SelectStationPage.routeName: (context) { return const SelectStationPage(); }, ViewStationPage.routeName: (context) { final args = ModalRoute.of(context)!.settings.arguments as ViewStationArguments; return ProviderScope( overrides: [ viewStationArgumentsProvider.overrideWithValue(args), ], child: const ViewStationPage(), ); }, }; class DragFluentScrollBevahior extends f.FluentScrollBehavior { const DragFluentScrollBevahior(); @override Set get dragDevices => { PointerDeviceKind.mouse, PointerDeviceKind.touch, }; } class DragCupertinoScrollBevahior extends c.CupertinoScrollBehavior { const DragCupertinoScrollBevahior(); @override Set get dragDevices => { PointerDeviceKind.mouse, PointerDeviceKind.touch, }; } class DragMaterialScrollBevahior extends m.MaterialScrollBehavior { const DragMaterialScrollBevahior(); @override Set get dragDevices => { PointerDeviceKind.mouse, PointerDeviceKind.touch, }; } class StartPoint extends ConsumerWidget { final String appTitle = 'Info Tren'; const StartPoint({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final uiDesign = ref.watch(uiDesignProvider); if (uiDesign == UiDesign.CUPERTINO) { return DynamicColorBuilder( builder: (lightScheme, darkScheme) { return AnnotatedRegion( value: const SystemUiOverlayStyle( statusBarBrightness: c.Brightness.dark, ), child: c.CupertinoApp( title: appTitle, theme: c.CupertinoThemeData( primaryColor: darkScheme?.primary ?? m.Colors.blue.shade600, brightness: c.Brightness.dark, // textTheme: CupertinoTextThemeData( // textStyle: TextStyle( // fontFamily: 'Atkinson Hyperlegible', // ), // ), ), scrollBehavior: Platform.isLinux ? const DragCupertinoScrollBevahior() : null, routes: routes, ), ); } ); } else if (uiDesign == UiDesign.FLUENT) { return DynamicColorBuilder( builder: (lightScheme, darkScheme) { return f.FluentApp( title: appTitle, theme: f.FluentThemeData( brightness: f.Brightness.light, accentColor: lightScheme != null ? f.AccentColor.swatch({ 'normal': lightScheme.primary, }) : f.Colors.blue, ), darkTheme: f.FluentThemeData( brightness: f.Brightness.dark, accentColor: darkScheme != null ? f.AccentColor.swatch({ 'normal': darkScheme.primary, }) : f.Colors.blue, ), routes: routes, scrollBehavior: Platform.isLinux ? const DragFluentScrollBevahior() : const f.FluentScrollBehavior(), ); } ); } else { return DynamicColorBuilder( builder: (lightScheme, darkScheme) { lightScheme ??= m.ColorScheme.fromSwatch( brightness: m.Brightness.light, primarySwatch: m.Colors.blue, ); darkScheme ??= m.ColorScheme.fromSwatch( brightness: m.Brightness.dark, primarySwatch: m.Colors.blue, ); return m.MaterialApp( title: appTitle, theme: m.ThemeData( colorScheme: lightScheme, useMaterial3: true, // fontFamily: 'Atkinson Hyperlegible', ), darkTheme: m.ThemeData( colorScheme: darkScheme, useMaterial3: true, // fontFamily: 'Atkinson Hyperlegible', ), scrollBehavior: Platform.isLinux ? const DragMaterialScrollBevahior() : null, routes: routes, ); } ); } } }