2024-05-28 21:25:51 +00:00
|
|
|
import 'dart:async';
|
2024-05-22 20:48:44 +00:00
|
|
|
import 'dart:developer';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:auto_route/annotations.dart';
|
|
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
|
|
|
|
import 'package:firebase_core/firebase_core.dart';
|
2024-05-28 21:25:51 +00:00
|
|
|
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
2024-05-22 20:48:44 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-05-28 21:25:51 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2024-05-22 20:48:44 +00:00
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
|
import 'package:jailbreak_root_detection/jailbreak_root_detection.dart';
|
|
|
|
|
import 'package:mnemo_cards/di/locator.dart';
|
|
|
|
|
import 'package:mnemo_cards/domain/router/app_router.dart';
|
|
|
|
|
import 'package:mnemo_cards/managers/repository/firebase_config_repository.dart';
|
|
|
|
|
import 'package:mnemo_cards/features/packs/pack_manager.dart';
|
|
|
|
|
import 'package:mnemo_cards/theme/themes.dart';
|
|
|
|
|
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
|
|
|
|
|
import 'package:no_screenshot/no_screenshot.dart';
|
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
import 'package:yandex_mobileads/mobile_ads.dart';
|
|
|
|
|
|
|
|
|
|
import 'di/injector.dart';
|
|
|
|
|
import 'domain/router/app_router.gr.dart';
|
|
|
|
|
import 'firebase_options.dart';
|
|
|
|
|
import 'flags.dart';
|
|
|
|
|
import 'managers/repository/repository.dart';
|
|
|
|
|
|
|
|
|
|
final scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
|
final scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
|
2024-05-28 21:25:51 +00:00
|
|
|
late final SharedPreferences globalSharedPreferences;
|
2024-05-22 20:48:44 +00:00
|
|
|
|
|
|
|
|
final appRouter = AppRouter(ADMIN_BUILD);
|
|
|
|
|
|
|
|
|
|
AndroidDeviceInfo? androidDeviceInfo;
|
|
|
|
|
|
|
|
|
|
Future<bool> _screenOff() async =>
|
|
|
|
|
ADMIN_BUILD || await NoScreenshot.instance.screenshotOff();
|
|
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2024-05-28 21:25:51 +00:00
|
|
|
final stopwatch = Stopwatch()..start();
|
|
|
|
|
print('ensureInitialized ${stopwatch.elapsedMilliseconds}');
|
|
|
|
|
SystemChrome.setPreferredOrientations([
|
|
|
|
|
DeviceOrientation.portraitUp,
|
|
|
|
|
]);
|
2024-05-22 20:48:44 +00:00
|
|
|
androidDeviceInfo = await DeviceInfoPlugin().androidInfo;
|
2024-05-28 21:25:51 +00:00
|
|
|
print('deviceInfo ${stopwatch.elapsedMilliseconds}');
|
2024-05-22 20:48:44 +00:00
|
|
|
final isNotTrust = await JailbreakRootDetection.instance.isNotTrust;
|
2024-05-28 21:25:51 +00:00
|
|
|
print('No trunst ${stopwatch.elapsedMilliseconds}');
|
2024-05-22 20:48:44 +00:00
|
|
|
if (isNotTrust && !ADMIN_BUILD) {
|
|
|
|
|
print('Not trusted');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
final off = await _screenOff();
|
2024-05-28 21:25:51 +00:00
|
|
|
print('screenshot off ${stopwatch.elapsedMilliseconds}');
|
2024-05-22 20:48:44 +00:00
|
|
|
if (!off) {
|
|
|
|
|
print('Cant disable screenhsot');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-28 21:25:51 +00:00
|
|
|
|
|
|
|
|
FlutterError.onError = (errorDetails) {
|
|
|
|
|
FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-22 20:48:44 +00:00
|
|
|
try {
|
|
|
|
|
globalSharedPreferences = await SharedPreferences.getInstance();
|
2024-06-15 15:42:18 +00:00
|
|
|
await _fillSp();
|
2024-05-28 21:25:51 +00:00
|
|
|
print('global sp ${stopwatch.elapsedMilliseconds}');
|
2024-05-22 20:48:44 +00:00
|
|
|
await setInjections();
|
2024-05-28 21:25:51 +00:00
|
|
|
print('injections ${stopwatch.elapsedMilliseconds}');
|
|
|
|
|
unawaited(initFirebase());
|
|
|
|
|
print('initing... ${stopwatch.elapsedMilliseconds}');
|
2024-05-22 20:48:44 +00:00
|
|
|
await locator.packCacheManager.init();
|
2024-05-28 21:25:51 +00:00
|
|
|
await locator.previewPackHolder.init();
|
|
|
|
|
await locator.previewPackPoller.init();
|
2024-05-22 20:48:44 +00:00
|
|
|
await locator.packManager.init();
|
|
|
|
|
await locator.userManager.init();
|
|
|
|
|
await locator.favoriteCardsController.init();
|
|
|
|
|
await locator.previewPackPoller.init();
|
|
|
|
|
await locator.packUpdater.init();
|
2024-05-28 21:25:51 +00:00
|
|
|
print('initing complete ${stopwatch.elapsedMilliseconds}');
|
2024-05-22 20:48:44 +00:00
|
|
|
await MobileAds.initialize();
|
2024-05-28 21:25:51 +00:00
|
|
|
print('mobile ads ${stopwatch.elapsedMilliseconds}');
|
|
|
|
|
print('runApp ${stopwatch.elapsedMilliseconds}');
|
2024-05-22 20:48:44 +00:00
|
|
|
runApp(const MyApp());
|
|
|
|
|
} on Object catch (e, s) {
|
|
|
|
|
log(e.toString(), stackTrace: s);
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-15 15:42:18 +00:00
|
|
|
Future<void> _fillSp() async {
|
|
|
|
|
final soundOn = globalSharedPreferences.getBool('sound_on');
|
|
|
|
|
if (soundOn == null) {
|
|
|
|
|
globalSharedPreferences.setBool('sound_on', true);
|
|
|
|
|
}
|
|
|
|
|
final soundSpeed = globalSharedPreferences.getDouble('sound_speed');
|
|
|
|
|
if (soundSpeed == null) {
|
2024-06-15 15:54:21 +00:00
|
|
|
globalSharedPreferences.setDouble('sound_speed', 1.0);
|
2024-06-15 15:42:18 +00:00
|
|
|
}
|
2024-06-16 19:01:33 +00:00
|
|
|
final autoPlay = globalSharedPreferences.getBool('auto_play_sound_tests');
|
2024-06-15 15:42:18 +00:00
|
|
|
if (autoPlay == null) {
|
2024-06-16 19:01:33 +00:00
|
|
|
globalSharedPreferences.setBool('auto_play_sound_tests', true);
|
|
|
|
|
}
|
|
|
|
|
final autoPlayView = globalSharedPreferences.getBool('auto_play_sound_view');
|
|
|
|
|
if (autoPlayView == null) {
|
|
|
|
|
globalSharedPreferences.setBool('auto_play_sound_view', false);
|
2024-06-15 15:42:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 20:48:44 +00:00
|
|
|
Future<void> initFirebase() async {
|
|
|
|
|
try {
|
|
|
|
|
await Firebase.initializeApp(
|
|
|
|
|
options: DefaultFirebaseOptions.currentPlatform,
|
2024-05-28 21:25:51 +00:00
|
|
|
);
|
2024-05-22 20:48:44 +00:00
|
|
|
await FirebaseRepository.update();
|
|
|
|
|
} on Object catch (e, s) {
|
|
|
|
|
log('Firebase not inited', error: e, stackTrace: s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget with WidgetsBindingObserver {
|
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
WidgetsBinding.instance.addObserver(this);
|
|
|
|
|
return ScreenUtilInit(
|
|
|
|
|
designSize: const Size(370, 800),
|
|
|
|
|
minTextAdapt: true,
|
|
|
|
|
splitScreenMode: true,
|
|
|
|
|
child: MaterialApp.router(
|
|
|
|
|
theme: lightTheme,
|
|
|
|
|
routerConfig: appRouter.config(),
|
|
|
|
|
scaffoldMessengerKey: scaffoldMessengerKey,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
|
|
switch (state) {
|
|
|
|
|
case AppLifecycleState.resumed:
|
|
|
|
|
_screenOff();
|
|
|
|
|
break;
|
|
|
|
|
case AppLifecycleState.inactive:
|
|
|
|
|
_screenOff();
|
|
|
|
|
break;
|
|
|
|
|
case AppLifecycleState.paused:
|
|
|
|
|
_screenOff();
|
|
|
|
|
break;
|
|
|
|
|
case AppLifecycleState.detached:
|
|
|
|
|
break;
|
|
|
|
|
case AppLifecycleState.hidden:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RoutePage()
|
|
|
|
|
class MainTabsPage extends StatefulWidget {
|
|
|
|
|
const MainTabsPage({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<MainTabsPage> createState() => _MainTabsPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _MainTabsPageState extends State<MainTabsPage> {
|
|
|
|
|
late List<CardPackDto> cardPacks;
|
|
|
|
|
late List<GameCardDto> cards;
|
|
|
|
|
CardPackDto? pack;
|
|
|
|
|
|
|
|
|
|
late Repository repository;
|
|
|
|
|
late PackManager packManager;
|
|
|
|
|
|
|
|
|
|
_Tabs _currentTab = _Tabs.home;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
repository = locator.repository;
|
|
|
|
|
packManager = locator.packManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final theme = Theme.of(context).textTheme;
|
|
|
|
|
return AutoTabsRouter.tabBar(
|
|
|
|
|
key: scaffoldKey,
|
|
|
|
|
homeIndex: 0,
|
|
|
|
|
routes: [
|
|
|
|
|
PageRouteInfo(HomePage.name),
|
|
|
|
|
// PageRouteInfo(ExplorePage.name),
|
|
|
|
|
// PageRouteInfo(ProfilePage.name),
|
|
|
|
|
],
|
|
|
|
|
builder: (_, child, tabsController) => Scaffold(
|
|
|
|
|
body: child,
|
|
|
|
|
// bottomNavigationBar: Container(
|
|
|
|
|
// child: DotNavigationBar(
|
|
|
|
|
// currentIndex: tabsController.index,
|
|
|
|
|
// dotIndicatorColor: Colors.white,
|
|
|
|
|
// unselectedItemColor: Colors.grey[300],
|
|
|
|
|
// marginR: EdgeInsets.symmetric(horizontal: 32),
|
|
|
|
|
// itemPadding: EdgeInsets.symmetric(vertical: 12.0, horizontal: 24.0),
|
|
|
|
|
// duration: Duration(milliseconds: 300),
|
|
|
|
|
// paddingR: EdgeInsets.zero,
|
|
|
|
|
// borderRadius: 32,
|
|
|
|
|
// enableFloatingNavBar: true,
|
|
|
|
|
// enablePaddingAnimation: false,
|
|
|
|
|
// splashBorderRadius: 32,
|
|
|
|
|
// boxShadow: [
|
|
|
|
|
// BoxShadow(
|
|
|
|
|
// color: Colors.black26,
|
|
|
|
|
// blurRadius: 8.0,
|
|
|
|
|
// )
|
|
|
|
|
// ],
|
|
|
|
|
// onTap: (i) {
|
|
|
|
|
// tabsController.index = i;
|
|
|
|
|
// },
|
|
|
|
|
// items: [
|
|
|
|
|
// /// Home
|
|
|
|
|
// DotNavigationBarItem(
|
|
|
|
|
// icon: Icon(
|
|
|
|
|
// Icons.home,
|
|
|
|
|
// size: 32,
|
|
|
|
|
// ),
|
|
|
|
|
// selectedColor: Colors.redAccent,
|
|
|
|
|
// ),
|
|
|
|
|
//
|
|
|
|
|
// /// Search
|
|
|
|
|
// DotNavigationBarItem(
|
|
|
|
|
// icon: Icon(
|
|
|
|
|
// Icons.search,
|
|
|
|
|
// size: 32,
|
|
|
|
|
// ),
|
|
|
|
|
// selectedColor: Colors.redAccent,
|
|
|
|
|
// ),
|
|
|
|
|
//
|
|
|
|
|
// /// Profile
|
|
|
|
|
// DotNavigationBarItem(
|
|
|
|
|
// icon: Icon(
|
|
|
|
|
// Icons.person,
|
|
|
|
|
// size: 32,
|
|
|
|
|
// ),
|
|
|
|
|
// selectedColor: Colors.redAccent,
|
|
|
|
|
// ),
|
|
|
|
|
// ],
|
|
|
|
|
// ),
|
|
|
|
|
// ),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum _Tabs { home, packs, profile }
|