AI 接入 V1.0
UI更新
This commit is contained in:
+18
-4
@@ -1,13 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../core/navigation/navigator_key.dart';
|
||||
import '../widgets/cute_icon.dart';
|
||||
|
||||
/// 统一提示封装(对齐 uni.showToast 的常用场景)
|
||||
void showToast(BuildContext context, String message, {bool error = false}) {
|
||||
///
|
||||
/// [icon] 传图标名(见 [cuteIconNames]),会在文字前面显示一个小图标 ——
|
||||
/// 比在文案里塞 emoji 干净,而且能跟着主题色走。
|
||||
void showToast(BuildContext context, String message,
|
||||
{bool error = false, String? icon}) {
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
content: Row(
|
||||
children: [
|
||||
if (icon != null) ...[
|
||||
// 深色底上用单色,双色在小尺寸下会糊成一团
|
||||
CuteIcon(icon, size: 18, tint: Colors.white),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
Expanded(child: Text(message)),
|
||||
],
|
||||
),
|
||||
backgroundColor: error ? const Color(0xFFB71C1C) : const Color(0xFF323232),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
duration: const Duration(seconds: 2),
|
||||
@@ -16,7 +30,7 @@ void showToast(BuildContext context, String message, {bool error = false}) {
|
||||
}
|
||||
|
||||
/// 全局提示:供没有 BuildContext 的地方调用(网络层、Provider)
|
||||
void showGlobalToast(String message, {bool error = false}) {
|
||||
void showGlobalToast(String message, {bool error = false, String? icon}) {
|
||||
final context = navigatorKey.currentContext;
|
||||
if (context != null) showToast(context, message, error: error);
|
||||
if (context != null) showToast(context, message, error: error, icon: icon);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user