From a41b38435d14039eecfa8c0c869aec737d38102b Mon Sep 17 00:00:00 2001 From: Dibash Poudel Date: Sat, 15 Feb 2025 10:43:56 +1100 Subject: [PATCH 1/7] Fix Null check operator used on a null value --- packages/flutter/lib/src/material/progress_indicator.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/progress_indicator.dart b/packages/flutter/lib/src/material/progress_indicator.dart index 03d0679a852a4..867cac2a6e05f 100644 --- a/packages/flutter/lib/src/material/progress_indicator.dart +++ b/packages/flutter/lib/src/material/progress_indicator.dart @@ -606,7 +606,7 @@ class _CircularProgressIndicatorPainter extends CustomPainter { ..strokeCap = strokeCap ?? StrokeCap.round ..style = PaintingStyle.stroke; // If hasGap is true, draw the background arc with a gap. - if (hasGap && value! > _epsilon) { + if (hasGap && value != null && value! > _epsilon) { final double arcRadius = arcActualSize.shortestSide / 2; final double strokeRadius = strokeWidth / arcRadius; final double gapRadius = trackGap! / arcRadius; From e107af8e9506d55fafc37e05bcfd40c390c086dc Mon Sep 17 00:00:00 2001 From: Dibash Poudel Date: Tue, 18 Feb 2025 00:00:13 +1100 Subject: [PATCH 2/7] Add test for legacy CircularProgressIndicator with custom track color and year2023 disabled --- .../progress_indicator_theme_test.dart | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/packages/flutter/test/material/progress_indicator_theme_test.dart b/packages/flutter/test/material/progress_indicator_theme_test.dart index bc2b7fdd40d81..7d0850f0368e9 100644 --- a/packages/flutter/test/material/progress_indicator_theme_test.dart +++ b/packages/flutter/test/material/progress_indicator_theme_test.dart @@ -376,6 +376,76 @@ void main() { ); }); + + testWidgets( + 'Legacy indeterminate CircularProgressIndicator renders correctly with year2023 disabled and circularTrackColor is passed on theme', + (WidgetTester tester) async { + const Color circularTrackColor = Color(0XFF0000FF); + final ThemeData theme = ThemeData( + progressIndicatorTheme: const ProgressIndicatorThemeData( + circularTrackColor: circularTrackColor, + year2023: false, + ), + ); + + await tester.pumpWidget( + MaterialApp( + theme: theme, + home: const Scaffold( + body: Center(child: CircularProgressIndicator()), + ), + ), + ); + + final Finder indicatorFinder = find.byType(CircularProgressIndicator); + + // Verify that both track and active indicator are painted correctly. + expect( + indicatorFinder, + paints + ..arc( + rect: const Rect.fromLTRB(2.0, 2.0, 38.0, 38.0), + color: circularTrackColor, + strokeWidth: 4.0, + strokeCap: StrokeCap.round, + style: PaintingStyle.stroke, + ) + ..arc( + rect: const Rect.fromLTRB(2.0, 2.0, 38.0, 38.0), + color: theme.colorScheme.primary, + strokeWidth: 4.0, + strokeCap: StrokeCap.round, + style: PaintingStyle.stroke, + ), + ); + + await expectLater( + indicatorFinder, + matchesGoldenFile( + 'circular_progress_indicator_theme_year2023_false_legacy.png'), + ); + + // Re-verify that the track's color is as specified. + expect( + indicatorFinder, + paints + ..arc( + rect: const Rect.fromLTRB(2.0, 2.0, 38.0, 38.0), + color: circularTrackColor, + strokeWidth: 4.0, + strokeCap: StrokeCap.round, + style: PaintingStyle.stroke, + ), + ); + + await expectLater( + indicatorFinder, + matchesGoldenFile( + 'circular_progress_indicator_theme_year2023_false_legacy_track_color.png'), + ); + }, + ); + testWidgets( 'Opt into 2024 CircularProgressIndicator appearance with ProgressIndicatorThemeData.year2023', (WidgetTester tester) async { From 637f5b785281242e883ebe923ae0812736e01eab Mon Sep 17 00:00:00 2001 From: Dibash Poudel Date: Tue, 18 Feb 2025 17:10:36 +1100 Subject: [PATCH 3/7] Fix test code --- .../progress_indicator_theme_test.dart | 58 ++----------------- 1 file changed, 5 insertions(+), 53 deletions(-) diff --git a/packages/flutter/test/material/progress_indicator_theme_test.dart b/packages/flutter/test/material/progress_indicator_theme_test.dart index 7d0850f0368e9..7a198e00b8b6a 100644 --- a/packages/flutter/test/material/progress_indicator_theme_test.dart +++ b/packages/flutter/test/material/progress_indicator_theme_test.dart @@ -378,7 +378,7 @@ void main() { testWidgets( - 'Legacy indeterminate CircularProgressIndicator renders correctly with year2023 disabled and circularTrackColor is passed on theme', + 'Legacy indeterminate CircularProgressIndicator renders with year2023 disabled and circularTrackColor is passed on theme', (WidgetTester tester) async { const Color circularTrackColor = Color(0XFF0000FF); final ThemeData theme = ThemeData( @@ -388,61 +388,13 @@ void main() { ), ); + final SemanticsHandle handle = tester.ensureSemantics(); await tester.pumpWidget( - MaterialApp( - theme: theme, - home: const Scaffold( - body: Center(child: CircularProgressIndicator()), - ), - ), - ); - - final Finder indicatorFinder = find.byType(CircularProgressIndicator); - - // Verify that both track and active indicator are painted correctly. - expect( - indicatorFinder, - paints - ..arc( - rect: const Rect.fromLTRB(2.0, 2.0, 38.0, 38.0), - color: circularTrackColor, - strokeWidth: 4.0, - strokeCap: StrokeCap.round, - style: PaintingStyle.stroke, - ) - ..arc( - rect: const Rect.fromLTRB(2.0, 2.0, 38.0, 38.0), - color: theme.colorScheme.primary, - strokeWidth: 4.0, - strokeCap: StrokeCap.round, - style: PaintingStyle.stroke, - ), - ); - - await expectLater( - indicatorFinder, - matchesGoldenFile( - 'circular_progress_indicator_theme_year2023_false_legacy.png'), + Theme(data: theme, child: const Center(child: CircularProgressIndicator())), ); - // Re-verify that the track's color is as specified. - expect( - indicatorFinder, - paints - ..arc( - rect: const Rect.fromLTRB(2.0, 2.0, 38.0, 38.0), - color: circularTrackColor, - strokeWidth: 4.0, - strokeCap: StrokeCap.round, - style: PaintingStyle.stroke, - ), - ); - - await expectLater( - indicatorFinder, - matchesGoldenFile( - 'circular_progress_indicator_theme_year2023_false_legacy_track_color.png'), - ); + expect(tester.getSemantics(find.byType(CircularProgressIndicator)), matchesSemantics()); + handle.dispose(); }, ); From 7a5476488a293f6852c7fb56f95d54524a574ad4 Mon Sep 17 00:00:00 2001 From: Dibash Poudel Date: Tue, 18 Feb 2025 20:19:48 +1100 Subject: [PATCH 4/7] review changes: improve test name & check for exception --- .../flutter/test/material/progress_indicator_theme_test.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/flutter/test/material/progress_indicator_theme_test.dart b/packages/flutter/test/material/progress_indicator_theme_test.dart index 7a198e00b8b6a..bb24e269ae1a1 100644 --- a/packages/flutter/test/material/progress_indicator_theme_test.dart +++ b/packages/flutter/test/material/progress_indicator_theme_test.dart @@ -378,7 +378,7 @@ void main() { testWidgets( - 'Legacy indeterminate CircularProgressIndicator renders with year2023 disabled and circularTrackColor is passed on theme', + 'CircularProgressIndicator.year2023 set to false and provided circularTrackColor does not throw exception', (WidgetTester tester) async { const Color circularTrackColor = Color(0XFF0000FF); final ThemeData theme = ThemeData( @@ -395,6 +395,7 @@ void main() { expect(tester.getSemantics(find.byType(CircularProgressIndicator)), matchesSemantics()); handle.dispose(); + expect(tester.takeException(), null); }, ); From bd6caab3e9e69dadfb8de7f37aa5751206b8a95f Mon Sep 17 00:00:00 2001 From: Dibash Poudel Date: Tue, 18 Feb 2025 20:21:11 +1100 Subject: [PATCH 5/7] format file --- .../flutter/test/material/progress_indicator_theme_test.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/flutter/test/material/progress_indicator_theme_test.dart b/packages/flutter/test/material/progress_indicator_theme_test.dart index bb24e269ae1a1..26641d9608647 100644 --- a/packages/flutter/test/material/progress_indicator_theme_test.dart +++ b/packages/flutter/test/material/progress_indicator_theme_test.dart @@ -376,7 +376,6 @@ void main() { ); }); - testWidgets( 'CircularProgressIndicator.year2023 set to false and provided circularTrackColor does not throw exception', (WidgetTester tester) async { From c24608530f5b65309c523b4f7388e25dd736d642 Mon Sep 17 00:00:00 2001 From: Dibash Poudel Date: Wed, 19 Feb 2025 04:54:53 +1100 Subject: [PATCH 6/7] remove semantics matches from test --- .../flutter/test/material/progress_indicator_theme_test.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/flutter/test/material/progress_indicator_theme_test.dart b/packages/flutter/test/material/progress_indicator_theme_test.dart index 26641d9608647..00bc55cca7cf3 100644 --- a/packages/flutter/test/material/progress_indicator_theme_test.dart +++ b/packages/flutter/test/material/progress_indicator_theme_test.dart @@ -387,13 +387,10 @@ void main() { ), ); - final SemanticsHandle handle = tester.ensureSemantics(); await tester.pumpWidget( Theme(data: theme, child: const Center(child: CircularProgressIndicator())), ); - expect(tester.getSemantics(find.byType(CircularProgressIndicator)), matchesSemantics()); - handle.dispose(); expect(tester.takeException(), null); }, ); From 5d95ea1fa3d2931e53a42bfa516896c108cdb4e6 Mon Sep 17 00:00:00 2001 From: Dibash Poudel Date: Thu, 20 Feb 2025 10:59:54 +1100 Subject: [PATCH 7/7] kick tests