-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Make sure that a SelectableText doesn't crash in 0x0 environment #177875
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 a SelectableText doesn't crash in 0x0 environment #177875
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 prevent a crash in SelectableText when it is rendered in a zero-sized area. The test is a good start, but it can be improved to more accurately reproduce the original bug condition by explicitly setting a text selection, which was the root cause of the crash. I've provided a suggestion to make the test more robust.
| testWidgets('SelectableText does not crash at zero area', (WidgetTester tester) async { | ||
| await tester.pumpWidget( | ||
| const MaterialApp( | ||
| home: Center(child: SizedBox.shrink(child: SelectableText('XYZ'))), | ||
| ), | ||
| ); | ||
| expect(tester.getSize(find.byType(SelectableText)), 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.
The current test only verifies that a SelectableText with zero area can be pumped without crashing. However, the original issue (#6537) was specifically about a crash that occurred when a selection was present. To make this test more robust and accurately cover the original bug, it's better to also manually set a selection on the SelectableText and ensure that it still doesn't crash.
testWidgets('SelectableText does not crash at zero area', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Center(child: SizedBox.shrink(child: SelectableText('XYZ'))),
),
);
expect(tester.getSize(find.byType(SelectableText)), Size.zero);
// Manually set a selection to trigger the code path that was crashing.
final EditableTextState state = tester.state(find.byType(EditableText));
state.updateEditingValue(const TextEditingValue(text: 'XYZ', selection: TextSelection(baseOffset: 0, extentOffset: 3)));
await tester.pump(); // This should not crash.
});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.
Although I think the current way is ok, Gemini's suggestion would be a good addition. Can you try this?
| ); | ||
| expect(tester.getSize(find.byType(SelectableText)), Size.zero); | ||
|
|
||
| // Manually set a selection to trigger the code path that was crashing |
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.
| // Manually set a selection to trigger the code path that was crashing | |
| // Manually set a selection to trigger the code path that was crashing. |
66a72ca to
41825b8
Compare
…tter#177875) This is my attempt to handle flutter#6537 for the SelectableText widget. --------- Co-authored-by: Tong Mu <[email protected]>
…tter#177875) This is my attempt to handle flutter#6537 for the SelectableText widget. --------- Co-authored-by: Tong Mu <[email protected]>
…tter#177875) This is my attempt to handle flutter#6537 for the SelectableText widget. --------- Co-authored-by: Tong Mu <[email protected]>
This is my attempt to handle #6537 for the SelectableText widget.