2024-06-03 23:42:44 +00:00
|
|
|
import 'dart:async';
|
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';
|
2024-06-03 23:42:44 +00:00
|
|
|
import 'dart:developer' as developer;
|
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';
|
2024-06-03 23:42:44 +00:00
|
|
|
import 'package:tetra_stats/services/tetrio_crud.dart';
|
2024-11-13 23:20:52 +00:00
|
|
|
import 'package:tetra_stats/views/first_time_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';
|
2024-11-05 23:07:43 +00:00
|
|
|
import 'package:tetra_stats/views/main_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-06-03 23:42:44 +00:00
|
|
|
late TetrioService teto;
|
2024-11-13 23:20:52 +00:00
|
|
|
late GoRouter router;
|
|
|
|
|
2024-07-27 19:10:45 +00:00
|
|
|
ThemeData theme = ThemeData(
|
|
|
|
fontFamily: 'Eurostile Round',
|
|
|
|
colorScheme: const ColorScheme.dark(
|
|
|
|
primary: Colors.cyanAccent,
|
|
|
|
surface: Color.fromARGB(255, 10, 10, 10),
|
2024-08-06 22:24:31 +00:00
|
|
|
secondary: Color(0xFF00838F),
|
2024-07-27 19:10:45 +00:00
|
|
|
),
|
2024-10-21 22:38:41 +00:00
|
|
|
textTheme: TextTheme(
|
|
|
|
titleLarge: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: 42),
|
|
|
|
titleSmall: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: 28, height: 0.9, fontWeight: FontWeight.w200),
|
|
|
|
headlineMedium: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: 36),
|
|
|
|
displayLarge: TextStyle(fontSize: 18),
|
|
|
|
),
|
2024-08-03 17:52:20 +00:00
|
|
|
cardTheme: const CardTheme(surfaceTintColor: Color.fromARGB(255, 10, 10, 10)),
|
|
|
|
drawerTheme: const DrawerThemeData(surfaceTintColor: Color.fromARGB(255, 10, 10, 10)),
|
|
|
|
searchBarTheme: const SearchBarThemeData(
|
|
|
|
shadowColor: WidgetStatePropertyAll(Colors.black),
|
|
|
|
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.horizontal(left: Radius.circular(12.0), right: Radius.circular(12.0)))),
|
|
|
|
elevation: WidgetStatePropertyAll(8.0)
|
|
|
|
),
|
2024-09-01 21:44:19 +00:00
|
|
|
chipTheme: const ChipThemeData(
|
2024-08-06 22:24:31 +00:00
|
|
|
side: BorderSide(color: Colors.transparent),
|
|
|
|
),
|
|
|
|
segmentedButtonTheme: SegmentedButtonThemeData(
|
|
|
|
style: ButtonStyle(
|
2024-11-22 22:35:16 +00:00
|
|
|
visualDensity: VisualDensity(horizontal: -4.0, vertical: -4.0),
|
2024-09-01 21:44:19 +00:00
|
|
|
side: const WidgetStatePropertyAll(BorderSide(color: Colors.transparent)),
|
|
|
|
surfaceTintColor: const WidgetStatePropertyAll(Colors.cyanAccent),
|
|
|
|
iconColor: const WidgetStatePropertyAll(Colors.cyanAccent),
|
2024-08-06 22:24:31 +00:00
|
|
|
shadowColor: WidgetStatePropertyAll(Colors.cyanAccent.shade200),
|
|
|
|
)
|
|
|
|
),
|
2024-10-05 22:32:09 +00:00
|
|
|
dividerColor: Color.fromARGB(50, 158, 158, 158),
|
|
|
|
dividerTheme: DividerThemeData(color: Color.fromARGB(50, 158, 158, 158)),
|
2024-10-06 22:25:55 +00:00
|
|
|
expansionTileTheme: ExpansionTileThemeData(
|
|
|
|
expansionAnimationStyle: AnimationStyle(curve: Easing.standard, reverseCurve: Easing.standard),
|
|
|
|
expandedAlignment: Alignment.bottomCenter,
|
|
|
|
),
|
2024-10-21 22:38:41 +00:00
|
|
|
dropdownMenuTheme: DropdownMenuThemeData(textStyle: TextStyle(fontFamily: "Eurostile Round", fontSize: 18)),
|
2024-11-19 23:21:03 +00:00
|
|
|
scaffoldBackgroundColor: Colors.black,
|
|
|
|
tooltipTheme: TooltipThemeData(
|
|
|
|
textStyle: TextStyle(color: Colors.white),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(8.0)),
|
|
|
|
border: Border.all(
|
|
|
|
color: Colors.white
|
|
|
|
),
|
|
|
|
color: Colors.black,
|
|
|
|
)
|
|
|
|
)
|
2024-07-27 19:10:45 +00:00
|
|
|
);
|
2024-06-11 16:30:13 +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-06-03 23:42:44 +00:00
|
|
|
teto = TetrioService();
|
2024-01-26 20:56:24 +00:00
|
|
|
|
2024-11-13 23:20:52 +00:00
|
|
|
router = GoRouter(
|
|
|
|
//initialLocation: prefs.getBool("notFirstTime") == true ? "/" : "/hihello",
|
|
|
|
initialLocation: "/",
|
|
|
|
routes: [
|
|
|
|
GoRoute(
|
|
|
|
path: "/",
|
|
|
|
builder: (_, __) => const MainView(),
|
|
|
|
),
|
|
|
|
GoRoute( // that one intended for Android users, that can open https://ch.tetr.io/u/ links
|
|
|
|
path: "/u/:userId",
|
|
|
|
builder: (_, __) => MainView(player: __.pathParameters['userId'])
|
|
|
|
),
|
|
|
|
GoRoute(
|
|
|
|
path: "/hihello",
|
|
|
|
builder: (_, __) => const FirstTimeView(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
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-06-03 23:42:44 +00:00
|
|
|
|
|
|
|
// I dont want to store old cache
|
2024-06-16 21:04:07 +00:00
|
|
|
Timer.periodic(const Duration(minutes: 5), (Timer timer) {
|
2024-06-03 23:42:44 +00:00
|
|
|
teto.cacheRoutine();
|
2024-06-16 21:04:07 +00:00
|
|
|
developer.log("Cache routine complete, next one in ${DateTime.now().add(const Duration(minutes: 5))}", name: "main");
|
2024-06-11 16:30:13 +00:00
|
|
|
// if (prefs.getBool("updateInBG") == true) teto.fetchTracked(); // TODO: Somehow avoid doing that in main isolate
|
2024-06-03 23:42:44 +00:00
|
|
|
});
|
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
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2024-06-15 22:49:57 +00:00
|
|
|
class MyApp extends StatefulWidget {
|
2023-07-15 16:22:25 +00:00
|
|
|
const MyApp({super.key});
|
|
|
|
|
2024-06-15 22:49:57 +00:00
|
|
|
@override
|
|
|
|
State<MyApp> createState() => MyAppState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyAppState extends State<MyApp> {
|
2024-06-16 21:04:07 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
setAccentColor(prefs.getInt("accentColor") != null ? Color(prefs.getInt("accentColor")!) : Colors.cyanAccent);
|
|
|
|
super.initState();
|
|
|
|
}
|
2024-06-15 22:49:57 +00:00
|
|
|
|
|
|
|
void setAccentColor(Color color){ // does this thing work??? yes??? no???
|
|
|
|
setState(() {
|
|
|
|
theme = theme.copyWith(colorScheme: theme.colorScheme.copyWith(primary: color));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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,
|
2024-06-15 22:49:57 +00:00
|
|
|
theme: theme
|
2024-01-26 20:56:24 +00:00
|
|
|
);
|
2023-07-10 17:42:20 +00:00
|
|
|
}
|
2024-07-27 19:10:45 +00:00
|
|
|
}
|