2026-03-08 20:00:01 +01:00
|
|
|
import 'dart:io'; // Aggiunto per il controllo Platform.isIOS
|
2026-02-27 23:26:13 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
|
|
|
import 'package:firebase_auth/firebase_auth.dart';
|
|
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
|
|
|
|
2026-03-08 20:00:01 +01:00
|
|
|
// --- LIBRERIE META SDK E TRACCIAMENTO APPLE ---
|
|
|
|
|
import 'package:app_tracking_transparency/app_tracking_transparency.dart';
|
|
|
|
|
import 'package:facebook_app_events/facebook_app_events.dart';
|
|
|
|
|
|
2026-02-27 23:26:13 +01:00
|
|
|
// ⚠️ IMPORTANTE: Assicurati che questo file esista (generato da flutterfire configure)
|
|
|
|
|
import 'firebase_options.dart';
|
|
|
|
|
|
|
|
|
|
import 'global_data.dart';
|
|
|
|
|
import 'scelta_lato.dart';
|
|
|
|
|
import 'carro_attr.dart';
|
|
|
|
|
import 'ps.dart';
|
|
|
|
|
|
2026-03-08 20:00:01 +01:00
|
|
|
// Istanza globale per tracciare gli eventi su Meta
|
|
|
|
|
final facebookAppEvents = FacebookAppEvents();
|
|
|
|
|
|
2026-02-27 23:26:13 +01:00
|
|
|
void main() async {
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
|
|
// 1. BLOCCO INIZIALE VERTICALE
|
|
|
|
|
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
|
|
|
|
|
|
|
|
|
// 2. INIZIALIZZAZIONE FIREBASE CON BIVIO IOS/ANDROID
|
|
|
|
|
// Il controllo .isEmpty evita il crash "Duplicate App" durante il debug
|
|
|
|
|
if (Firebase.apps.isEmpty) {
|
|
|
|
|
await Firebase.initializeApp(
|
|
|
|
|
// Questa riga gestisce automaticamente il bivio tra le chiavi Android e iOS
|
|
|
|
|
// leggendole dal file firebase_options.dart
|
|
|
|
|
options: DefaultFirebaseOptions.currentPlatform,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_effettuaLoginAnonimo();
|
|
|
|
|
runApp(const MyApp());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _effettuaLoginAnonimo() async {
|
|
|
|
|
try {
|
|
|
|
|
if (FirebaseAuth.instance.currentUser == null) {
|
|
|
|
|
await FirebaseAuth.instance.signInAnonymously();
|
|
|
|
|
debugPrint("✅ Login anonimo effettuato.");
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
debugPrint("⚠️ Login anonimo fallito (ritento tra 2s): $e");
|
|
|
|
|
Future.delayed(const Duration(seconds: 2), _effettuaLoginAnonimo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return MaterialApp(
|
|
|
|
|
title: 'La tua App CAI',
|
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
|
|
|
|
|
|
// --- IMPOSTIAMO I COLORI GLOBALI DEL CALENDARIO E DELL'APP ---
|
|
|
|
|
theme: ThemeData.light().copyWith(
|
|
|
|
|
colorScheme: const ColorScheme.light(
|
|
|
|
|
primary: Color(0xFF1565C0), // Blu (usato per i calendari)
|
|
|
|
|
onPrimary: Colors.white,
|
|
|
|
|
onSurface: Colors.black,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
localizationsDelegates: const [
|
|
|
|
|
GlobalMaterialLocalizations.delegate,
|
|
|
|
|
GlobalWidgetsLocalizations.delegate,
|
|
|
|
|
GlobalCupertinoLocalizations.delegate,
|
|
|
|
|
],
|
|
|
|
|
supportedLocales: const [
|
|
|
|
|
Locale('it', 'IT'),
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
home: const HomeScreen(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
|
|
|
const HomeScreen({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _HomeScreenState extends State<HomeScreen> with RouteAware {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
// Al primo avvio puliamo tutto
|
|
|
|
|
_resetCompleto();
|
2026-03-08 20:00:01 +01:00
|
|
|
|
|
|
|
|
// --- NUOVO CODICE: TRACCIAMENTO APPLE ---
|
|
|
|
|
// Lancia la richiesta di tracciamento appena la UI è pronta e visibile
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
_richiediTracciamentoApple();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- NUOVO METODO PER IL POPUP APPLE E EVENTI META ---
|
|
|
|
|
Future<void> _richiediTracciamentoApple() async {
|
|
|
|
|
// Il popup serve ESCLUSIVAMENTE su iOS
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
final TrackingStatus status = await AppTrackingTransparency.trackingAuthorizationStatus;
|
|
|
|
|
|
|
|
|
|
// Se l'utente non ha ancora fatto una scelta (è il primissimo avvio)
|
|
|
|
|
if (status == TrackingStatus.notDetermined) {
|
|
|
|
|
// Pausa vitale: Apple boccia le app se il popup appare prima che lo schermo sia ben visibile
|
|
|
|
|
await Future.delayed(const Duration(milliseconds: 500));
|
|
|
|
|
|
|
|
|
|
// Mostra il popup di sistema all'utente
|
|
|
|
|
await AppTrackingTransparency.requestTrackingAuthorization();
|
|
|
|
|
|
|
|
|
|
// Logga l'evento della prima apertura su Facebook
|
|
|
|
|
facebookAppEvents.logEvent(name: 'app_opened_first_time');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Su Android non c'è il blocco ATT, possiamo loggare liberamente l'apertura
|
|
|
|
|
facebookAppEvents.logEvent(name: 'app_opened_android');
|
|
|
|
|
}
|
2026-02-27 23:26:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Metodo centralizzato per reset e orientamento
|
|
|
|
|
Future<void> _resetCompleto() async {
|
|
|
|
|
GlobalData.reset();
|
|
|
|
|
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
|
|
|
|
debugPrint("🏠 Home: Dati resettati e Verticale forzato.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
// Intercettiamo il "ritorno" alla home per forzare il verticale
|
|
|
|
|
// (utile se si torna indietro con gesture o tasto back fisico)
|
|
|
|
|
return PopScope(
|
|
|
|
|
canPop: false, // La home è la root, non si esce
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
extendBodyBehindAppBar: true,
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
title: const Text(
|
|
|
|
|
'CAI Facile',
|
|
|
|
|
style: TextStyle(fontWeight: FontWeight.w900, letterSpacing: 1.5, fontSize: 24)
|
|
|
|
|
),
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
backgroundColor: Colors.blue.shade900.withOpacity(0.95),
|
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
|
elevation: 10,
|
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.vertical(bottom: Radius.circular(20))
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
body: Stack(
|
|
|
|
|
children: [
|
|
|
|
|
// 1. Sfondo Base (Mappa)
|
|
|
|
|
const Positioned.fill(child: BackgroundImage()),
|
|
|
|
|
|
|
|
|
|
// Contenuto
|
|
|
|
|
SafeArea(
|
|
|
|
|
child: Center(
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
physics: const BouncingScrollPhysics(),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 20),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
|
|
// 1. Compila Sinistro
|
|
|
|
|
_buildButton3D(
|
|
|
|
|
context: context,
|
|
|
|
|
label: "COMPILA SINISTRO",
|
|
|
|
|
icon: Icons.assignment_outlined,
|
|
|
|
|
baseColor: Colors.blue.shade800,
|
|
|
|
|
onTap: () async {
|
|
|
|
|
// Reset esplicito prima di iniziare
|
|
|
|
|
await _resetCompleto();
|
2026-03-08 20:00:01 +01:00
|
|
|
|
|
|
|
|
// Logghiamo l'inizio di una compilazione su Meta
|
|
|
|
|
facebookAppEvents.logEvent(name: 'cai_start_compilation');
|
|
|
|
|
|
2026-02-27 23:26:13 +01:00
|
|
|
if (context.mounted) {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(builder: (c) => const SceltaLatoScreen())
|
|
|
|
|
).then((_) {
|
|
|
|
|
// Quando l'utente torna indietro dalla compilazione,
|
|
|
|
|
// forziamo di nuovo il reset e il verticale
|
|
|
|
|
_resetCompleto();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
const SizedBox(height: 25),
|
|
|
|
|
|
|
|
|
|
// 2. Carro Attrezzi
|
|
|
|
|
_buildButton3D(
|
|
|
|
|
context: context,
|
|
|
|
|
label: "SOS CARRO ATTREZZI",
|
|
|
|
|
icon: Icons.support_agent,
|
|
|
|
|
baseColor: Colors.red.shade800,
|
|
|
|
|
onTap: () {
|
2026-03-08 20:00:01 +01:00
|
|
|
facebookAppEvents.logEvent(name: 'open_carro_attrezzi');
|
2026-02-27 23:26:13 +01:00
|
|
|
Navigator.push(context, MaterialPageRoute(builder: (c) => const CarroAttrezziScreen()));
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
const SizedBox(height: 25),
|
|
|
|
|
|
|
|
|
|
// 3. Pronto Soccorso
|
|
|
|
|
_buildButton3D(
|
|
|
|
|
context: context,
|
|
|
|
|
label: "PRONTO SOCCORSO",
|
|
|
|
|
icon: Icons.local_hospital_outlined,
|
|
|
|
|
baseColor: Colors.green.shade800,
|
|
|
|
|
onTap: () {
|
2026-03-08 20:00:01 +01:00
|
|
|
facebookAppEvents.logEvent(name: 'open_pronto_soccorso');
|
2026-02-27 23:26:13 +01:00
|
|
|
Navigator.push(context, MaterialPageRoute(builder: (c) => const ProntoSoccorsoScreen()));
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Widget helper per i bottoni con effetto 3D
|
|
|
|
|
Widget _buildButton3D({
|
|
|
|
|
required BuildContext context,
|
|
|
|
|
required String label,
|
|
|
|
|
required IconData icon,
|
|
|
|
|
required Color baseColor,
|
|
|
|
|
required VoidCallback onTap,
|
|
|
|
|
}) {
|
|
|
|
|
return Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(color: Colors.black.withOpacity(0.4), offset: const Offset(0, 6), blurRadius: 8, spreadRadius: 1)
|
|
|
|
|
],
|
|
|
|
|
gradient: LinearGradient(
|
|
|
|
|
begin: Alignment.topLeft,
|
|
|
|
|
end: Alignment.bottomRight,
|
|
|
|
|
colors: [
|
|
|
|
|
baseColor.withOpacity(0.9),
|
|
|
|
|
baseColor,
|
|
|
|
|
baseColor.withRed((baseColor.red - 20).clamp(0, 255))
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Material(
|
|
|
|
|
color: Colors.transparent,
|
|
|
|
|
child: InkWell(
|
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
|
onTap: onTap,
|
|
|
|
|
splashColor: Colors.white.withOpacity(0.2),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 20),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Icon(icon, size: 32, color: Colors.white),
|
|
|
|
|
const SizedBox(width: 20),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Text(
|
|
|
|
|
label,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontWeight: FontWeight.w800,
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
letterSpacing: 1.0
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
Icon(Icons.arrow_forward_ios, size: 18, color: Colors.white.withOpacity(0.7)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Widget Sfondo
|
|
|
|
|
class BackgroundImage extends StatelessWidget {
|
|
|
|
|
const BackgroundImage({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Container(
|
|
|
|
|
color: const Color(0xFFF0F4F8),
|
|
|
|
|
child: Image.asset(
|
|
|
|
|
'assets/sfondo_mappa.jpg',
|
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
|
color: const Color(0xFFF0F4F8).withOpacity(0.6),
|
|
|
|
|
colorBlendMode: BlendMode.lighten,
|
|
|
|
|
errorBuilder: (c, e, s) => Container(color: Colors.grey.shade200),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-03-10 21:04:19 +01:00
|
|
|
}
|