275 lines
8.9 KiB
Dart
275 lines
8.9 KiB
Dart
|
|
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';
|
||
|
|
|
||
|
|
// ⚠️ 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';
|
||
|
|
|
||
|
|
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();
|
||
|
|
}
|
||
|
|
|
||
|
|
// 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();
|
||
|
|
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: () {
|
||
|
|
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: () {
|
||
|
|
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),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|