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.

158 lines
4.7 KiB

import 'dart:io';
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';
5 years ago
void main() async {
final sharedPreferences = await SharedPreferences.getInstance();
runApp(
ProviderScope(
overrides: [
sharedPreferencesProvider.overrideWithValue(sharedPreferences),
],
child: const StartPoint(),
),
);
}
Map<String, WidgetBuilder> 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(),
);
},
};
5 years ago
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});
5 years ago
@override
Widget build(BuildContext context, WidgetRef ref) {
final uiDesign = ref.watch(uiDesignProvider);
if (uiDesign == UiDesign.CUPERTINO) {
return AnnotatedRegion(
value: const SystemUiOverlayStyle(
statusBarBrightness: c.Brightness.dark,
),
child: c.CupertinoApp(
title: appTitle,
theme: c.CupertinoThemeData(
primaryColor: 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 f.FluentApp(
title: appTitle,
theme: f.ThemeData(
brightness: f.Brightness.dark,
accentColor: f.Colors.blue,
),
routes: routes,
scrollBehavior: Platform.isLinux ? const DragFluentScrollBevahior() : const f.FluentScrollBehavior(),
);
}
else {
return m.MaterialApp(
title: appTitle,
theme: m.ThemeData(
primarySwatch: m.Colors.blue,
colorScheme: m.ColorScheme.fromSwatch(
brightness: m.Brightness.dark,
primarySwatch: m.Colors.blue,
accentColor: m.Colors.blue.shade700,
),
useMaterial3: true,
// fontFamily: 'Atkinson Hyperlegible',
),
scrollBehavior: Platform.isLinux ? const DragMaterialScrollBevahior() : null,
routes: routes,
);
}
5 years ago
}
}