import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:proxibuy/presentation/auth/bloc/auth_bloc.dart'; import 'package:proxibuy/presentation/pages/notification_preferences_page.dart'; import '../../core/config/app_colors.dart'; import '../../core/gen/assets.gen.dart'; class UserInfoPage extends StatefulWidget { const UserInfoPage({super.key}); @override State createState() => _UserInfoPageState(); } class _UserInfoPageState extends State { final _nameController = TextEditingController(); String _selectedGender = 'male'; @override void dispose() { _nameController.dispose(); super.dispose(); } void _navigateToNextPage() { Navigator.of(context).pushReplacement( MaterialPageRoute( builder: (context) => const NotificationPreferencesPage(), ), ); } Widget _buildGenderRadio(String title, String value) { return InkWell( onTap: () => setState(() => _selectedGender = value), child: Row( mainAxisSize: MainAxisSize.min, children: [ Radio( value: value, groupValue: _selectedGender, onChanged: (newValue) => setState(() => _selectedGender = newValue!), activeColor: AppColors.primary, ), Text(title, style: const TextStyle(color: Colors.grey)), ], ), ); } void _submitUserInfo() { if (_nameController.text.isNotEmpty) { context.read().add( UpdateUserInfoEvent( name: _nameController.text, gender: _selectedGender, ), ); } else { ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('لطفا نام خود را وارد کنید.'), backgroundColor: Colors.red, ), ); } } @override Widget build(BuildContext context) { final textTheme = Theme.of(context).textTheme; return Scaffold( body: Stack( children: [ Positioned.fill( child: Image.asset(Assets.images.userinfo.path, fit: BoxFit.cover), ), DraggableScrollableSheet( initialChildSize: 0.50, minChildSize: 0.50, maxChildSize: 0.50, builder: (context, scrollController) { return Container( decoration: const BoxDecoration( color: Colors.white, borderRadius: BorderRadius.vertical(top: Radius.circular(32)), ), child: SingleChildScrollView( controller: scrollController, padding: const EdgeInsets.all(24.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Center( child: Container( width: 50, height: 5, decoration: BoxDecoration( color: Colors.grey.withOpacity(0.5), borderRadius: BorderRadius.circular(12), ), ), ), const SizedBox(height: 40), TextField( controller: _nameController, textAlign: TextAlign.right, decoration: const InputDecoration( labelText: "دوست داری با چه اسمی صدات کنیم؟", labelStyle: TextStyle( fontWeight: FontWeight.bold, fontSize: 20, ), hintText: "مثلا نام کوچک شما", hintStyle: TextStyle( fontSize: 15, color: Colors.grey, ), ), ), const SizedBox(height: 24), Text( "جنسیت", style: textTheme.titleMedium?.copyWith( color: Colors.black, ), ), const SizedBox(height: 8), Wrap( spacing: 10.0, runSpacing: 8.0, children: [ _buildGenderRadio('مرد', 'male'), _buildGenderRadio('زن', 'female'), _buildGenderRadio('تمایلی به پاسخ ندارم', 'none'), ], ), const SizedBox(height: 55), BlocConsumer( listener: (context, state) { debugPrint( "UserInfoPage: 🟠 Listener یک State جدید دریافت کرد: ${state.runtimeType}", ); if (state is AuthFailure) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text(state.message), backgroundColor: Colors.red, ), ); } if (state is AuthSuccess) { debugPrint( "UserInfoPage: ✅ State از نوع AuthSuccess است. فراخوانی _navigateToNextPage...", ); _navigateToNextPage(); } }, builder: (context, state) { final isLoading = state is AuthLoading; return Column( children: [ SizedBox( width: double.infinity, height: 60, child: ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: AppColors.confirm, foregroundColor: Colors.white, ), onPressed: isLoading ? null : _submitUserInfo, child: isLoading ? const CircularProgressIndicator( color: Colors.white, ) : const Text("اعمال"), ), ), const SizedBox(height: 9), ], ); }, ), const SizedBox(height: 9), Center( child: TextButton( onPressed: _navigateToNextPage, child: const Text( "رد شدن", style: TextStyle(color: Colors.black), ), ), ), ], ), ), ); }, ), ], ), ); } }