a10a2db27a
- 新增 visual_design_language.md 设计规范文档 - 新增 auth 设计 tokens (authBackground, authCard, authInput, feedback 系列等) - 重构登录/注册/验证码/重置密码页面为新设计系统 - 新增 AuthHeroHeader, AuthSurfaceCard, AuthSection, AuthField, PasswordField 组件 - 重构 AppBanner 和 Toast 支持多类型配置 (info/success/warning/error) - 后端 AgentScope: 重整 schemas/prompts/tools 作用域, 新增协议文档 - 更新 AGENTS.md 集成视觉设计语言约束
182 lines
5.3 KiB
Dart
182 lines
5.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../../core/theme/design_tokens.dart';
|
|
import 'toast_type.dart';
|
|
import 'toast_type_config.dart';
|
|
|
|
class Toast {
|
|
static void show(
|
|
BuildContext context,
|
|
String message, {
|
|
ToastType type = ToastType.info,
|
|
Duration duration = const Duration(seconds: 2),
|
|
}) {
|
|
final overlay = Overlay.of(context);
|
|
late OverlayEntry entry;
|
|
|
|
entry = OverlayEntry(
|
|
builder: (context) => _ToastWidget(
|
|
message: message,
|
|
type: type,
|
|
duration: duration,
|
|
onDismiss: () => entry.remove(),
|
|
),
|
|
);
|
|
|
|
overlay.insert(entry);
|
|
}
|
|
}
|
|
|
|
class _ToastWidget extends StatefulWidget {
|
|
final String message;
|
|
final ToastType type;
|
|
final Duration duration;
|
|
final VoidCallback onDismiss;
|
|
|
|
const _ToastWidget({
|
|
required this.message,
|
|
required this.type,
|
|
required this.duration,
|
|
required this.onDismiss,
|
|
});
|
|
|
|
@override
|
|
State<_ToastWidget> createState() => _ToastWidgetState();
|
|
}
|
|
|
|
class _ToastWidgetState extends State<_ToastWidget>
|
|
with SingleTickerProviderStateMixin {
|
|
late AnimationController _controller;
|
|
late Animation<Offset> _slideAnimation;
|
|
late Animation<double> _fadeAnimation;
|
|
bool _dismissed = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = AnimationController(
|
|
duration: const Duration(milliseconds: 280),
|
|
vsync: this,
|
|
);
|
|
|
|
_slideAnimation = Tween<Offset>(
|
|
begin: const Offset(0, -0.18),
|
|
end: Offset.zero,
|
|
).animate(CurvedAnimation(parent: _controller, curve: Curves.easeOutCubic));
|
|
|
|
_fadeAnimation = Tween<double>(
|
|
begin: 0,
|
|
end: 1,
|
|
).animate(CurvedAnimation(parent: _controller, curve: Curves.easeOut));
|
|
|
|
_controller.forward();
|
|
|
|
Future.delayed(widget.duration, _dismiss);
|
|
}
|
|
|
|
void _dismiss() {
|
|
if (!mounted || _dismissed) return;
|
|
_dismissed = true;
|
|
_controller.reverse().then((_) {
|
|
if (mounted) {
|
|
widget.onDismiss();
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final config = ToastTypeConfig.fromType(widget.type);
|
|
|
|
return Positioned(
|
|
top: MediaQuery.of(context).padding.top + 12,
|
|
left: 16,
|
|
right: 16,
|
|
child: SlideTransition(
|
|
position: _slideAnimation,
|
|
child: FadeTransition(
|
|
opacity: _fadeAnimation,
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: SafeArea(
|
|
bottom: false,
|
|
child: GestureDetector(
|
|
onTap: _dismiss,
|
|
child: Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: config.surfaceColor,
|
|
borderRadius: BorderRadius.circular(AppRadius.lg),
|
|
border: Border.all(color: config.borderColor),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: AppColors.slate900.withValues(alpha: 0.08),
|
|
blurRadius: 24,
|
|
offset: const Offset(0, 10),
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
width: 34,
|
|
height: 34,
|
|
decoration: BoxDecoration(
|
|
color: config.iconColor.withValues(alpha: 0.12),
|
|
borderRadius: BorderRadius.circular(AppRadius.full),
|
|
),
|
|
child: Icon(
|
|
config.icon,
|
|
size: 18,
|
|
color: config.iconColor,
|
|
),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
config.label,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w700,
|
|
color: config.textColor,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
widget.message,
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
height: 1.35,
|
|
color: config.textColor,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Icon(
|
|
Icons.close_rounded,
|
|
size: 18,
|
|
color: config.textColor.withValues(alpha: 0.72),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|