import 'package:wanisclient/config/custom_text.dart'; import 'package:wanisclient/config/custom_text.dart'; import 'package:wanisclient/utils/colors.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../providers/ContactProvider.dart'; class ContactUsScreen extends StatefulWidget { const ContactUsScreen({Key? key}) : super(key: key); @override _ContactUsScreenState createState() => _ContactUsScreenState(); } class _ContactUsScreenState extends State { final _formKey = GlobalKey(); final _subjectController = TextEditingController(); final _messageController = TextEditingController(); final _subjectFocusNode = FocusNode(); final _messageFocusNode = FocusNode(); @override void dispose() { _subjectController.dispose(); _messageController.dispose(); _subjectFocusNode.dispose(); _messageFocusNode.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final contactus = Provider.of(context); final theme = Theme.of(context); return Container( decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [ Colors.grey.shade50, Colors.white, ], ), ), child: Column( children: [ // Handle bar Container( margin: const EdgeInsets.only(top: 12), width: 40, height: 4, decoration: BoxDecoration( color: Colors.grey.shade300, borderRadius: BorderRadius.circular(2), ), ), // Header Padding( padding: const EdgeInsets.all(24.0), child: Row( children: [ Container( padding: const EdgeInsets.all(12), decoration: BoxDecoration( color: AppColors.primaryColor.withOpacity(0.1), borderRadius: BorderRadius.circular(12), ), child: const Icon( Icons.mail_outline, color: AppColors.primaryColor, size: 24, ), ), const SizedBox(width: 16), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Txt( text: 'Contact Us', style: theme.textTheme.headlineSmall!.copyWith( fontWeight: FontWeight.bold, color: Colors.grey.shade800, ), ), const SizedBox(height: 4), Txt( text: 'to hear from you', style: theme.textTheme.bodyMedium!.copyWith( color: Colors.grey.shade600, ), ), ], ), ), IconButton( onPressed: () => Navigator.of(context).pop(), icon: Icon( Icons.close, color: Colors.grey.shade600, ), ), ], ), ), // Form Expanded( child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.symmetric(horizontal: 24.0), child: Form( key: _formKey, child: Column( children: [ // Subject field Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(16), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.1), spreadRadius: 1, blurRadius: 10, offset: const Offset(0, 2), ), ], ), child: TextFormField( controller: _subjectController, focusNode: _subjectFocusNode, decoration: InputDecoration( label: const Txt( text: 'Subject', style: TextStyle(), ), labelStyle: TextStyle( color: Colors.grey.shade600, fontWeight: FontWeight.w500, ), prefixIcon: Icon( Icons.subject, color: Colors.grey.shade400, ), border: OutlineInputBorder( borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none, ), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(16), borderSide: const BorderSide( color: AppColors.primaryColor, width: 2, ), ), filled: true, fillColor: Colors.white, contentPadding: const EdgeInsets.symmetric( vertical: 20, horizontal: 16, ), ), validator: (value) => value?.isEmpty ?? true ? 'Please enter a subject' : null, textInputAction: TextInputAction.next, onFieldSubmitted: (_) => _messageFocusNode.requestFocus(), ), ), const SizedBox(height: 20), // Message field Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(16), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.1), spreadRadius: 1, blurRadius: 10, offset: const Offset(0, 2), ), ], ), child: TextFormField( controller: _messageController, focusNode: _messageFocusNode, maxLines: 6, decoration: InputDecoration( label: const Txt( text: 'Your Message', style: TextStyle(), ), labelStyle: TextStyle( color: Colors.grey.shade600, fontWeight: FontWeight.w500, ), prefixIcon: Padding( padding: const EdgeInsets.only(bottom: 80), child: Icon( Icons.message_outlined, color: Colors.grey.shade400, ), ), border: OutlineInputBorder( borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none, ), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(16), borderSide: const BorderSide( color: AppColors.primaryColor, width: 2, ), ), filled: true, fillColor: Colors.white, contentPadding: const EdgeInsets.symmetric( vertical: 20, horizontal: 16, ), ), validator: (value) => value?.isEmpty ?? true ? 'Please enter your message' : null, ), ), const SizedBox(height: 32), // Send button SizedBox( width: double.infinity, height: 56, child: contactus.isLoading ? Container( decoration: BoxDecoration( color: AppColors.primaryColor.withOpacity(0.1), borderRadius: BorderRadius.circular(16), ), child: const Center( child: SizedBox( width: 24, height: 24, child: CircularProgressIndicator( strokeWidth: 2, valueColor: AlwaysStoppedAnimation( //AppColors.primaryColor, Colors.limeAccent), ), ), ), ) : ElevatedButton( onPressed: () async { if (_formKey.currentState!.validate()) { // Hide keyboard FocusScope.of(context).unfocus(); final success = await contactus.submitContact( _subjectController.text.trim(), _messageController.text.trim(), ); if (mounted) { final snackBar = SnackBar( content: Row( children: [ Icon( success ? Icons.check_circle : Icons.error, color: Colors.white, size: 20, ), const SizedBox(width: 12), Expanded( child: Txt( text: success ? 'Message sent successfully!' : contactus.error ?? 'Failed to send message', style: const TextStyle( color: Colors.white, fontWeight: FontWeight.w500, ), ), ), ], ), backgroundColor: success ? Colors.green.shade600 : Colors.red.shade600, behavior: SnackBarBehavior.floating, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), margin: const EdgeInsets.all(16), ); ScaffoldMessenger.of(context) .showSnackBar(snackBar); if (success) { // Clear form and close modal after successful submission _subjectController.clear(); _messageController.clear(); Future.delayed( const Duration(seconds: 1), () { if (mounted) { Navigator.of(context).pop(); } }); } } } }, style: ElevatedButton.styleFrom( backgroundColor: AppColors.primaryColor, foregroundColor: Colors.white, elevation: 0, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), ), padding: const EdgeInsets.symmetric(vertical: 16), ), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ const Icon(Icons.send, size: 20), const SizedBox(width: 8), Txt( text: 'Send Message', style: theme.textTheme.titleMedium!.copyWith( color: Colors.white, fontWeight: FontWeight.w600, ), ), ], ), ), ), const SizedBox(height: 24), ], ), ), ), ), ), ], ), ); } }