1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
| | import 'dart:async';
| |
| | import 'package:flutter/material.dart';
| |
| | import '../theme/app_theme.dart';
| |
| | /// Slide-in toast for cross-session incoming messages.
| | class ToastOverlay extends StatefulWidget {
| | final String sessionName;
| | final String preview;
| | final VoidCallback onTap;
| | final VoidCallback onDismiss;
| |
| | const ToastOverlay({
| | super.key,
| | required this.sessionName,
| | required this.preview,
| | required this.onTap,
| | required this.onDismiss,
| | });
| |
| | @override
| | State<ToastOverlay> createState() => _ToastOverlayState();
| | }
| |
| | class _ToastOverlayState extends State<ToastOverlay>
| | with SingleTickerProviderStateMixin {
| | late final AnimationController _controller;
| | late final Animation<Offset> _slideAnimation;
| | Timer? _autoDismiss;
| |
| | @override
| | void initState() {
| | super.initState();
| | _controller = AnimationController(
| | vsync: this,
| | duration: const Duration(milliseconds: 300),
| | );
| | _slideAnimation = Tween<Offset>(
| | begin: const Offset(0, -1),
| | end: Offset.zero,
| | ).animate(CurvedAnimation(parent: _controller, curve: Curves.easeOutCubic));
| |
| | _controller.forward();
| | _autoDismiss = Timer(const Duration(seconds: 4), _dismiss);
| | }
| |
| | void _dismiss() {
| | _autoDismiss?.cancel();
| | _controller.reverse().then((_) {
| | widget.onDismiss();
| | });
| | }
| |
| | @override
| | void dispose() {
| | _autoDismiss?.cancel();
| | _controller.dispose();
| | super.dispose();
| | }
| |
| | @override
| | Widget build(BuildContext context) {
| | return SlideTransition(
| | position: _slideAnimation,
| | child: SafeArea(
| | bottom: false,
| | child: GestureDetector(
| | onTap: () {
| | _autoDismiss?.cancel();
| | widget.onTap();
| | },
| | onVerticalDragEnd: (details) {
| | if (details.primaryVelocity != null &&
| | details.primaryVelocity! < -100) {
| | _dismiss();
| | }
| | },
| | child: Container(
| | margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
| | padding: const EdgeInsets.all(12),
| | decoration: BoxDecoration(
| | color: AppColors.darkSurface,
| | borderRadius: BorderRadius.circular(12),
| | boxShadow: [
| | BoxShadow(
| | color: Colors.black.withAlpha(80),
| | blurRadius: 12,
| | offset: const Offset(0, 4),
| | ),
| | ],
| | ),
| | child: Row(
| | children: [
| | Container(
| | width: 36,
| | height: 36,
| | decoration: const BoxDecoration(
| | color: AppColors.accent,
| | shape: BoxShape.circle,
| | ),
| | child: const Icon(
| | Icons.chat_bubble_outline,
| | color: Colors.white,
| | size: 18,
| | ),
| | ),
| | const SizedBox(width: 12),
| | Expanded(
| | child: Column(
| | crossAxisAlignment: CrossAxisAlignment.start,
| | mainAxisSize: MainAxisSize.min,
| | children: [
| | Text(
| | widget.sessionName,
| | style: const TextStyle(
| | color: Colors.white,
| | fontWeight: FontWeight.w600,
| | fontSize: 13,
| | ),
| | ),
| | const SizedBox(height: 2),
| | Text(
| | widget.preview,
| | style: const TextStyle(
| | color: AppColors.darkTextSecondary,
| | fontSize: 12,
| | ),
| | maxLines: 2,
| | overflow: TextOverflow.ellipsis,
| | ),
| | ],
| | ),
| | ),
| | ],
| | ),
| | ),
| | ),
| | ),
| | );
| | }
| | }
| |
| | /// Global toast manager for showing cross-session notifications.
| | class ToastManager {
| | ToastManager._();
| |
| | static OverlayEntry? _currentEntry;
| |
| | static void show(
| | BuildContext context, {
| | required String sessionName,
| | required String preview,
| | required VoidCallback onTap,
| | }) {
| | dismiss();
| |
| | _currentEntry = OverlayEntry(
| | builder: (ctx) => Positioned(
| | top: 0,
| | left: 0,
| | right: 0,
| | child: Material(
| | color: Colors.transparent,
| | child: ToastOverlay(
| | sessionName: sessionName,
| | preview: preview,
| | onTap: () {
| | dismiss();
| | onTap();
| | },
| | onDismiss: dismiss,
| | ),
| | ),
| | ),
| | );
| |
| | Overlay.of(context).insert(_currentEntry!);
| | }
| |
| | static void dismiss() {
| | _currentEntry?.remove();
| | _currentEntry = null;
| | }
| | }
|
|