2023-06-17 21:50:52 +00:00
|
|
|
import 'dart:io';
|
2023-07-20 20:56:00 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/gestures.dart';
|
2023-06-17 21:50:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-10-09 18:48:50 +00:00
|
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
2023-07-15 16:22:25 +00:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2023-10-19 21:45:07 +00:00
|
|
|
import 'package:tetra_stats/views/customization_view.dart';
|
2023-10-08 17:20:42 +00:00
|
|
|
import 'package:window_manager/window_manager.dart';
|
2023-06-17 21:50:52 +00:00
|
|
|
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
2023-07-20 20:56:00 +00:00
|
|
|
import 'package:sqflite_common_ffi_web/sqflite_ffi_web.dart';
|
2023-07-10 17:42:20 +00:00
|
|
|
import 'package:tetra_stats/gen/strings.g.dart';
|
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
2023-06-17 21:50:52 +00:00
|
|
|
import 'package:tetra_stats/views/main_view.dart';
|
|
|
|
import 'package:tetra_stats/views/settings_view.dart';
|
|
|
|
import 'package:tetra_stats/views/tracked_players_view.dart';
|
|
|
|
import 'package:tetra_stats/views/calc_view.dart';
|
2023-12-26 22:02:47 +00:00
|
|
|
import 'package:go_router/go_router.dart';
|
2023-06-17 21:50:52 +00:00
|
|
|
|
2023-10-09 18:48:50 +00:00
|
|
|
late final PackageInfo packageInfo;
|
2023-10-26 22:38:03 +00:00
|
|
|
late SharedPreferences prefs;
|
2024-01-13 18:49:36 +00:00
|
|
|
ColorScheme sheme = const ColorScheme.dark(primary: Colors.cyanAccent, secondary: Colors.white);
|
2023-10-28 22:05:56 +00:00
|
|
|
|
2024-01-26 20:56:24 +00:00
|
|
|
void setAccentColor(Color color){ // does this thing work??? yes??? no???
|
|
|
|
sheme = ColorScheme.dark(primary: color, secondary: Colors.white);
|
2023-10-28 22:05:56 +00:00
|
|
|
}
|
2023-10-09 18:48:50 +00:00
|
|
|
|
2023-12-26 22:02:47 +00:00
|
|
|
final router = GoRouter(
|
2024-01-03 17:43:03 +00:00
|
|
|
initialLocation: "/",
|
2023-12-26 22:02:47 +00:00
|
|
|
routes: [
|
|
|
|
GoRoute(
|
|
|
|
path: "/",
|
|
|
|
builder: (_, __) => const MainView(),
|
|
|
|
routes: [
|
|
|
|
GoRoute(
|
|
|
|
path: 'settings',
|
|
|
|
builder: (_, __) => const SettingsView(),
|
|
|
|
),
|
|
|
|
GoRoute(
|
|
|
|
path: 'states',
|
|
|
|
builder: (_, __) => const TrackedPlayersView(),
|
|
|
|
),
|
|
|
|
GoRoute(
|
|
|
|
path: 'calc',
|
|
|
|
builder: (_, __) => const CalcView(),
|
|
|
|
),
|
|
|
|
GoRoute(
|
|
|
|
path: 'customization',
|
|
|
|
builder: (_, __) => const CustomizationView(),
|
|
|
|
),
|
|
|
|
]
|
2023-12-26 22:55:51 +00:00
|
|
|
),
|
2024-01-26 20:56:24 +00:00
|
|
|
GoRoute( // that one intended for Android users, that can open https://ch.tetr.io/u/ links
|
2023-12-26 22:55:51 +00:00
|
|
|
path: "/u/:userId",
|
|
|
|
builder: (_, __) => MainView(player: __.pathParameters['userId'])
|
2023-12-26 22:02:47 +00:00
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
2023-07-15 16:22:25 +00:00
|
|
|
void main() async {
|
2024-01-26 20:56:24 +00:00
|
|
|
// Initializing sqflite
|
2023-07-20 20:56:00 +00:00
|
|
|
if (kIsWeb) {
|
|
|
|
sqfliteFfiInit();
|
|
|
|
databaseFactory = databaseFactoryFfiWeb;
|
|
|
|
} else if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
|
2023-06-17 21:50:52 +00:00
|
|
|
sqfliteFfiInit();
|
|
|
|
databaseFactory = databaseFactoryFfi;
|
|
|
|
}
|
2024-01-26 20:56:24 +00:00
|
|
|
|
|
|
|
// Initializing funny things
|
2023-07-15 16:22:25 +00:00
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2024-01-26 20:56:24 +00:00
|
|
|
if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS){ // we can't control windows manager in web and mobile
|
|
|
|
await WindowManager.instance.ensureInitialized(); // Initializing windows manager
|
2023-10-09 18:48:50 +00:00
|
|
|
windowManager.waitUntilReadyToShow().then((_) async {
|
2024-01-26 20:56:24 +00:00
|
|
|
await windowManager.setTitle('Tetra Stats'); // And setting the windows title
|
2023-10-09 18:48:50 +00:00
|
|
|
});
|
|
|
|
}
|
2024-01-26 20:56:24 +00:00
|
|
|
|
2023-10-09 18:48:50 +00:00
|
|
|
packageInfo = await PackageInfo.fromPlatform();
|
2023-07-15 16:22:25 +00:00
|
|
|
prefs = await SharedPreferences.getInstance();
|
2024-01-26 20:56:24 +00:00
|
|
|
|
|
|
|
// Choosing the locale
|
2023-07-15 16:22:25 +00:00
|
|
|
String? locale = prefs.getString("locale");
|
|
|
|
if (locale == null){
|
|
|
|
LocaleSettings.useDeviceLocale();
|
|
|
|
}else{
|
|
|
|
LocaleSettings.setLocaleRaw(locale);
|
|
|
|
}
|
2024-01-26 20:56:24 +00:00
|
|
|
|
2023-07-10 17:42:20 +00:00
|
|
|
runApp(TranslationProvider(
|
2023-08-21 15:39:04 +00:00
|
|
|
child: const MyApp(),
|
2023-07-10 17:42:20 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
2023-07-15 16:22:25 +00:00
|
|
|
const MyApp({super.key});
|
|
|
|
|
2023-07-10 17:42:20 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-12-26 22:02:47 +00:00
|
|
|
return MaterialApp.router(
|
2024-01-26 20:56:24 +00:00
|
|
|
title: "Tetra Stats",
|
|
|
|
routerConfig: router,
|
|
|
|
scrollBehavior: const MaterialScrollBehavior().copyWith(
|
2023-07-20 20:56:00 +00:00
|
|
|
dragDevices: {PointerDeviceKind.mouse, PointerDeviceKind.touch, PointerDeviceKind.stylus, PointerDeviceKind.unknown},
|
2024-01-26 20:56:24 +00:00
|
|
|
),
|
|
|
|
locale: TranslationProvider.of(context).flutterLocale,
|
|
|
|
supportedLocales: AppLocaleUtils.supportedLocales,
|
|
|
|
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
|
|
|
theme: ThemeData(
|
|
|
|
fontFamily: 'Eurostile Round',
|
|
|
|
colorScheme: sheme,
|
|
|
|
scaffoldBackgroundColor: Colors.black
|
|
|
|
)
|
|
|
|
);
|
2023-07-10 17:42:20 +00:00
|
|
|
}
|
2023-06-17 21:50:52 +00:00
|
|
|
}
|