cargo66/lib/presentation/screens/profile.dart

245 lines
6.7 KiB
Dart
Raw Normal View History

2024-08-03 07:58:07 +00:00
import 'package:easy_localization/easy_localization.dart';
2024-08-02 10:44:37 +00:00
import 'package:flutter/material.dart';
2024-08-07 13:56:12 +00:00
import 'package:flutter_bloc/flutter_bloc.dart';
2024-08-02 10:44:37 +00:00
2024-08-07 13:56:12 +00:00
import '../../application/user_bloc/user_bloc.dart';
2024-08-02 10:44:37 +00:00
import '../../configs/configs.dart';
import '../../core/core.dart';
2024-08-07 13:56:12 +00:00
import '../../domain/entities/user/user.dart';
import '../widgets/lang_selection.dart';
2024-08-02 10:44:37 +00:00
2024-08-07 13:56:12 +00:00
class ProfileScreen extends StatefulWidget {
2024-08-02 10:44:37 +00:00
const ProfileScreen({super.key});
2024-08-07 13:56:12 +00:00
@override
State<ProfileScreen> createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen> {
@override
void initState() {
super.initState();
2024-08-08 08:51:47 +00:00
context.read<UserBloc>().add(GetUser());
2024-08-07 13:56:12 +00:00
}
2024-08-02 10:44:37 +00:00
@override
Widget build(BuildContext context) {
App.init(context);
return Scaffold(
backgroundColor: AppColors.surface,
2024-08-08 08:51:47 +00:00
body: BlocConsumer<UserBloc, UserState>(
listener: (context, state) {
if (state is UserLoggedOut || state is UserLoggedFail) {
_navigateToLoginScreen(context);
}
},
2024-08-07 13:56:12 +00:00
builder: (context, state) {
if (state is UserLoading) {
return const Center(child: CircularProgressIndicator());
} else if (state is UserFetched) {
return _buildProfileContent(context, state.user);
} else if (state is UserLoggedFail) {
2024-08-08 05:40:30 +00:00
return ErrorUtil.buildErrorContent(
context,
state.failure,
() {
context.read<UserBloc>().add(GetRemoteUser());
},
);
2024-08-07 13:56:12 +00:00
} else {
return const SizedBox.shrink();
}
},
),
);
}
2024-08-02 10:44:37 +00:00
2024-08-07 13:56:12 +00:00
Widget _buildProfileContent(BuildContext context, User user) {
return SingleChildScrollView(
child: Padding(
padding: Space.all(1, 1),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
/// gap
2024-08-19 04:50:22 +00:00
Space.yf(1.3),
2024-08-02 10:44:37 +00:00
2024-08-07 13:56:12 +00:00
/// header
Text(
'Şahsy otagym',
style: AppText.h1b,
),
2024-08-02 10:44:37 +00:00
2024-08-07 13:56:12 +00:00
Space.y!,
2024-08-02 10:44:37 +00:00
2024-08-07 13:56:12 +00:00
/// card
SizedBox(
width: double.infinity,
child: Card(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
/// name surname
RowWidget(
text: user.fullName,
leadingIcon: Icons.person_2_outlined,
),
2024-08-02 10:44:37 +00:00
2024-08-07 13:56:12 +00:00
/// gap
Space.yf(1),
/// phone
RowWidget(
text: user.phone,
leadingIcon: Icons.phone_android_outlined,
),
],
2024-08-02 10:44:37 +00:00
),
),
),
2024-08-07 13:56:12 +00:00
),
2024-08-02 10:44:37 +00:00
2024-08-07 13:56:12 +00:00
///gap
Space.yf(2),
/// card
const SizedBox(
width: double.infinity,
child: Card(
color: Colors.white,
child: Padding(
padding: EdgeInsets.all(16.0),
child: RowWidget(
text: 'Tehniki goldaw bilen habarlaşmak',
leadingIcon: Icons.contact_support_outlined,
trailingIcon: Icons.arrow_forward_ios,
2024-08-02 10:44:37 +00:00
),
),
),
2024-08-07 13:56:12 +00:00
),
2024-08-02 10:44:37 +00:00
2024-08-07 13:56:12 +00:00
///gap
Space.yf(2),
/// card
SizedBox(
width: double.infinity,
child: Card(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
/// language
GestureDetector(
onTap: () => onSelectLang(context),
child: Container(
color: Colors.transparent,
child: RowWidget(
text: 'profile_select_lang'.tr(),
leadingIcon: Icons.language_outlined,
trailingIcon: Icons.arrow_forward_ios,
2024-08-03 07:58:07 +00:00
),
2024-08-02 10:44:37 +00:00
),
2024-08-07 13:56:12 +00:00
),
2024-08-02 10:44:37 +00:00
2024-08-07 13:56:12 +00:00
/// name surname
const RowWidget(
text: 'Gizlinlik syýasaty',
leadingIcon: Icons.gpp_maybe_outlined,
trailingIcon: Icons.arrow_forward_ios,
),
2024-08-02 10:44:37 +00:00
2024-08-07 13:56:12 +00:00
/// phone
const RowWidget(
text: 'Ulanyş şertleri',
leadingIcon: Icons.file_copy_outlined,
trailingIcon: Icons.arrow_forward_ios,
),
],
2024-08-02 10:44:37 +00:00
),
),
),
2024-08-07 13:56:12 +00:00
),
///gap
Space.yf(2),
2024-08-02 10:44:37 +00:00
2024-08-07 13:56:12 +00:00
/// logout
Align(
alignment: Alignment.center,
child: TextButton(
2024-08-08 08:51:47 +00:00
onPressed: () {
context.read<UserBloc>().add(SignOutUser());
},
2024-08-07 13:56:12 +00:00
child: Text(
'Şahsy otagdan çykmak',
style: AppText.b1!.copyWith(
color: Colors.red,
2024-08-02 10:44:37 +00:00
),
),
),
2024-08-07 13:56:12 +00:00
),
2024-08-02 10:44:37 +00:00
2024-08-07 13:56:12 +00:00
///gap
Space.yf(2),
],
2024-08-02 10:44:37 +00:00
),
),
);
}
2024-08-08 08:51:47 +00:00
void _navigateToLoginScreen(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.of(context).pushNamedAndRemoveUntil(
AppRouter.login,
(route) => false,
);
});
}
2024-08-02 10:44:37 +00:00
}
class RowWidget extends StatelessWidget {
final String text;
final IconData leadingIcon;
final IconData? trailingIcon;
const RowWidget({
super.key,
required this.text,
required this.leadingIcon,
this.trailingIcon,
});
@override
Widget build(BuildContext context) {
2024-08-03 07:58:07 +00:00
return Padding(
padding: Space.vf(0.5),
child: Row(
children: [
2024-08-02 10:44:37 +00:00
Icon(
2024-08-03 07:58:07 +00:00
leadingIcon,
2024-08-02 10:44:37 +00:00
color: AppColors.darkGrey,
),
2024-08-03 07:58:07 +00:00
Space.x!,
Text(
text,
style: AppText.b1!.copyWith(
color: AppColors.darkGrey,
),
),
if (trailingIcon != null) ...[
const Spacer(),
Icon(
trailingIcon,
color: AppColors.darkGrey,
size: AppDimensions.normalize(7),
),
]
],
),
2024-08-02 10:44:37 +00:00
);
}
}