import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:injector/injector.dart'; import 'package:prosappco/blocs/suggestion_bloc/suggestion_bloc.dart'; const _kPrimary = Color(0xFF1565C0); class SuggestionScreen extends StatefulWidget { const SuggestionScreen({super.key}); @override State createState() => _SuggestionScreenState(); } class _SuggestionScreenState extends State { final _formKey = GlobalKey(); final _messageController = TextEditingController(); bool _isLoading = false; @override void dispose() { _messageController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return BlocProvider( create: (_) => Injector.appInstance.get(), child: BlocListener( listener: (context, state) { if (state is SuggestionLoading) { setState(() => _isLoading = true); } else if (state is SuggestionSuccess) { setState(() => _isLoading = false); ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('¡Gracias por tu sugerencia!')), ); Navigator.of(context).pop(); } else if (state is SuggestionFailure) { setState(() => _isLoading = false); ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('No se pudo enviar la sugerencia'), ), ); } }, child: Scaffold( appBar: AppBar(title: const Text('Sugerencias')), body: Padding( padding: const EdgeInsets.all(16), child: Form( key: _formKey, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text( '¿Tienes una idea o algo que podamos mejorar? ' 'Cuéntanos.', style: TextStyle(fontSize: 14, color: Colors.grey), ), const SizedBox(height: 16), TextFormField( controller: _messageController, minLines: 5, maxLines: 8, maxLength: 1000, decoration: InputDecoration( hintText: 'Escribe tu sugerencia aquí...', alignLabelWithHint: true, border: OutlineInputBorder( borderRadius: BorderRadius.circular(12), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: Colors.grey.shade300), ), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: _kPrimary, width: 2), ), ), validator: (v) => (v == null || v.trim().isEmpty) ? 'Escribe un mensaje' : null, ), const SizedBox(height: 24), SizedBox( width: double.infinity, child: ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: _kPrimary, foregroundColor: Colors.white, padding: const EdgeInsets.symmetric(vertical: 14), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), ), onPressed: _isLoading ? null : () { if (_formKey.currentState?.validate() != true) { return; } context.read().add( SubmitSuggestion( message: _messageController.text.trim(), ), ); }, child: _isLoading ? const SizedBox( height: 20, width: 20, child: CircularProgressIndicator( strokeWidth: 2, color: Colors.white, ), ) : const Text('Enviar'), ), ), ], ), ), ), ), ), ); } }