-
Notifications
You must be signed in to change notification settings - Fork 93
fix(genui): add missing weight property to Component constructor; default TextField width to 1 when nested in a Row
#603
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
Merged
andrewkolos
merged 2 commits into
flutter:main
from
andrewkolos:fix-unbounded-text-field-width-v2
Dec 17, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
packages/genui/test/catalog/core_widgets/text_field_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // Copyright 2025 The Flutter Authors. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:genui/genui.dart'; | ||
|
|
||
| void main() { | ||
| testWidgets('TextField with no weight in Row defaults to weight: 1 ' | ||
| 'and expands', (WidgetTester tester) async { | ||
| final a2uiProcessor = A2uiMessageProcessor( | ||
| catalogs: [CoreCatalogItems.asCatalog()], | ||
| ); | ||
| const surfaceId = 'testSurface'; | ||
| final components = [ | ||
| const Component( | ||
| id: 'row', | ||
| componentProperties: { | ||
| 'Row': { | ||
| 'children': { | ||
| 'explicitList': ['text_field'], | ||
| }, | ||
| }, | ||
| }, | ||
| ), | ||
| const Component( | ||
| id: 'text_field', | ||
| componentProperties: { | ||
| 'TextField': { | ||
| 'label': {'literalString': 'Input'}, | ||
| }, | ||
| }, | ||
| // "weight" property is left unset. | ||
| ), | ||
| ]; | ||
|
|
||
| a2uiProcessor.handleMessage( | ||
| SurfaceUpdate(surfaceId: surfaceId, components: components), | ||
| ); | ||
| a2uiProcessor.handleMessage( | ||
| const BeginRendering( | ||
| surfaceId: surfaceId, | ||
| root: 'row', | ||
| catalogId: 'a2ui.org:standard_catalog_0_8_0', | ||
| ), | ||
| ); | ||
|
|
||
| await tester.pumpWidget( | ||
| MaterialApp( | ||
| home: Scaffold( | ||
| body: GenUiSurface(host: a2uiProcessor, surfaceId: surfaceId), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| expect(find.byType(TextField), findsOneWidget); | ||
|
|
||
| final Flexible flexible = tester.widget( | ||
| find.ancestor( | ||
| of: find.byType(TextField), | ||
| matching: find.byType(Flexible), | ||
| ), | ||
| ); | ||
| expect(flexible.flex, 1); | ||
|
|
||
| final Finder textFieldFinder = find.byType(TextField); | ||
| final Size size = tester.getSize(textFieldFinder); | ||
| expect(size.width, 800.0); | ||
| }); | ||
|
|
||
| testWidgets('TextField in Row (with weight) expands', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| final manager = A2uiMessageProcessor( | ||
| catalogs: [CoreCatalogItems.asCatalog()], | ||
| ); | ||
| const surfaceId = 'testSurface'; | ||
| final components = [ | ||
| const Component( | ||
| id: 'row', | ||
| componentProperties: { | ||
| 'Row': { | ||
| 'children': { | ||
| 'explicitList': ['text_field'], | ||
| }, | ||
| }, | ||
| }, | ||
| ), | ||
| const Component( | ||
| id: 'text_field', | ||
| componentProperties: { | ||
| 'TextField': { | ||
| 'label': {'literalString': 'Input'}, | ||
| }, | ||
| }, | ||
| weight: 1, | ||
| ), | ||
| ]; | ||
|
|
||
| manager.handleMessage( | ||
| SurfaceUpdate(surfaceId: surfaceId, components: components), | ||
| ); | ||
| manager.handleMessage( | ||
| const BeginRendering( | ||
| surfaceId: surfaceId, | ||
| root: 'row', | ||
| catalogId: 'a2ui.org:standard_catalog_0_8_0', | ||
| ), | ||
| ); | ||
|
|
||
| await tester.pumpWidget( | ||
| MaterialApp( | ||
| home: Scaffold( | ||
| body: GenUiSurface(host: manager, surfaceId: surfaceId), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| expect(find.byType(TextField), findsOneWidget); | ||
|
|
||
| expect( | ||
| find.ancestor( | ||
| of: find.byType(TextField), | ||
| matching: find.byType(Flexible), | ||
| ), | ||
| findsOneWidget, | ||
| ); | ||
|
|
||
| // Default test screen width is 800. | ||
| final Size size = tester.getSize(find.byType(TextField)); | ||
| expect(size.width, 800.0); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 LGTM as a practical fix for this now! I think we need a more scalable solution long term, to avoid other leaf components having this issue. We should figure out what circumstances this error happens in - is it for any leaf component that has an unbounded max width or height? Maybe we need them to be identifiable somehow. Either way, this is a great first step I think!
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.
Yeah, constraints go down; sizes go up and all that1. Basically any widget that relies on a constraint from their parent to figure out how large they should be. For example, I suspect sliders within rows will fall victim to this exact crash.
Footnotes
https://docs.flutter.dev/ui/layout/constraints ↩
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.
And yeah, the cleaner solution would be some sort of declaration within the catalog that describe what constraint(s) a widget needs to be able to render. We'd also have to do some plumbing and/or refactoring to make this information available to layout widgets like
RowandColumn.