-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstyle_screen.dart
More file actions
178 lines (162 loc) · 4.89 KB
/
Copy pathstyle_screen.dart
File metadata and controls
178 lines (162 loc) · 4.89 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
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/providers.dart';
import '../models/models.dart';
import '../utils/utils.dart';
import '../widgets/widgets.dart';
/// Screen showing drinks of a specific style
class StyleScreen extends StatefulWidget {
final String festivalId;
final String style;
const StyleScreen({
required this.festivalId,
required this.style,
super.key,
});
@override
State<StyleScreen> createState() => _StyleScreenState();
}
class _StyleScreenState extends State<StyleScreen> {
@override
void initState() {
super.initState();
// Log style viewed event after the first frame
WidgetsBinding.instance.addPostFrameCallback((_) {
final provider = context.read<BeerProvider>();
unawaited(provider.analyticsService.logStyleViewed(widget.style));
});
}
@override
Widget build(BuildContext context) {
final provider = context.watch<BeerProvider>();
// Show loading state while drinks are being fetched
if (provider.isLoading) {
return buildLoadingScaffold();
}
// Get all drinks with this style
final styleDrinks = provider.allDrinks
.where((drink) =>
drink.product.style?.toLowerCase() == widget.style.toLowerCase())
.toList();
if (styleDrinks.isEmpty) {
return Scaffold(
appBar: AppBar(title: const Text('Style Not Found')),
body: const Center(
child: Text('No drinks found with this style.')),
);
}
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(
title: _buildAppBarTitle(context, provider),
leading: buildHomeLeadingButton(context, widget.festivalId),
),
body: CustomScrollView(
slivers: [
// Header section
SliverToBoxAdapter(
child: _buildHeader(context, theme),
),
// Hero info card
SliverToBoxAdapter(
child: _buildHeroCard(context, styleDrinks, theme),
),
// Description (if available)
SliverToBoxAdapter(
child: FutureBuilder<String?>(
future: StyleDescriptionHelper.getStyleDescription(widget.style),
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data != null) {
return _buildDescription(context, snapshot.data!, theme);
}
return const SizedBox.shrink();
},
),
),
// Drinks list
...DrinkListSection.buildSlivers(
context: context,
festivalId: widget.festivalId,
title: 'Drinks',
drinks: styleDrinks,
),
],
),
);
}
/// Build the app bar title with breadcrumb navigation
Widget _buildAppBarTitle(BuildContext context, BeerProvider provider) {
return buildBreadcrumbTitle(
context,
title: widget.style,
festivalName: provider.currentFestival.name,
);
}
/// Build clean white header with style name
Widget _buildHeader(BuildContext context, ThemeData theme) {
return Container(
width: double.infinity,
padding: const EdgeInsets.all(24.0),
color: theme.colorScheme.surface,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SelectableText(
widget.style,
style: theme.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.onSurface,
),
),
],
),
);
}
/// Build hero info card with key style information
Widget _buildHeroCard(
BuildContext context,
List<Drink> styleDrinks,
ThemeData theme,
) {
// Calculate average ABV
final avgABV = styleDrinks.isEmpty
? 0.0
: styleDrinks.map((d) => d.product.abv).reduce((a, b) => a + b) /
styleDrinks.length;
final rows = <HeroInfoRow>[
// Drink count
HeroInfoRow(
icon: Icons.local_bar,
text: '${styleDrinks.length} ${styleDrinks.length == 1 ? "drink" : "drinks"} at this festival',
),
// Average ABV
if (styleDrinks.isNotEmpty)
HeroInfoRow(
icon: Icons.science,
text: 'Average ABV: ${avgABV.toStringAsFixed(1)}%',
),
];
return HeroInfoCard(rows: rows);
}
/// Build description section
Widget _buildDescription(
BuildContext context,
String description,
ThemeData theme,
) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SectionHeader(title: 'About This Style'),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: SelectableText(
description,
style: theme.textTheme.bodyLarge,
),
),
],
);
}
}