import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:tangheem/api/user_api_client.dart'; import 'package:tangheem/app_state/app_state.dart'; import 'package:tangheem/classes/colors.dart'; import 'package:tangheem/classes/consts.dart'; import 'package:tangheem/classes/utils.dart'; import 'package:tangheem/extensions/int_extensions.dart'; import 'package:tangheem/extensions/string_extensions.dart'; import 'package:tangheem/extensions/widget_extensions.dart'; import 'package:tangheem/ui/dialogs/change_password_dialog.dart'; import 'package:tangheem/ui/dialogs/general_dialog.dart'; import 'package:tangheem/ui/screens/change_password_screen.dart'; class UserProfileScreen extends StatefulWidget { static const String routeName = "/profile"; UserProfileScreen({Key key}) : super(key: key); @override _UserProfileScreenState createState() { return _UserProfileScreenState(); } } class _UserProfileScreenState extends State { @override void initState() { super.initState(); } @override void dispose() { super.dispose(); } void deleteUserAccount() async { Utils.showLoading(context); try { await UserApiClient().deleteAccount(AppState().userId); SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.remove(GlobalConsts.userAuthData); AppState().setAuthenticationModel(null); Utils.showToast("تم حذف الحساب"); Navigator.pop(context); Utils.hideLoading(context); } catch (ex) { if (mounted) { Utils.hideLoading(context); Utils.handleException(ex, null); } } } @override Widget build(BuildContext context) { return SizedBox( width: double.infinity, child: Stack( alignment: Alignment.topCenter, children: [ Image.asset( "assets/icons/new/home_dark.jpg", fit: BoxFit.cover, height: double.infinity, opacity: const AlwaysStoppedAnimation(1), ), Container(color: ColorConsts.darkText.withOpacity(0.8)), Column( mainAxisSize: MainAxisSize.min, children: [ 100.height, Image.asset('assets/icons/new/Tangeem-logo-W.png', width: 50), 100.height, Container( width: 78, height: 78, decoration: BoxDecoration( shape: BoxShape.circle, color: ColorConsts.dark2Text, ), child: SvgPicture.asset( "assets/icons/new/user_acount.svg", color: Colors.white, ), ), 14.height, (AppState().userName ?? "").toText(25), 50.height, button("تغيير كلمة المرور").onPress(() { Navigator.pushNamed(context, ChangePasswordScreen.routeName); }), Container(width: 50, height: 1, color: ColorConsts.dark99Text).paddingOnly(top: 15, bottom: 15), button("تسجيل الخروج").onPress(() async { SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.remove(GlobalConsts.userAuthData); AppState().setAuthenticationModel(null); Utils.showToast("تسجيل خروج المستخدم"); Navigator.pop(context); }), Container(width: 50, height: 1, color: ColorConsts.dark99Text).paddingOnly(top: 15, bottom: 15), button("حذف الحساب").onPress(() { showDialog( context: context, barrierColor: Colors.white.withOpacity(0.2), builder: (BuildContext context) => GeneralDialog( message: "هل تود حذف حسابك عبر تطبيق تنغيم؟", backgroundColor: Color(0xff598A8D), buttonTitle: "تأكيد الحذف", buttonBorderColor: ColorConsts.brownLightColor, onTap: () { Navigator.pop(context); deleteUserAccount(); }, ), ); }), ], ), ], ), ); } Widget button(String title) { return Container( height: 36, width: 165, alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.circular(32), border: Border.all(color: Colors.white, width: 1), ), child: title.toText(13), ); } }