2026-03-04 21:00:00 +01:00
|
|
|
// ===========================================================================
|
|
|
|
|
// FILE: lib/main.dart
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
2026-03-18 14:00:00 +01:00
|
|
|
import 'dart:io' show Platform;
|
2026-02-27 23:35:54 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2026-03-05 15:00:00 +01:00
|
|
|
import 'package:flutter/foundation.dart';
|
2026-02-27 23:35:54 +01:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'core/theme_manager.dart';
|
|
|
|
|
import 'logic/game_controller.dart';
|
|
|
|
|
import 'ui/home/home_screen.dart';
|
2026-03-04 18:00:01 +01:00
|
|
|
import 'services/storage_service.dart';
|
2026-03-05 15:00:00 +01:00
|
|
|
import 'services/audio_service.dart';
|
2026-02-27 23:35:54 +01:00
|
|
|
import 'package:firebase_core/firebase_core.dart';
|
2026-03-04 19:00:00 +01:00
|
|
|
import 'package:firebase_auth/firebase_auth.dart';
|
2026-02-27 23:35:54 +01:00
|
|
|
import 'firebase_options.dart';
|
2026-03-05 15:00:00 +01:00
|
|
|
import 'package:firebase_app_check/firebase_app_check.dart';
|
2026-03-18 14:00:00 +01:00
|
|
|
import 'package:upgrader/upgrader.dart';
|
|
|
|
|
import 'package:in_app_update/in_app_update.dart';
|
2026-03-05 15:00:00 +01:00
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
|
|
|
import 'package:tetraq/l10n/app_localizations.dart';
|
2026-02-27 23:35:54 +01:00
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
|
|
await Firebase.initializeApp(
|
|
|
|
|
options: DefaultFirebaseOptions.currentPlatform,
|
|
|
|
|
);
|
|
|
|
|
|
2026-03-04 19:00:00 +01:00
|
|
|
await FirebaseAppCheck.instance.activate(
|
|
|
|
|
androidProvider: kDebugMode ? AndroidProvider.debug : AndroidProvider.playIntegrity,
|
|
|
|
|
appleProvider: kDebugMode ? AppleProvider.debug : AppleProvider.deviceCheck,
|
|
|
|
|
);
|
|
|
|
|
|
2026-03-04 18:00:01 +01:00
|
|
|
try {
|
|
|
|
|
await FirebaseAuth.instance.signInAnonymously();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
debugPrint("Errore Auth: $e");
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 23:35:54 +01:00
|
|
|
await StorageService.instance.init();
|
2026-03-04 21:00:00 +01:00
|
|
|
await AudioService.instance.init();
|
|
|
|
|
|
2026-02-27 23:35:54 +01:00
|
|
|
runApp(
|
|
|
|
|
MultiProvider(
|
|
|
|
|
providers: [
|
|
|
|
|
ChangeNotifierProvider(create: (_) => ThemeManager()),
|
|
|
|
|
ChangeNotifierProvider(create: (_) => GameController()),
|
|
|
|
|
],
|
|
|
|
|
child: const TetraQApp(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class TetraQApp extends StatelessWidget {
|
|
|
|
|
const TetraQApp({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return MaterialApp(
|
|
|
|
|
title: 'TetraQ',
|
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
|
theme: ThemeData(
|
|
|
|
|
fontFamily: 'Roboto',
|
|
|
|
|
useMaterial3: true,
|
|
|
|
|
),
|
2026-03-05 15:00:00 +01:00
|
|
|
|
|
|
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
|
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
|
|
|
|
2026-03-20 22:00:01 +01:00
|
|
|
// Nessun modificatore const richiesto qui.
|
|
|
|
|
home: UpdateWrapper(child: HomeScreen()),
|
2026-02-27 23:35:54 +01:00
|
|
|
);
|
|
|
|
|
}
|
2026-03-18 14:00:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
// WIDGET WRAPPER PER LA GESTIONE DEGLI AGGIORNAMENTI IBRIDI (iOS/Android)
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
class UpdateWrapper extends StatefulWidget {
|
|
|
|
|
final Widget child;
|
|
|
|
|
const UpdateWrapper({super.key, required this.child});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<UpdateWrapper> createState() => _UpdateWrapperState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _UpdateWrapperState extends State<UpdateWrapper> {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
if (!kIsWeb && Platform.isAndroid) {
|
|
|
|
|
_checkForAndroidUpdate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _checkForAndroidUpdate() async {
|
|
|
|
|
try {
|
|
|
|
|
final info = await InAppUpdate.checkForUpdate();
|
|
|
|
|
if (info.updateAvailability == UpdateAvailability.updateAvailable) {
|
|
|
|
|
if (info.flexibleUpdateAllowed) {
|
|
|
|
|
await InAppUpdate.startFlexibleUpdate();
|
2026-03-20 22:00:01 +01:00
|
|
|
await InAppUpdate.completeFlexibleUpdate();
|
2026-03-18 14:00:00 +01:00
|
|
|
}
|
|
|
|
|
else if (info.immediateUpdateAllowed) {
|
|
|
|
|
await InAppUpdate.performImmediateUpdate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
debugPrint("Errore in_app_update Android: $e");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
if (!kIsWeb && (Platform.isIOS || Platform.isMacOS)) {
|
|
|
|
|
return UpgradeAlert(
|
2026-03-18 16:00:01 +01:00
|
|
|
dialogStyle: (Platform.isIOS || Platform.isMacOS)
|
|
|
|
|
? UpgradeDialogStyle.cupertino
|
|
|
|
|
: UpgradeDialogStyle.material,
|
2026-03-20 22:00:01 +01:00
|
|
|
showIgnore: false,
|
|
|
|
|
showLater: true,
|
|
|
|
|
upgrader: Upgrader(),
|
2026-03-18 14:00:00 +01:00
|
|
|
child: widget.child,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return widget.child;
|
|
|
|
|
}
|
2026-02-27 23:35:54 +01:00
|
|
|
}
|