simulacion de estados y flujo de notificacion, modificacion de estilos en todas las vistas
This commit is contained in:
@@ -1,13 +1,95 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../core/widgets/app_widgets.dart';
|
||||
import '../../shared/widgets/eco_floating_button.dart';
|
||||
import '../notifications/notification_service.dart';
|
||||
import '../alerts/alerts_provider.dart';
|
||||
|
||||
class CitizenShell extends StatelessWidget {
|
||||
class CitizenShell extends ConsumerStatefulWidget {
|
||||
const CitizenShell({super.key, required this.child});
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
ConsumerState<CitizenShell> createState() => _CitizenShellState();
|
||||
}
|
||||
|
||||
class _CitizenShellState extends ConsumerState<CitizenShell> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
NotificationService.onFcmMessage.addListener(_onGlobalPush);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
NotificationService.onFcmMessage.removeListener(_onGlobalPush);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onGlobalPush() {
|
||||
final msg = NotificationService.onFcmMessage.lastMessage;
|
||||
if (msg?.notification != null) {
|
||||
final title = msg!.notification!.title ?? 'Nueva Alerta';
|
||||
final body = msg.notification!.body ?? '';
|
||||
|
||||
// Guardamos la alerta en el historial
|
||||
ref.read(alertsProvider.notifier).addAlert(title, body);
|
||||
|
||||
// Mostramos un globo de notificación amigable dentro de la app
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: AppTheme.primaryDark,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
margin: const EdgeInsets.all(16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
duration: const Duration(seconds: 5),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.notifications_active,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
body,
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 13),
|
||||
),
|
||||
],
|
||||
),
|
||||
action: SnackBarAction(
|
||||
label: 'VER',
|
||||
textColor: AppTheme.primaryLight,
|
||||
onPressed: () => context.go('/alerts'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int _currentIndex(BuildContext context) {
|
||||
final location = GoRouterState.of(context).matchedLocation;
|
||||
if (location.startsWith('/alerts')) return 1;
|
||||
@@ -32,7 +114,7 @@ class CitizenShell extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: child,
|
||||
body: widget.child,
|
||||
floatingActionButton: const EcoFloatingButton(),
|
||||
bottomNavigationBar: AppBottomNav(
|
||||
currentIndex: _currentIndex(context),
|
||||
|
||||
Reference in New Issue
Block a user