From e7efba68430aeed2b7b79e1e705ef6fac9d8ed8a Mon Sep 17 00:00:00 2001 From: dom Date: Mon, 8 Jun 2026 11:40:03 +0800 Subject: [PATCH] fix #2351 Signed-off-by: dom --- lib/common/widgets/custom_toast.dart | 43 ++++++++++++++++++++++++---- lib/main.dart | 3 ++ lib/utils/login_utils.dart | 15 ++++++---- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/lib/common/widgets/custom_toast.dart b/lib/common/widgets/custom_toast.dart index 91e83f005..59ac774f8 100644 --- a/lib/common/widgets/custom_toast.dart +++ b/lib/common/widgets/custom_toast.dart @@ -9,13 +9,13 @@ class CustomToast extends StatelessWidget { Widget build(BuildContext context) { final colorScheme = ColorScheme.of(context); return Container( - margin: EdgeInsets.only( + margin: .only( bottom: MediaQuery.viewPaddingOf(context).bottom + 30, ), - padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 10), + padding: const .symmetric(horizontal: 17, vertical: 10), decoration: BoxDecoration( color: colorScheme.primaryContainer, - borderRadius: const BorderRadius.all(Radius.circular(20)), + borderRadius: const .all(.circular(20)), ), child: Text( msg, @@ -39,14 +39,14 @@ class LoadingWidget extends StatelessWidget { final theme = Theme.of(context); final onSurfaceVariant = theme.colorScheme.onSurfaceVariant; return Container( - padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 20), + padding: const .symmetric(horizontal: 30, vertical: 20), decoration: BoxDecoration( color: theme.dialogTheme.backgroundColor, - borderRadius: const BorderRadius.all(Radius.circular(15)), + borderRadius: const .all(.circular(15)), ), child: Column( spacing: 20, - mainAxisSize: MainAxisSize.min, + mainAxisSize: .min, children: [ //loading animation CircularProgressIndicator( @@ -60,3 +60,34 @@ class LoadingWidget extends StatelessWidget { ); } } + +class NotifyWarning extends StatelessWidget { + const NotifyWarning(this.msg, {super.key}); + + final String msg; + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + final onSurfaceVariant = theme.colorScheme.onSurfaceVariant; + return Container( + decoration: BoxDecoration( + borderRadius: const .all(.circular(8)), + color: theme.dialogTheme.backgroundColor, + ), + padding: const .symmetric(horizontal: 20, vertical: 10), + child: Column( + spacing: 5, + mainAxisSize: .min, + children: [ + Icon( + Icons.warning_amber_rounded, + size: 22, + color: onSurfaceVariant, + ), + Text(msg, style: TextStyle(color: onSurfaceVariant)), + ], + ), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index 9d5ab5b63..d2ad010c0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -260,6 +260,9 @@ class MyApp extends StatelessWidget { builder: FlutterSmartDialog.init( toastBuilder: CustomToast.new, loadingBuilder: LoadingWidget.new, + notifyStyle: const FlutterSmartNotifyStyle( + warningBuilder: NotifyWarning.new, + ), builder: _builder, ), navigatorObservers: [routeObserver], diff --git a/lib/utils/login_utils.dart b/lib/utils/login_utils.dart index 1ccf8c581..66ddc760c 100644 --- a/lib/utils/login_utils.dart +++ b/lib/utils/login_utils.dart @@ -67,11 +67,16 @@ abstract final class LoginUtils { } } else { // 获取用户信息失败 - await Accounts.deleteAll({account}); - SmartDialog.showNotify( - msg: '登录失败,请检查cookie是否正确,${res.toString()}', - notifyType: NotifyType.warning, - ); + final errMsg = res.toString(); + if (errMsg == '账号未登录') { + await Accounts.deleteAll({account}); + SmartDialog.showNotify( + msg: '登录失败,请检查cookie是否正确,$errMsg', + notifyType: .warning, + ); + } else { + SmartDialog.showToast(errMsg); + } } }