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,