-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfestival_menu_sheets.dart
More file actions
556 lines (532 loc) · 20.5 KB
/
Copy pathfestival_menu_sheets.dart
File metadata and controls
556 lines (532 loc) · 20.5 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import '../models/models.dart';
import '../providers/providers.dart';
import '../utils/utils.dart';
import 'festival_header.dart';
import 'sheet_handle.dart';
/// Shows the festival browser/selector as a modal bottom sheet
void showFestivalBrowser(BuildContext context) {
final provider = context.read<BeerProvider>();
// Capture current route before opening modal — GoRouterState must not be
// accessed inside an onTap handler (gesture callbacks are not build phase).
String? currentPath;
try {
currentPath = GoRouterState.of(context).uri.path;
} catch (_) {
// GoRouterState unavailable (e.g., in tests)
}
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) =>
FestivalSelectorSheet(provider: provider, currentPath: currentPath),
);
}
/// Shows the settings modal with theme selector
void showSettingsSheet(BuildContext context) {
final provider = context.read<BeerProvider>();
showModalBottomSheet(
context: context,
builder: (context) => SettingsSheet(provider: provider),
);
}
/// Festival selector sheet for browsing all festivals
class FestivalSelectorSheet extends StatelessWidget {
final BeerProvider provider;
final String? currentPath;
const FestivalSelectorSheet({
required this.provider,
this.currentPath,
super.key,
});
String _getStatusLabel(FestivalStatus status) {
switch (status) {
case FestivalStatus.live:
return 'currently live';
case FestivalStatus.upcoming:
return 'coming soon';
case FestivalStatus.mostRecent:
return 'most recent';
case FestivalStatus.past:
return 'past event';
}
}
@override
Widget build(BuildContext context) {
// Unlike every other sheet in this file, two of this one's controls —
// Retry and Refresh — deliberately do NOT pop the sheet, so their result
// has to land while it is still open. A captured provider reference does
// not subscribe to anything, and a modal route is not rebuilt by its
// opener, so without this the buttons were dead: loadFestivals() ran and
// nothing on screen changed.
//
// ListenableBuilder rather than Consumer: the provider is injected through
// the constructor, so listening to that instance directly keeps the widget
// usable without an ancestor Provider.
return ListenableBuilder(
listenable: provider,
builder: (context, _) => _buildSheet(context),
);
}
Widget _buildSheet(BuildContext context) {
final theme = Theme.of(context);
// Use dynamically loaded festivals (sorted)
final festivals = provider.sortedFestivals;
return Container(
padding: const EdgeInsets.all(16),
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * 0.7,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SheetHandle(handleKey: Key('festival_selector_drag_handle')),
const SizedBox(height: 16),
Row(
children: [
const Icon(Icons.festival, size: 28),
const SizedBox(width: 12),
Text('Browse Festivals', style: theme.textTheme.titleLarge),
],
),
const SizedBox(height: 8),
Text(
'Choose a festival to browse its drinks',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 16),
Flexible(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (provider.isFestivalsLoading)
const Center(
child: Padding(
padding: EdgeInsets.all(16.0),
child: CircularProgressIndicator(),
),
)
else if (provider.festivalsError != null)
Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Icon(
Icons.error_outline,
size: 48,
color: theme.colorScheme.error,
),
const SizedBox(height: 12),
Text(
'Failed to load festivals',
style: theme.textTheme.titleMedium,
),
const SizedBox(height: 8),
Text(
provider.festivalsError!,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
Semantics(
label: 'Retry loading festivals',
hint: 'Double tap to reload festival list',
button: true,
child: FilledButton.icon(
onPressed: provider.loadFestivals,
icon: const Icon(Icons.refresh),
label: const Text('Retry'),
),
),
],
),
),
)
else if (festivals.isEmpty)
Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Icon(
Icons.festival_outlined,
size: 48,
color: theme.colorScheme.onSurfaceVariant,
),
const SizedBox(height: 12),
Text(
'No festivals available',
style: theme.textTheme.titleMedium,
),
const SizedBox(height: 16),
Semantics(
label: 'Refresh festivals',
hint: 'Double tap to reload festival list',
button: true,
child: FilledButton.icon(
onPressed: provider.loadFestivals,
icon: const Icon(Icons.refresh),
label: const Text('Refresh'),
),
),
],
),
),
)
else
...festivals.map((festival) {
final status = Festival.getStatusInContext(
festival,
festivals,
);
final statusLabel = _getStatusLabel(status);
final isSelected =
festival.id == provider.currentFestival.id;
final festivalLabel = isSelected
? '${festival.name}, currently selected, $statusLabel'
: '${festival.name}, $statusLabel';
return Semantics(
label: festivalLabel,
selected: isSelected,
button: true,
hint: 'Double tap to select this festival',
child: FestivalCard(
festival: festival,
sortedFestivals: festivals,
isSelected: isSelected,
onTap: () {
// Preserve user's tab: if on favorites, stay on favorites.
// currentPath was captured before the modal opened to avoid
// calling GoRouterState.of() inside a gesture callback,
// which can cause a freeze during active widget rebuilds.
String targetPath = buildFestivalHome(festival.id);
if (currentPath?.endsWith('/favorites') == true) {
targetPath = buildFavoritesPath(festival.id);
}
final router = GoRouter.maybeOf(context);
provider.setFestival(festival);
Navigator.pop(context);
router?.go(targetPath);
},
onInfoTap: () {
final router = GoRouter.maybeOf(context);
Navigator.pop(context);
router?.push(buildFestivalInfoPath(festival.id));
},
),
);
}),
],
),
),
),
const SizedBox(height: 16),
],
),
);
}
}
/// Enhanced festival card with more information
class FestivalCard extends StatelessWidget {
final Festival festival;
final List<Festival> sortedFestivals;
final bool isSelected;
final VoidCallback onTap;
final VoidCallback onInfoTap;
const FestivalCard({
required this.festival,
required this.sortedFestivals,
required this.isSelected,
required this.onTap,
required this.onInfoTap,
super.key,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final status = Festival.getStatusInContext(festival, sortedFestivals);
return Card(
margin: const EdgeInsets.only(bottom: 12),
elevation: isSelected ? 4 : 1,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: isSelected
? BorderSide(color: theme.colorScheme.primary, width: 2)
: BorderSide.none,
),
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
FestivalStatusBadge(status: status),
const SizedBox(width: 8),
Expanded(
child: Text(
festival.name,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
],
),
if (festival.formattedDates.isNotEmpty) ...[
const SizedBox(height: 4),
Row(
children: [
Icon(
Icons.calendar_today,
size: 14,
color: theme.colorScheme.onSurfaceVariant,
),
const SizedBox(width: 4),
Text(
festival.formattedDates,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
],
),
],
if (festival.location != null) ...[
const SizedBox(height: 4),
Row(
children: [
Icon(
Icons.location_on,
size: 14,
color: theme.colorScheme.onSurfaceVariant,
),
const SizedBox(width: 4),
Expanded(
child: Text(
festival.location!,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
overflow: TextOverflow.ellipsis,
),
),
],
),
],
],
),
),
Column(
children: [
if (isSelected)
ExcludeSemantics(
child: Icon(
Icons.check_circle,
color: theme.colorScheme.primary,
size: 24,
),
)
else
ExcludeSemantics(
child: Icon(
Icons.radio_button_unchecked,
color: theme.colorScheme.onSurfaceVariant,
size: 24,
),
),
const SizedBox(height: 8),
Semantics(
label: 'Festival information',
hint: 'Double tap to view festival details',
button: true,
child: IconButton(
icon: const Icon(Icons.info_outline),
onPressed: onInfoTap,
visualDensity: VisualDensity.compact,
tooltip: 'Festival info',
),
),
],
),
],
),
if (festival.availableBeverageTypes.isNotEmpty) ...[
const SizedBox(height: 12),
Wrap(
key: const Key('beverage_chips_wrap'),
spacing: 6,
runSpacing: 4,
children: festival.availableBeverageTypes
.take(5) // Show max 5 types
.map(
(type) => Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 2,
),
decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(12),
),
child: Text(
BeverageTypeHelper.formatBeverageType(type),
style: theme.textTheme.labelSmall,
),
),
)
.toList(),
),
],
],
),
),
),
);
}
}
/// Settings bottom sheet with theme selector
class SettingsSheet extends StatelessWidget {
final BeerProvider provider;
const SettingsSheet({required this.provider, super.key});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final themeMode = provider.themeMode;
String themeLabel;
IconData themeIcon;
switch (themeMode) {
case ThemeMode.light:
themeLabel = 'Light';
themeIcon = Icons.light_mode;
case ThemeMode.dark:
themeLabel = 'Dark';
themeIcon = Icons.dark_mode;
case ThemeMode.system:
themeLabel = 'System';
themeIcon = Icons.brightness_auto;
}
return Container(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SheetHandle(handleKey: Key('settings_sheet_drag_handle')),
const SizedBox(height: 16),
Text('Settings', style: theme.textTheme.titleLarge),
const SizedBox(height: 16),
Semantics(
label: 'Change theme, currently $themeLabel mode',
hint: 'Double tap to change theme',
button: true,
child: Card(
child: ListTile(
leading: Icon(themeIcon),
title: const Text('Theme'),
subtitle: Text('$themeLabel mode'),
trailing: const Icon(Icons.chevron_right),
onTap: () {
Navigator.pop(context);
_showThemeSelector(context, provider);
},
),
),
),
const SizedBox(height: 16),
],
),
);
}
void _showThemeSelector(BuildContext context, BeerProvider provider) {
showModalBottomSheet(
context: context,
builder: (context) => ThemeSelectorSheet(provider: provider),
);
}
}
/// Theme selector bottom sheet
class ThemeSelectorSheet extends StatelessWidget {
final BeerProvider provider;
const ThemeSelectorSheet({required this.provider, super.key});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Container(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SheetHandle(handleKey: Key('theme_selector_sheet_drag_handle')),
const SizedBox(height: 16),
Text('Theme', style: theme.textTheme.titleLarge),
const SizedBox(height: 16),
RadioGroup<ThemeMode>(
groupValue: provider.themeMode,
onChanged: (value) {
if (value != null) {
provider.setThemeMode(value);
Navigator.pop(context);
}
},
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Radio<ThemeMode>(value: ThemeMode.system),
title: const Text('System'),
subtitle: const Text('Follow device settings'),
trailing: const Icon(Icons.brightness_auto),
onTap: () {
provider.setThemeMode(ThemeMode.system);
Navigator.pop(context);
},
),
ListTile(
leading: const Radio<ThemeMode>(value: ThemeMode.light),
title: const Text('Light'),
subtitle: const Text('Always use light theme'),
trailing: const Icon(Icons.light_mode),
onTap: () {
provider.setThemeMode(ThemeMode.light);
Navigator.pop(context);
},
),
ListTile(
leading: const Radio<ThemeMode>(value: ThemeMode.dark),
title: const Text('Dark'),
subtitle: const Text('Always use dark theme'),
trailing: const Icon(Icons.dark_mode),
onTap: () {
provider.setThemeMode(ThemeMode.dark);
Navigator.pop(context);
},
),
],
),
),
const SizedBox(height: 16),
],
),
);
}
}