115 lines
3.5 KiB
Dart
115 lines
3.5 KiB
Dart
// ================================================================
|
|
// main.dart — EcoTrack
|
|
// Sistema de Notificacion Privada de Recoleccion de Residuos
|
|
// ================================================================
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'screens/login_screen.dart';
|
|
import 'screens/home_screen.dart';
|
|
import 'screens/route_list_screen.dart';
|
|
import 'screens/info_screen.dart';
|
|
import 'screens/analytics_screen.dart';
|
|
import 'screens/reporte_screen.dart';
|
|
import 'screens/mapa_rutas_screen.dart';
|
|
import 'firebase_options.dart';
|
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
|
|
const AndroidNotificationChannel _canal = AndroidNotificationChannel(
|
|
'ecotrack_canal',
|
|
'EcoTrack Notificaciones',
|
|
description: 'Notificaciones del camión de basura',
|
|
importance: Importance.high,
|
|
);
|
|
|
|
final FlutterLocalNotificationsPlugin _localNotifications =
|
|
FlutterLocalNotificationsPlugin();
|
|
|
|
@pragma('vm:entry-point')
|
|
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
|
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
|
}
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
|
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
|
|
|
// DESPUÉS
|
|
final androidPlugin =
|
|
_localNotifications.resolvePlatformSpecificImplementation<
|
|
AndroidFlutterLocalNotificationsPlugin>();
|
|
await androidPlugin?.createNotificationChannel(_canal);
|
|
|
|
await _localNotifications.initialize(
|
|
const InitializationSettings(
|
|
android: AndroidInitializationSettings('@mipmap/ic_launcher'),
|
|
),
|
|
);
|
|
|
|
// ← EL QUE TE FALTABA
|
|
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
|
final notification = message.notification;
|
|
if (notification == null) return;
|
|
_localNotifications.show(
|
|
notification.hashCode,
|
|
notification.title,
|
|
notification.body,
|
|
NotificationDetails(
|
|
android: AndroidNotificationDetails(
|
|
_canal.id,
|
|
_canal.name,
|
|
channelDescription: _canal.description,
|
|
importance: Importance.high,
|
|
priority: Priority.high,
|
|
icon: '@mipmap/ic_launcher',
|
|
),
|
|
),
|
|
);
|
|
});
|
|
|
|
await FirebaseMessaging.instance.requestPermission(
|
|
alert: true,
|
|
badge: true,
|
|
sound: true,
|
|
);
|
|
|
|
runApp(const EcoTrackApp());
|
|
}
|
|
|
|
class EcoTrackApp extends StatelessWidget {
|
|
const EcoTrackApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'EcoTrack',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: const Color(0xFF2E7D32),
|
|
brightness: Brightness.light,
|
|
),
|
|
useMaterial3: true,
|
|
fontFamily: 'Roboto',
|
|
appBarTheme: const AppBarTheme(
|
|
centerTitle: false,
|
|
elevation: 0,
|
|
),
|
|
),
|
|
initialRoute: '/',
|
|
routes: {
|
|
'/': (context) => const LoginScreen(),
|
|
'/home': (context) => const HomeScreen(),
|
|
'/routes': (context) => const RouteListScreen(),
|
|
'/info': (context) => const InfoScreen(),
|
|
'/analytics': (context) => const AnalyticsScreen(),
|
|
'/reporte': (context) => const ReporteScreen(),
|
|
'/mapa': (context) => const MapaRutasScreen(),
|
|
},
|
|
);
|
|
}
|
|
}
|