proxibuy/lib/presentation/pages/user_info_page.dart

217 lines
8.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// lib/presentation/pages/user_info_page.dart
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<UserInfoPage> createState() => _UserInfoPageState();
}
class _UserInfoPageState extends State<UserInfoPage> {
final _nameController = TextEditingController();
String _selectedGender = 'male';
@override
void dispose() {
_nameController.dispose();
super.dispose();
}
// ******** شروع تغییر ۱ ********
// متد ناوبری را ساده می‌کنیم.
// این متد دیگر Provider جدیدی نمی‌سازد و از Provider های سراسری استفاده می‌کند.
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<String>(
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<AuthBloc>().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<AuthBloc, AuthState>(
listener: (context, state) {
// ******** لاگ: 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) {
// ******** لاگ: state موفقیت آمیز بود ********
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),
),
),
),
],
),
),
);
},
),
],
),
);
}
}