From 6a84d9fdd55f300de9873f7403c42923db57b4a7 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 2 Apr 2021 14:53:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E6=9C=BA=E5=8F=B7=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E6=B7=BB=E5=8A=A0=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account_and_safety_page.dart | 28 +++++++++---------- lib/widgets/progress/re_toast.dart | 12 ++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/pages/user/account_and_safety/account_and_safety_page.dart b/lib/pages/user/account_and_safety/account_and_safety_page.dart index a8b76be..1b74f40 100644 --- a/lib/pages/user/account_and_safety/account_and_safety_page.dart +++ b/lib/pages/user/account_and_safety/account_and_safety_page.dart @@ -57,14 +57,7 @@ class _AccountAndSafetyPageState extends State { padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 6.w), materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, onPressed: () async { - final cancel = ReToast.loading(text: '修改中'); - secureValue = !secureValue; - await HttpManager.post( - APIV2.userAPI.securePhone, - {'secure': secureValue ? 1 : 0}, - ); - cancel(); - setState(() {}); + await _updateSwitchState(); }, child: Row( children: [ @@ -83,12 +76,7 @@ class _AccountAndSafetyPageState extends State { value: secureValue, trackColor: Color(0xFFDB2D2D), onChanged: (state) async { - final cancel = ReToast.loading(text: '修改中'); - secureValue = !secureValue; - await HttpManager.post(APIV2.userAPI.securePhone, - {'secure': secureValue ? 1 : 0}); - cancel(); - setState(() {}); + await _updateSwitchState(); }, ), ], @@ -99,6 +87,18 @@ class _AccountAndSafetyPageState extends State { ); } + _updateSwitchState() async { + final cancel = ReToast.loading(text: '修改中'); + secureValue = !secureValue; + await HttpManager.post( + APIV2.userAPI.securePhone, + {'secure': secureValue ? 1 : 0}, + ); + cancel(); + ReToast.success(text: '修改成功'); + setState(() {}); + } + _backButton(context) { if (Navigator.canPop(context)) { return IconButton( diff --git a/lib/widgets/progress/re_toast.dart b/lib/widgets/progress/re_toast.dart index 51668b1..49278e1 100644 --- a/lib/widgets/progress/re_toast.dart +++ b/lib/widgets/progress/re_toast.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:bot_toast/bot_toast.dart'; +import 'package:recook/widgets/alert.dart'; import 'package:recook/widgets/progress/loading_dialog.dart'; @@ -24,6 +25,17 @@ class ReToast { ); } + static Function success({String text}) { + return BotToast.showCustomText( + toastBuilder: (func) { + return StatusDialog( + status: Status.success, + text: text ?? '', + ); + }, + ); + } + static Function raw(Widget child) => BotToast.showCustomLoading( toastBuilder: (func) => child, enableKeyboardSafeArea: false,