Skip to content

Commit 07fd5d3

Browse files
Merge pull request #140 from richardthe3rd/copilot/fix-warnings-from-analyze
Fix flutter analyze warnings: deprecated withOpacity and const declarations
2 parents b5a6f0c + e7857cd commit 07fd5d3

9 files changed

Lines changed: 54 additions & 53 deletions

lib/constants.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
///
33
/// This file contains shared constants used across multiple screens
44
/// to maintain a single source of truth and avoid duplication.
5+
library;
56

67
/// GitHub repository URL for the Cambridge Beer Festival app
78
///

lib/screens/brewery_screen.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ class _BreweryScreenState extends State<BreweryScreen> {
124124
colors: brightness == Brightness.dark
125125
? [
126126
theme.colorScheme.primaryContainer,
127-
theme.colorScheme.primaryContainer.withOpacity(0.7),
127+
theme.colorScheme.primaryContainer.withValues(alpha: 0.7),
128128
]
129129
: [
130130
theme.colorScheme.primaryContainer,
131-
theme.colorScheme.secondaryContainer.withOpacity(0.5),
131+
theme.colorScheme.secondaryContainer.withValues(alpha: 0.5),
132132
],
133133
),
134134
),
@@ -160,7 +160,7 @@ class _BreweryScreenState extends State<BreweryScreen> {
160160
height: 60,
161161
decoration: BoxDecoration(
162162
shape: BoxShape.circle,
163-
color: theme.colorScheme.secondary.withOpacity(0.1),
163+
color: theme.colorScheme.secondary.withValues(alpha: 0.1),
164164
),
165165
),
166166
),
@@ -172,7 +172,7 @@ class _BreweryScreenState extends State<BreweryScreen> {
172172
height: 40,
173173
decoration: BoxDecoration(
174174
shape: BoxShape.circle,
175-
color: theme.colorScheme.tertiary.withOpacity(0.08),
175+
color: theme.colorScheme.tertiary.withValues(alpha: 0.08),
176176
),
177177
),
178178
),
@@ -200,7 +200,7 @@ class _BreweryScreenState extends State<BreweryScreen> {
200200
borderRadius: BorderRadius.circular(16),
201201
boxShadow: [
202202
BoxShadow(
203-
color: theme.colorScheme.primary.withOpacity(0.3),
203+
color: theme.colorScheme.primary.withValues(alpha: 0.3),
204204
blurRadius: 8,
205205
offset: const Offset(0, 2),
206206
),
@@ -271,10 +271,10 @@ class _BreweryScreenState extends State<BreweryScreen> {
271271
Container(
272272
padding: const EdgeInsets.all(16),
273273
decoration: BoxDecoration(
274-
color: theme.colorScheme.surface.withOpacity(0.5),
274+
color: theme.colorScheme.surface.withValues(alpha: 0.5),
275275
borderRadius: BorderRadius.circular(12),
276276
border: Border.all(
277-
color: theme.colorScheme.outline.withOpacity(0.2),
277+
color: theme.colorScheme.outline.withValues(alpha: 0.2),
278278
),
279279
),
280280
child: Row(

lib/screens/drink_detail_screen.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ class _DrinkDetailScreenState extends State<DrinkDetailScreen> {
133133
colors: brightness == Brightness.dark
134134
? [
135135
theme.colorScheme.primaryContainer,
136-
theme.colorScheme.primaryContainer.withOpacity(0.8),
136+
theme.colorScheme.primaryContainer.withValues(alpha: 0.8),
137137
]
138138
: [
139139
theme.colorScheme.primaryContainer,
140-
theme.colorScheme.secondaryContainer.withOpacity(0.3),
140+
theme.colorScheme.secondaryContainer.withValues(alpha: 0.3),
141141
],
142142
),
143143
border: Border(
@@ -179,7 +179,7 @@ class _DrinkDetailScreenState extends State<DrinkDetailScreen> {
179179
height: 6 + (index % 3) * 4,
180180
decoration: BoxDecoration(
181181
shape: BoxShape.circle,
182-
color: categoryColor.withOpacity(0.15 - (index * 0.015)),
182+
color: categoryColor.withValues(alpha: 0.15 - (index * 0.015)),
183183
),
184184
),
185185
),
@@ -436,32 +436,32 @@ class _DrinkDetailScreenState extends State<DrinkDetailScreen> {
436436
if (category.contains('beer')) {
437437
// Amber-like color
438438
return brightness == Brightness.dark
439-
? colorScheme.secondary.withOpacity(0.8)
439+
? colorScheme.secondary.withValues(alpha: 0.8)
440440
: colorScheme.secondary;
441441
} else if (category.contains('cider')) {
442442
// Green-ish color
443443
return brightness == Brightness.dark
444-
? const Color(0xFF8BC34A).withOpacity(0.8)
444+
? const Color(0xFF8BC34A).withValues(alpha: 0.8)
445445
: const Color(0xFF689F38);
446446
} else if (category.contains('perry')) {
447447
// Lime-ish color
448448
return brightness == Brightness.dark
449-
? const Color(0xFFCDDC39).withOpacity(0.8)
449+
? const Color(0xFFCDDC39).withValues(alpha: 0.8)
450450
: const Color(0xFFAFB42B);
451451
} else if (category.contains('mead')) {
452452
// Yellow-ish color
453453
return brightness == Brightness.dark
454-
? const Color(0xFFFFEB3B).withOpacity(0.8)
454+
? const Color(0xFFFFEB3B).withValues(alpha: 0.8)
455455
: const Color(0xFFF9A825);
456456
} else if (category.contains('wine')) {
457457
// Deep purple/red color
458458
return brightness == Brightness.dark
459-
? const Color(0xFF9C27B0).withOpacity(0.8)
459+
? const Color(0xFF9C27B0).withValues(alpha: 0.8)
460460
: const Color(0xFF7B1FA2);
461461
} else if (category.contains('low') || category.contains('no')) {
462462
// Blue-ish color
463463
return brightness == Brightness.dark
464-
? colorScheme.primary.withOpacity(0.8)
464+
? colorScheme.primary.withValues(alpha: 0.8)
465465
: colorScheme.primary;
466466
}
467467
// Default fallback
@@ -478,17 +478,17 @@ class _DrinkDetailScreenState extends State<DrinkDetailScreen> {
478478
if (abv < 4.0) {
479479
// Low ABV: Blue-ish
480480
return brightness == Brightness.dark
481-
? colorScheme.primary.withOpacity(0.7)
481+
? colorScheme.primary.withValues(alpha: 0.7)
482482
: colorScheme.primary;
483483
} else if (abv < 7.0) {
484484
// Medium ABV: Amber/Secondary
485485
return brightness == Brightness.dark
486-
? colorScheme.secondary.withOpacity(0.8)
486+
? colorScheme.secondary.withValues(alpha: 0.8)
487487
: colorScheme.secondary;
488488
} else {
489489
// High ABV: Deep Orange/Tertiary
490490
return brightness == Brightness.dark
491-
? const Color(0xFFFF5722).withOpacity(0.85)
491+
? const Color(0xFFFF5722).withValues(alpha: 0.85)
492492
: const Color(0xFFE64A19);
493493
}
494494
}

lib/screens/style_screen.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ class _StyleScreenState extends State<StyleScreen> {
114114
colors: brightness == Brightness.dark
115115
? [
116116
theme.colorScheme.primaryContainer,
117-
theme.colorScheme.primaryContainer.withOpacity(0.7),
117+
theme.colorScheme.primaryContainer.withValues(alpha: 0.7),
118118
]
119119
: [
120120
theme.colorScheme.primaryContainer,
121-
theme.colorScheme.secondaryContainer.withOpacity(0.5),
121+
theme.colorScheme.secondaryContainer.withValues(alpha: 0.5),
122122
],
123123
),
124124
border: Border(
@@ -160,7 +160,7 @@ class _StyleScreenState extends State<StyleScreen> {
160160
height: 8 - (index * 1.2),
161161
decoration: BoxDecoration(
162162
shape: BoxShape.circle,
163-
color: accentColor.withOpacity(0.2 - (index * 0.03)),
163+
color: accentColor.withValues(alpha: 0.2 - (index * 0.03)),
164164
),
165165
),
166166
),
@@ -179,10 +179,10 @@ class _StyleScreenState extends State<StyleScreen> {
179179
width: 56,
180180
height: 56,
181181
decoration: BoxDecoration(
182-
color: accentColor.withOpacity(0.2),
182+
color: accentColor.withValues(alpha: 0.2),
183183
borderRadius: BorderRadius.circular(12),
184184
border: Border.all(
185-
color: accentColor.withOpacity(0.4),
185+
color: accentColor.withValues(alpha: 0.4),
186186
width: 2,
187187
),
188188
),
@@ -247,27 +247,27 @@ class _StyleScreenState extends State<StyleScreen> {
247247

248248
if (cat.contains('beer')) {
249249
return brightness == Brightness.dark
250-
? colorScheme.secondary.withOpacity(0.8)
250+
? colorScheme.secondary.withValues(alpha: 0.8)
251251
: colorScheme.secondary;
252252
} else if (cat.contains('cider')) {
253253
return brightness == Brightness.dark
254-
? const Color(0xFF8BC34A).withOpacity(0.8)
254+
? const Color(0xFF8BC34A).withValues(alpha: 0.8)
255255
: const Color(0xFF689F38);
256256
} else if (cat.contains('perry')) {
257257
return brightness == Brightness.dark
258-
? const Color(0xFFCDDC39).withOpacity(0.8)
258+
? const Color(0xFFCDDC39).withValues(alpha: 0.8)
259259
: const Color(0xFFAFB42B);
260260
} else if (cat.contains('mead')) {
261261
return brightness == Brightness.dark
262-
? const Color(0xFFFFEB3B).withOpacity(0.8)
262+
? const Color(0xFFFFEB3B).withValues(alpha: 0.8)
263263
: const Color(0xFFF9A825);
264264
} else if (cat.contains('wine')) {
265265
return brightness == Brightness.dark
266-
? const Color(0xFF9C27B0).withOpacity(0.8)
266+
? const Color(0xFF9C27B0).withValues(alpha: 0.8)
267267
: const Color(0xFF7B1FA2);
268268
} else if (cat.contains('low') || cat.contains('no')) {
269269
return brightness == Brightness.dark
270-
? colorScheme.primary.withOpacity(0.8)
270+
? colorScheme.primary.withValues(alpha: 0.8)
271271
: colorScheme.primary;
272272
}
273273
return colorScheme.outline;
@@ -306,10 +306,10 @@ class _StatCard extends StatelessWidget {
306306
return Container(
307307
padding: const EdgeInsets.all(12),
308308
decoration: BoxDecoration(
309-
color: theme.colorScheme.surface.withOpacity(0.5),
309+
color: theme.colorScheme.surface.withValues(alpha: 0.5),
310310
borderRadius: BorderRadius.circular(12),
311311
border: Border.all(
312-
color: theme.colorScheme.outline.withOpacity(0.2),
312+
color: theme.colorScheme.outline.withValues(alpha: 0.2),
313313
),
314314
),
315315
child: Column(

lib/widgets/environment_badge.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class EnvironmentBadge extends StatelessWidget {
6666
borderRadius: BorderRadius.circular(12),
6767
boxShadow: [
6868
BoxShadow(
69-
color: Colors.black.withOpacity(0.2),
69+
color: Colors.black.withValues(alpha: 0.2),
7070
blurRadius: 4,
7171
offset: const Offset(0, 2),
7272
),

test/analytics_service_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void main() {
2525
);
2626
await service.logFestivalSelected(festival);
2727

28-
final producer = Producer(
28+
const producer = Producer(
2929
id: '1',
3030
name: 'Test Brewery',
3131
location: 'Test Location',

test/brewery_screen_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ void main() {
1818
late MockAnalyticsService mockAnalyticsService;
1919
late BeerProvider provider;
2020

21-
final producer1 = Producer(
21+
const producer1 = Producer(
2222
id: 'brewery1',
2323
name: 'Test Brewery',
2424
location: 'Cambridge, UK',
2525
yearFounded: 1990,
2626
products: [],
2727
);
2828

29-
final product1 = Product(
29+
const product1 = Product(
3030
id: 'drink1',
3131
name: 'Test Beer 1',
3232
abv: 5.0,
3333
category: 'beer',
3434
dispense: 'cask',
3535
);
3636

37-
final product2 = Product(
37+
const product2 = Product(
3838
id: 'drink2',
3939
name: 'Test Beer 2',
4040
abv: 4.5,
@@ -52,7 +52,7 @@ void main() {
5252
mockAnalyticsService = MockAnalyticsService();
5353

5454
// Mock fetchFestivals to return a test festival
55-
final testFestival = Festival(
55+
const testFestival = Festival(
5656
id: 'cbf2025',
5757
name: 'Cambridge Beer Festival 2025',
5858
dataBaseUrl: 'https://test.example.com/cbf2025',
@@ -177,7 +177,7 @@ void main() {
177177

178178
testWidgets('does not display year founded when null',
179179
(WidgetTester tester) async {
180-
final producerNoYear = Producer(
180+
const producerNoYear = Producer(
181181
id: 'brewery2',
182182
name: 'New Brewery',
183183
location: 'London, UK',
@@ -197,7 +197,7 @@ void main() {
197197

198198
testWidgets('handles empty location',
199199
(WidgetTester tester) async {
200-
final producerNoLocation = Producer(
200+
const producerNoLocation = Producer(
201201
id: 'brewery3',
202202
name: 'Mystery Brewery',
203203
location: '',
@@ -218,14 +218,14 @@ void main() {
218218

219219
testWidgets('filters drinks to show only from requested brewery',
220220
(WidgetTester tester) async {
221-
final producer2 = Producer(
221+
const producer2 = Producer(
222222
id: 'brewery2',
223223
name: 'Other Brewery',
224224
location: 'London, UK',
225225
yearFounded: null,
226226
products: [],
227227
);
228-
final product3 = Product(
228+
const product3 = Product(
229229
id: 'drink3',
230230
name: 'Other Beer',
231231
abv: 6.0,

test/drink_detail_screen_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ void main() {
1717
late MockAnalyticsService mockAnalyticsService;
1818
late BeerProvider provider;
1919

20-
final festival = Festival(
20+
const festival = Festival(
2121
id: 'cbf2025',
2222
name: 'Cambridge Beer Festival 2025',
2323
dataBaseUrl: 'https://example.com',
2424
hashtag: '#CBF2025',
2525
);
2626

27-
final producer = Producer(
27+
const producer = Producer(
2828
id: 'brewery1',
2929
name: 'Test Brewery',
3030
location: 'Cambridge, UK',
3131
yearFounded: 1990,
3232
products: [],
3333
);
3434

35-
final product = Product(
35+
const product = Product(
3636
id: 'drink1',
3737
name: 'Test Beer',
3838
abv: 5.0,
@@ -113,7 +113,7 @@ void main() {
113113

114114
testWidgets('displays status text in chips when available',
115115
(WidgetTester tester) async {
116-
final productWithStatus = Product(
116+
const productWithStatus = Product(
117117
id: 'drink3',
118118
name: 'Status Beer',
119119
abv: 5.5,
@@ -134,7 +134,7 @@ void main() {
134134

135135
testWidgets('does not display status chip when status text is null',
136136
(WidgetTester tester) async {
137-
final productNoStatus = Product(
137+
const productNoStatus = Product(
138138
id: 'drink4',
139139
name: 'No Status Beer',
140140
abv: 4.5,
@@ -278,7 +278,7 @@ void main() {
278278

279279
testWidgets('does not display description section when notes are null',
280280
(WidgetTester tester) async {
281-
final productNoNotes = Product(
281+
const productNoNotes = Product(
282282
id: 'drink2',
283283
name: 'Simple Beer',
284284
abv: 4.0,

0 commit comments

Comments
 (0)