proxibuy/lib/presentation/pages/user_info_page.dart

201 lines
7.2 KiB
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();
}
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(
// ignore: deprecated_member_use
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) {
if (state is AuthFailure) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.message),
backgroundColor: Colors.red,
),
);
}
},
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: () {
Navigator.of(context).pushReplacement(
NotificationPreferencesPage.route(),
);
},
child: const Text(
"رد شدن",
style: TextStyle(color: Colors.black),
),
),
),
],
),
),
);
},
),
],
),
);
}
}