From 03dcd1bd5a95bbfb0392e81b95fc640b6530b355 Mon Sep 17 00:00:00 2001 From: Declan Woods Date: Sat, 15 Aug 2020 03:01:05 +0800 Subject: [PATCH] Fix SafeArea and SliverSafeArea debug flag properties (#63455) --- .../flutter/lib/src/widgets/safe_area.dart | 12 +++---- .../flutter/test/widgets/safe_area_test.dart | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/packages/flutter/lib/src/widgets/safe_area.dart b/packages/flutter/lib/src/widgets/safe_area.dart index 0a7b9ce2105..4e410626904 100644 --- a/packages/flutter/lib/src/widgets/safe_area.dart +++ b/packages/flutter/lib/src/widgets/safe_area.dart @@ -125,9 +125,9 @@ class SafeArea extends StatelessWidget { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(FlagProperty('left', value: left, ifTrue: 'avoid left padding')); - properties.add(FlagProperty('top', value: left, ifTrue: 'avoid top padding')); - properties.add(FlagProperty('right', value: left, ifTrue: 'avoid right padding')); - properties.add(FlagProperty('bottom', value: left, ifTrue: 'avoid bottom padding')); + properties.add(FlagProperty('top', value: top, ifTrue: 'avoid top padding')); + properties.add(FlagProperty('right', value: right, ifTrue: 'avoid right padding')); + properties.add(FlagProperty('bottom', value: bottom, ifTrue: 'avoid bottom padding')); } } @@ -219,8 +219,8 @@ class SliverSafeArea extends StatelessWidget { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(FlagProperty('left', value: left, ifTrue: 'avoid left padding')); - properties.add(FlagProperty('top', value: left, ifTrue: 'avoid top padding')); - properties.add(FlagProperty('right', value: left, ifTrue: 'avoid right padding')); - properties.add(FlagProperty('bottom', value: left, ifTrue: 'avoid bottom padding')); + properties.add(FlagProperty('top', value: top, ifTrue: 'avoid top padding')); + properties.add(FlagProperty('right', value: right, ifTrue: 'avoid right padding')); + properties.add(FlagProperty('bottom', value: bottom, ifTrue: 'avoid bottom padding')); } } diff --git a/packages/flutter/test/widgets/safe_area_test.dart b/packages/flutter/test/widgets/safe_area_test.dart index d6a342e9ddc..06514bc73a8 100644 --- a/packages/flutter/test/widgets/safe_area_test.dart +++ b/packages/flutter/test/widgets/safe_area_test.dart @@ -89,6 +89,22 @@ void main() { expect(tester.getBottomRight(find.byType(Placeholder)), const Offset(800.0, 600.0)); }); + testWidgets('SafeArea - properties', (WidgetTester tester) async { + final SafeArea child = SafeArea( + left: true, + right: false, + bottom: false, + child: Container() + ); + final DiagnosticPropertiesBuilder properties = DiagnosticPropertiesBuilder(); + child.debugFillProperties(properties); + + expect(properties.properties.any((DiagnosticsNode n) => n is FlagProperty && n.toString() == 'avoid left padding'), true); + expect(properties.properties.any((DiagnosticsNode n) => n is FlagProperty && n.toString() == 'avoid right padding'), false); + expect(properties.properties.any((DiagnosticsNode n) => n is FlagProperty && n.toString() == 'avoid top padding'), true); + expect(properties.properties.any((DiagnosticsNode n) => n is FlagProperty && n.toString() == 'avoid bottom padding'), false); + }); + group('SafeArea maintains bottom viewPadding when specified for consumed bottom padding', () { Widget boilerplate(Widget child) { return Localizations( @@ -300,4 +316,20 @@ void main() { ]); }); }); + + testWidgets('SliverSafeArea - properties', (WidgetTester tester) async { + const SliverSafeArea child = SliverSafeArea( + left: true, + right: false, + bottom: false, + sliver: SliverToBoxAdapter(child: SizedBox(width: 800.0, height: 100.0, child: Text('padded'))), + ); + final DiagnosticPropertiesBuilder properties = DiagnosticPropertiesBuilder(); + child.debugFillProperties(properties); + + expect(properties.properties.any((DiagnosticsNode n) => n is FlagProperty && n.toString() == 'avoid left padding'), true); + expect(properties.properties.any((DiagnosticsNode n) => n is FlagProperty && n.toString() == 'avoid right padding'), false); + expect(properties.properties.any((DiagnosticsNode n) => n is FlagProperty && n.toString() == 'avoid top padding'), true); + expect(properties.properties.any((DiagnosticsNode n) => n is FlagProperty && n.toString() == 'avoid bottom padding'), false); + }); }