-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwidget_builders.dart
More file actions
102 lines (96 loc) · 2.72 KB
/
Copy pathwidget_builders.dart
File metadata and controls
102 lines (96 loc) · 2.72 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
/// Common widget builders for reducing duplication across screens.
///
/// This file contains reusable widget builders that are used across multiple
/// screens to maintain consistency and reduce code duplication.
library;
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'navigation_helpers.dart';
/// Builds a loading scaffold with standard appearance.
///
/// Used when data is being fetched to show a consistent loading state
/// across all screens.
///
/// Example:
/// ```dart
/// if (provider.isLoading) {
/// return buildLoadingScaffold();
/// }
/// ```
Widget buildLoadingScaffold() {
return Scaffold(
appBar: AppBar(title: const Text('Loading...')),
body: const Center(child: CircularProgressIndicator()),
);
}
/// Builds a home button for the AppBar leading position.
///
/// Shows a home button instead of the back button when navigation cannot pop.
/// This ensures users can always navigate back to the festival home.
///
/// The [festivalId] is used to navigate to the correct festival home page.
///
/// Example:
/// ```dart
/// AppBar(
/// leading: buildHomeLeadingButton(context, festivalId),
/// )
/// ```
Widget? buildHomeLeadingButton(BuildContext context, String festivalId) {
if (canPopNavigation(context)) {
return null; // Use default back button
}
return Semantics(
label: 'Go to home screen',
hint: 'Double tap to return to drinks list',
button: true,
child: IconButton(
icon: const Icon(Icons.home),
onPressed: () => context.go(buildFestivalHome(festivalId)),
tooltip: 'Home',
),
);
}
/// Builds a breadcrumb-style title for the AppBar.
///
/// Shows a primary title with the festival name as a subtitle for context.
/// This provides consistent navigation breadcrumbs across detail screens.
///
/// The [title] is the main heading (e.g., brewery name, style name, drink name).
/// The [festivalName] appears as a smaller subtitle below the title.
///
/// Example:
/// ```dart
/// AppBar(
/// title: buildBreadcrumbTitle(
/// context,
/// title: 'IPA',
/// festivalName: 'Cambridge Beer Festival 2025',
/// ),
/// )
/// ```
Widget buildBreadcrumbTitle(
BuildContext context, {
required String title,
required String festivalName,
}) {
final theme = Theme.of(context);
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: theme.textTheme.titleLarge,
overflow: TextOverflow.ellipsis,
),
Text(
festivalName,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
overflow: TextOverflow.ellipsis,
),
],
);
}