-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Make sure that GridTile doesn't crash in 0x0 environment #175321
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
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 aims to prevent GridTile and GridTileBar from crashing when rendered in a zero-sized area by wrapping GridTileBar's content in a LayoutBuilder to make its height responsive to layout constraints. A corresponding test case is added to verify the fix. However, the implementation has a critical flaw where it uses constraints.minHeight instead of constraints.maxHeight to calculate the bar's height. This causes the GridTileBar to have zero height in most standard use cases, effectively making it disappear. I've provided suggestions to correct this logic in both the widget implementation and its new test.
| height: math.min( | ||
| (title != null && subtitle != null) ? 68.0 : 48.0, | ||
| constraints.minHeight, | ||
| ), |
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.
Using constraints.minHeight here will cause the GridTileBar to have a height of 0 in its most common use case inside a GridTile. GridTile uses Positioned widgets for its header and footer, which provide loose vertical constraints (minHeight of 0). This results in the bar's height being calculated as math.min(idealHeight, 0.0), which is 0.0, making it invisible.
To correctly respect the available space while maintaining the desired height, you should use constraints.maxHeight. This will allow the bar to take its ideal height when space is available, and shrink to fit when space is constrained.
height: math.min(
(title != null && subtitle != null) ? 68.0 : 48.0,
constraints.maxHeight,
),| ), | ||
| ); | ||
| expect(tester.getSize(find.byType(GridTile)), Size.zero); | ||
| expect(tester.getSize(find.byType(GridTileBar)), 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 assertion will pass with the current implementation, but the implementation has a flaw that makes the GridTileBar have zero height in normal conditions. After fixing the implementation to use constraints.maxHeight, the GridTileBar will correctly calculate its height. In this test scenario, it's placed in a GridTile constrained to zero width, but with loose vertical constraints. Therefore, its size should be Size(0.0, 68.0) (since it has both a title and subtitle). The test should be updated to assert this correct size.
| expect(tester.getSize(find.byType(GridTileBar)), Size.zero); | |
| expect(tester.getSize(find.byType(GridTileBar)), const Size(0.0, 68.0)); |
c7aaa06 to
ca54886
Compare
| ), | ||
| ); | ||
| expect(tester.getSize(find.byType(GridTile)), Size.zero); | ||
| expect(tester.getSize(find.byType(GridTileBar)).isEmpty, isTrue); |
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.
Can you split GridTileBar into a separate test case so that we can verify its layout in a constraint of exactly zero?
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
|
autosubmit label was removed for flutter/flutter/175321, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.
|
Roll Flutter from 027f2e410241 to e5d5c01850f2 (73 revisions) flutter/flutter@027f2e4...e5d5c01 2025-11-04 [email protected] [web] Upgrade Chrome to 141 (for engine tests) (flutter/flutter#177743) 2025-11-04 [email protected] Replace deprecated withOpacity in `chip_animation_style.0.dart` example (flutter/flutter#177834) 2025-11-04 [email protected] Roll Skia from 03612114a36d to c89b6118266b (1 revision) (flutter/flutter#177991) 2025-11-04 [email protected] [web] Delete unused futurize util (flutter/flutter#177861) 2025-11-04 [email protected] Roll Skia from 1a179581af75 to 03612114a36d (1 revision) (flutter/flutter#177984) 2025-11-04 [email protected] Roll Skia from 150f844e83fb to 1a179581af75 (3 revisions) (flutter/flutter#177979) 2025-11-04 [email protected] Roll Dart SDK from 6f1bd8d05b1d to 156bf665dba4 (2 revisions) (flutter/flutter#177976) 2025-11-04 [email protected] Roll Skia from 3990fc40acdf to 150f844e83fb (1 revision) (flutter/flutter#177964) 2025-11-04 [email protected] Roll Skia from 85adfd3b8e75 to 3990fc40acdf (1 revision) (flutter/flutter#177962) 2025-11-04 [email protected] Fix `isHeif` crash (flutter/flutter#177944) 2025-11-04 [email protected] Roll Dart SDK from ac065fcd782e to 6f1bd8d05b1d (1 revision) (flutter/flutter#177955) 2025-11-04 [email protected] Roll Skia from 001516d132f0 to 85adfd3b8e75 (4 revisions) (flutter/flutter#177958) 2025-11-04 [email protected] [ Widget Preview ] Add analytic event that's reported when the previewer is opened (flutter/flutter#177949) 2025-11-04 [email protected] Marks Linux_pixel_7pro dynamic_path_stroke_tessellation_perf__timeline_summary to be unflaky (flutter/flutter#171144) 2025-11-03 [email protected] Roll Skia from da9b8fb01101 to 001516d132f0 (6 revisions) (flutter/flutter#177951) 2025-11-03 [email protected] Add FAQ entry about our attempts to remove Skia image codecs. (flutter/flutter#177947) 2025-11-03 [email protected] Add blockAccessibilityFocus flag (flutter/flutter#175551) 2025-11-03 [email protected] Make sure that a SnackBarAction doesn't crash in 0x0 environment (flutter/flutter#177899) 2025-11-03 [email protected] Make sure that a SelectionArea doesn't crash in 0x0 environment (flutter/flutter#177876) 2025-11-03 [email protected] Speculative fix for android_verified_input_test (flutter/flutter#177937) 2025-11-03 [email protected] [skia] Explicitly disable XPS backend (flutter/flutter#177050) 2025-11-03 [email protected] Roll Dart SDK from 2d3aa1d5cb9f to ac065fcd782e (2 revisions) (flutter/flutter#177927) 2025-11-03 [email protected] Improve Impeller's docs in the top-level docs folder (flutter/flutter#177848) 2025-11-03 [email protected] Make sure that GridTile doesn't crash in 0x0 environment (flutter/flutter#175321) 2025-11-03 [email protected] Make sure that a Slider doesn't crash in 0x0 environment (flutter/flutter#177882) 2025-11-03 [email protected] fix(impeller): fix params to glDiscardFrameBufferEXT (flutter/flutter#175589) 2025-11-03 [email protected] Roll Skia from 56a10bf56ee0 to da9b8fb01101 (5 revisions) (flutter/flutter#177928) 2025-11-03 [email protected] wires up set application locale to web engine (flutter/flutter#177284) 2025-11-03 [email protected] [Android 16] Update `linux_android_emu_unstable` to use avd rev 7 (flutter/flutter#177854) 2025-11-03 [email protected] Make sure that a CheckedPopupMenuItem doesn't crash in 0x0 environment (flutter/flutter#177545) 2025-11-03 [email protected] Roll Fuchsia Linux SDK from Ynp3qiXocK8WLTjlb... to vxK5obzfr1X9P2kSh... (flutter/flutter#177917) 2025-11-03 [email protected] Update pubspec.yaml.tmpl build version tracker on line 5 (flutter/flutter#173600) 2025-11-03 [email protected] [Impeller] Fix the source rectangle used when rendering an AtlasContents with the strict mode for nine-patch images (flutter/flutter#177860) 2025-11-03 [email protected] docs: Default Splash / Loading screen for web app in index.html (flutter/flutter#177084) 2025-11-03 [email protected] Roll Skia from 25e1e4e96980 to 56a10bf56ee0 (6 revisions) (flutter/flutter#177910) 2025-11-03 [email protected] Make sure that a PopupMenuItem doesn't crash in 0x0 environment (flutter/flutter#177533) 2025-11-03 [email protected] Make sure that a RefreshProgressIndicator doesn't crash in 0x0 enviro… (flutter/flutter#177556) 2025-11-03 [email protected] Make sure that a PopupMenuButton doesn't crash in 0x0 environment (flutter/flutter#177493) 2025-11-03 [email protected] Make sure that a CircularProgressIndicator doesn't crash in 0x0 envir… (flutter/flutter#177555) 2025-11-02 [email protected] Make sure that a Radio doesn't crash in 0x0 environment (flutter/flutter#177580) 2025-11-02 [email protected] Make sure that a RadioListTile doesn't crash in 0x0 environment (flutter/flutter#177576) 2025-11-02 [email protected] Make sure that an ExpandIcon doesn't crash in 0x0 envrionment (flutter/flutter#175042) 2025-11-02 [email protected] Make sure that a RangeSlider doesn't crash in 0x0 environment (flutter/flutter#177642) 2025-11-02 [email protected] Make sure that a GridTileBar doesn't crash in 0x0 environment (flutter/flutter#177546) 2025-11-02 [email protected] Make sure that a LinearProgressIndicator doesn't crash in 0x0 environ… (flutter/flutter#177553) 2025-11-02 [email protected] Make sure that a PopupMenuDivider doesn't crash in 0x0 environment (flutter/flutter#177445) ...
) This is my attempt to handle flutter#6537 for the GridTile widget. --------- Co-authored-by: Tong Mu <[email protected]>
) This is my attempt to handle flutter#6537 for the GridTile widget. --------- Co-authored-by: Tong Mu <[email protected]>
This is my attempt to handle #6537 for the GridTile widget.