info_tren/lib/main.dart

192 lines
5.9 KiB
Dart
Raw Normal View History

import 'dart:io';
2023-07-24 06:47:03 +02:00
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';
2022-10-31 03:44:29 +01:00
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';
2022-11-19 05:35:51 +01:00
import 'package:info_tren/pages/settings/setings_page.dart';
2021-08-28 04:35:58 +03:00
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';
2022-10-31 03:44:29 +01:00
import 'package:info_tren/providers.dart';
import 'package:shared_preferences/shared_preferences.dart';
2022-12-11 01:34:19 +01:00
import 'package:timezone/data/latest.dart';
2019-07-23 16:56:51 +03:00
2022-10-31 03:44:29 +01:00
void main() async {
2023-07-24 06:47:03 +02:00
WidgetsFlutterBinding.ensureInitialized();
2022-12-11 01:34:19 +01:00
initializeTimeZones();
2022-10-31 03:44:29 +01:00
final sharedPreferences = await SharedPreferences.getInstance();
runApp(
2022-10-31 03:44:29 +01:00
ProviderScope(
overrides: [
sharedPreferencesProvider.overrideWithValue(sharedPreferences),
],
child: const StartPoint(),
),
);
}
2022-10-31 03:44:29 +01:00
Map<String, WidgetBuilder> get routes => {
Navigator.defaultRouteName: (context) {
2022-10-31 03:44:29 +01:00
return const MainPage();
},
AboutPage.routeName: (context) {
2022-10-31 03:44:29 +01:00
return const AboutPage();
},
2022-11-19 05:35:51 +01:00
SettingsPage.routeName: (context) {
return const SettingsPage();
},
SelectTrainPage.routeName: (context) {
2022-10-31 03:44:29 +01:00
return const SelectTrainPage();
},
TrainInfo.routeName: (context) {
2022-08-06 00:27:46 +03:00
final args = ModalRoute.of(context)!.settings.arguments as TrainInfoArguments;
2022-10-31 03:44:29 +01:00
return ProviderScope(
overrides: [
trainInfoArgumentsProvider.overrideWithValue(args),
],
child: const TrainInfo(),
2021-08-28 04:35:58 +03:00
);
},
SelectStationPage.routeName: (context) {
2022-10-31 03:44:29 +01:00
return const SelectStationPage();
2021-08-28 04:35:58 +03:00
},
ViewStationPage.routeName: (context) {
2022-10-31 03:44:29 +01:00
final args = ModalRoute.of(context)!.settings.arguments as ViewStationArguments;
return ProviderScope(
overrides: [
viewStationArgumentsProvider.overrideWithValue(args),
],
child: const ViewStationPage(),
);
},
};
2019-07-23 16:56:51 +03:00
class DragFluentScrollBevahior extends f.FluentScrollBehavior {
const DragFluentScrollBevahior();
@override
Set<PointerDeviceKind> get dragDevices => {
PointerDeviceKind.mouse,
PointerDeviceKind.touch,
};
}
class DragCupertinoScrollBevahior extends c.CupertinoScrollBehavior {
const DragCupertinoScrollBevahior();
@override
Set<PointerDeviceKind> get dragDevices => {
PointerDeviceKind.mouse,
PointerDeviceKind.touch,
};
}
class DragMaterialScrollBevahior extends m.MaterialScrollBehavior {
const DragMaterialScrollBevahior();
@override
Set<PointerDeviceKind> get dragDevices => {
PointerDeviceKind.mouse,
PointerDeviceKind.touch,
};
}
class StartPoint extends ConsumerWidget {
final String appTitle = 'Info Tren';
const StartPoint({super.key});
2019-07-23 16:56:51 +03:00
@override
Widget build(BuildContext context, WidgetRef ref) {
final uiDesign = ref.watch(uiDesignProvider);
if (uiDesign == UiDesign.CUPERTINO) {
2023-07-24 06:47:03 +02:00
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) {
2023-07-24 06:47:03 +02:00
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 {
2023-07-24 06:47:03 +02:00
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,
2023-07-24 06:47:03 +02:00
);
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,
);
}
2019-09-15 02:33:07 +03:00
);
}
2019-07-23 16:56:51 +03:00
}
}