Fix SafeArea and SliverSafeArea debug flag properties (#63455)

This commit is contained in:
Declan Woods 2020-08-15 03:01:05 +08:00 committed by GitHub
parent 5ec7426be7
commit 03dcd1bd5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 6 deletions

View File

@ -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'));
}
}

View File

@ -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);
});
}