-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Make sure that an InputDecorator doesn't crash in 0x0 environment #176116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sure that an InputDecorator doesn't crash in 0x0 environment #176116
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds a regression test to ensure that InputDecorator does not crash when rendered in a zero-sized environment. The added test case is good, but it only covers the default UnderlineInputBorder. The original issue that this PR aims to fix was specifically about OutlineInputBorder. I've suggested expanding the test to also cover OutlineInputBorder to ensure the fix is comprehensive.
| testWidgets('InputDecorator does not crash at zero area', (WidgetTester tester) async { | ||
| await tester.pumpWidget( | ||
| const MaterialApp( | ||
| home: Scaffold( | ||
| body: Center( | ||
| child: SizedBox.shrink(child: InputDecorator(decoration: InputDecoration())), | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| expect(tester.getSize(find.byType(InputDecorator)), Size.zero); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good regression test. However, the original issue (#6537) was specifically about OutlineInputBorder, while this test uses the default InputDecoration, which results in an UnderlineInputBorder.
To make the test more comprehensive and ensure it covers the original bug, I suggest also testing with an OutlineInputBorder. You could add another test case or parameterize this one.
testWidgets('InputDecorator does not crash at zero area', (WidgetTester tester) async {
// Test with default UnderlineInputBorder
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: Center(
child: SizedBox.shrink(child: InputDecorator(decoration: InputDecoration())),
),
),
),
);
expect(tester.getSize(find.byType(InputDecorator)), Size.zero);
// Test with OutlineInputBorder as mentioned in the original issue.
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: Center(
child: SizedBox.shrink(
child: InputDecorator(
decoration: InputDecoration(
border: OutlineInputBorder(),
),
),
),
),
),
),
);
expect(tester.getSize(find.byType(InputDecorator)), Size.zero);
});There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
dkwingsmt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checklist:
- The test is in the correct file
- The test name goes “does not crash at zero area”
- The target widget is wrapped by
Center(or is fullscreen) - The target widget does not have an overlay, or the overlay is tested
- The target widget is expected to have a size of exactly
Size.zero
…utter#176116) This is my attempt to handle flutter#6537 for the InputDecorator widget. --------- Co-authored-by: Tong Mu <[email protected]>
This is my attempt to handle #6537 for the InputDecorator widget.