Browse Source

[new]增加账号退出功能

zk 9 months ago
parent
commit
67376c69a6

+ 5 - 0
assets/string/base/string.xml

@@ -93,4 +93,9 @@
     <string name="location_mine">我</string>
     <string name="location_trace">轨迹</string>
 
+    <string name="dialog_cancel">取消</string>
+    <string name="dialog_sure">确定</string>
+    <string name="dialog_exit_account_title">提示</string>
+    <string name="dialog_exit_account_desc">确定退出登录吗?</string>
+
 </resources>

+ 2 - 0
lib/data/repositories/account_repository.dart

@@ -117,6 +117,8 @@ class AccountRepository {
     KVUtil.putString(keyAccountLoginUserId, null);
     loginPhoneNum.value = null;
     memberStatusInfo.value = null;
+
+    friendsRepository.clearFriends();
   }
 
   void refreshMemberStatus() {

+ 3 - 3
lib/dialog/agreement_dialog.dart

@@ -11,12 +11,12 @@ import 'package:location/utils/common_expand.dart';
 import '../data/consts/web_url.dart';
 
 class AgreementDialog {
-  static final tag = "AgreementDialog";
+  static final _tag = "AgreementDialog";
 
   static void show(
       {required VoidCallback cancelClick, required VoidCallback sureClick}) {
     SmartDialog.show(
-      tag: tag,
+      tag: _tag,
       backDismiss: false,
       builder: (_) {
         return _AgreementDialog(cancelClick, sureClick);
@@ -26,7 +26,7 @@ class AgreementDialog {
   }
 
   static void dismiss() {
-    SmartDialog.dismiss(tag: tag);
+    SmartDialog.dismiss(tag: _tag);
   }
 }
 

+ 120 - 0
lib/dialog/common_alert_dialog.dart

@@ -0,0 +1,120 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_screenutil/flutter_screenutil.dart';
+import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
+import 'package:location/resource/colors.gen.dart';
+import 'package:location/utils/common_expand.dart';
+
+class CommonAlertDialog {
+  static const String _tag = "CommonAlertDialog";
+
+  static void show(
+      {required Widget titleWidget,
+      required Widget descWidget,
+      required String cancelText,
+      required String confirmText,
+      required VoidCallback cancelOnTap,
+      required VoidCallback confirmOnTap,
+      String tag = _tag}) {
+    SmartDialog.show(
+        tag: _tag,
+        builder: (_) {
+          return _CommonAlertDialog(
+              titleWidget: titleWidget,
+              descWidget: descWidget,
+              cancelText: cancelText,
+              confirmText: confirmText,
+              cancelOnTap: cancelOnTap,
+              confirmOnTap: confirmOnTap);
+        });
+  }
+
+  static void dismiss() {
+    SmartDialog.dismiss(tag: _tag);
+  }
+}
+
+class _CommonAlertDialog extends Dialog {
+  final Widget titleWidget;
+  final Widget descWidget;
+  final String cancelText;
+  final String confirmText;
+  final VoidCallback cancelOnTap;
+  final VoidCallback confirmOnTap;
+
+  const _CommonAlertDialog({
+    required this.titleWidget,
+    required this.descWidget,
+    required this.cancelText,
+    required this.confirmText,
+    required this.cancelOnTap,
+    required this.confirmOnTap,
+  });
+
+  @override
+  Widget build(BuildContext context) {
+    return IntrinsicHeight(
+      child: Container(
+        width: 300.w,
+        decoration: BoxDecoration(
+          color: Colors.white,
+          borderRadius: BorderRadius.circular(20.w),
+        ),
+        child: Column(
+          children: [
+            SizedBox(height: 27.w),
+            titleWidget,
+            SizedBox(height: 15.w),
+            Container(
+              margin: EdgeInsets.symmetric(horizontal: 28.w),
+              child: descWidget,
+            ),
+            SizedBox(height: 32.w),
+            Row(
+              mainAxisAlignment: MainAxisAlignment.center,
+              children: [
+                GestureDetector(
+                  onTap: () => cancelOnTap(),
+                  child: Container(
+                    width: 109.w,
+                    height: 43.w,
+                    decoration: BoxDecoration(
+                      borderRadius: BorderRadius.all(Radius.circular(57.w)),
+                      border: Border.all(color: ColorName.black15, width: 1.w),
+                    ),
+                    child: Center(
+                      child: Text(cancelText,
+                          style: TextStyle(
+                              fontSize: 14.sp,
+                              color: '#333333'.color,
+                              fontWeight: FontWeight.bold)),
+                    ),
+                  ),
+                ),
+                SizedBox(width: 30.w),
+                GestureDetector(
+                  onTap: () => confirmOnTap(),
+                  child: Container(
+                    width: 109.w,
+                    height: 43.w,
+                    decoration: BoxDecoration(
+                      color: ColorName.colorPrimary,
+                      borderRadius: BorderRadius.all(Radius.circular(57.w)),
+                    ),
+                    child: Center(
+                      child: Text(confirmText,
+                          style: TextStyle(
+                              fontSize: 14.sp,
+                              color: Colors.white,
+                              fontWeight: FontWeight.bold)),
+                    ),
+                  ),
+                ),
+              ],
+            ),
+            SizedBox(height: 20.w),
+          ],
+        ),
+      ),
+    );
+  }
+}

+ 30 - 0
lib/dialog/common_alert_dialog_impl.dart

@@ -0,0 +1,30 @@
+import 'package:flutter/cupertino.dart';
+import 'package:flutter_screenutil/flutter_screenutil.dart';
+import 'package:location/resource/colors.gen.dart';
+import 'package:location/resource/string.gen.dart';
+import 'package:location/utils/common_expand.dart';
+import 'common_alert_dialog.dart';
+
+void exitAccountDialog({required VoidCallback confirmOnTap}) {
+  CommonAlertDialog.show(
+      titleWidget: Text(
+        StringName.dialogExitAccountTitle,
+        style: TextStyle(
+            fontSize: 18.sp,
+            color: ColorName.black90,
+            fontWeight: FontWeight.bold),
+      ),
+      descWidget: Text(
+        StringName.dialogExitAccountDesc,
+        style: TextStyle(fontSize: 15.sp, color: '#404040'.color),
+      ),
+      cancelText: StringName.dialogCancel,
+      confirmText: StringName.dialogSure,
+      cancelOnTap: () {
+        CommonAlertDialog.dismiss();
+      },
+      confirmOnTap: () {
+        confirmOnTap();
+        CommonAlertDialog.dismiss();
+      });
+}

+ 6 - 3
lib/module/mine/mine_controller.dart

@@ -5,9 +5,8 @@ import 'package:location/base/base_controller.dart';
 import 'package:location/data/bean/member_status_info.dart';
 import 'package:location/module/login/login_page.dart';
 import 'package:location/resource/string.gen.dart';
-import 'package:location/utils/toast_util.dart';
-
 import '../../data/repositories/account_repository.dart';
+import '../../dialog/common_alert_dialog_impl.dart';
 
 @injectable
 class MineController extends BaseController {
@@ -45,7 +44,11 @@ class MineController extends BaseController {
 
   onLogoutAccountClick() {}
 
-  onFunExitAccountClick() {}
+  onFunExitAccountClick() {
+    exitAccountDialog(confirmOnTap: () {
+      accountRepository.logout();
+    });
+  }
 
   onLoginClick() {
     if (isLogin) {

+ 15 - 11
lib/module/mine/mine_page.dart

@@ -70,17 +70,21 @@ class MinePage extends BasePage<MineController> {
 
   Widget buildMineFunItem(
       ImageProvider icon, String funName, VoidCallback onTap) {
-    return Container(
-      padding: EdgeInsets.symmetric(vertical: 15.w, horizontal: 12.w),
-      child: Row(
-        children: [
-          Image(image: icon, width: 24.w, height: 24.w),
-          SizedBox(width: 6.w),
-          Text(funName,
-              style: TextStyle(fontSize: 15.sp, color: '#202020'.color)),
-          Spacer(),
-          Assets.images.iconMineFunArrow.image(width: 20.w, height: 20.w)
-        ],
+    return GestureDetector(
+      behavior: HitTestBehavior.translucent,
+      onTap: onTap,
+      child: Container(
+        padding: EdgeInsets.symmetric(vertical: 15.w, horizontal: 12.w),
+        child: Row(
+          children: [
+            Image(image: icon, width: 24.w, height: 24.w),
+            SizedBox(width: 6.w),
+            Text(funName,
+                style: TextStyle(fontSize: 15.sp, color: '#202020'.color)),
+            Spacer(),
+            Assets.images.iconMineFunArrow.image(width: 20.w, height: 20.w)
+          ],
+        ),
       ),
     );
   }

+ 10 - 0
lib/resource/string.gen.dart

@@ -100,6 +100,12 @@ class StringName {
   static final String privacyAgree = 'privacy_agree'.tr; // 同意
   static final String locationMine = 'location_mine'.tr; // 我
   static final String locationTrace = 'location_trace'.tr; // 轨迹
+  static final String dialogCancel = 'dialog_cancel'.tr; // 取消
+  static final String dialogSure = 'dialog_sure'.tr; // 确定
+  static final String dialogExitAccountTitle =
+      'dialog_exit_account_title'.tr; // 提示
+  static final String dialogExitAccountDesc =
+      'dialog_exit_account_desc'.tr; // 确定退出登录吗?
 }
 class StringMultiSource {
   StringMultiSource._();
@@ -180,6 +186,10 @@ class StringMultiSource {
       'privacy_agree': '同意',
       'location_mine': '我',
       'location_trace': '轨迹',
+      'dialog_cancel': '取消',
+      'dialog_sure': '确定',
+      'dialog_exit_account_title': '提示',
+      'dialog_exit_account_desc': '确定退出登录吗?',
     },
   };
 }