mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add DropdownButtonFormField value param test (#170518)
This PR adds a new test that verifies that the value param is only used on initial build and when resetting the field. Test for https://github.com/flutter/flutter/pull/170050#issuecomment-2965486000 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Bruno Leroux <bruno.leroux@gmail.com>
This commit is contained in:
parent
a33b81c3f9
commit
fc7c97c146
@ -588,6 +588,55 @@ void main() {
|
||||
expect(value, equals('three'));
|
||||
});
|
||||
|
||||
testWidgets('Dropdown form field only uses value parameter when first built and when reset', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
final GlobalKey<FormFieldState<String>> fieldKey = GlobalKey<FormFieldState<String>>();
|
||||
await tester.pumpWidget(
|
||||
StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
return MaterialApp(
|
||||
home: Material(
|
||||
child: DropdownButtonFormField<String>(
|
||||
key: fieldKey,
|
||||
value: 'one',
|
||||
hint: const Text('Select Value'),
|
||||
items:
|
||||
menuItems.map((String val) {
|
||||
return DropdownMenuItem<String>(value: val, child: Text(val));
|
||||
}).toList(),
|
||||
onChanged: (String? newValue) {
|
||||
setState(() {
|
||||
// Do nothing, just to trigger a rebuild.
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
expect(fieldKey.currentState!.value, 'one');
|
||||
|
||||
// Open the dropdown menu.
|
||||
await tester.tap(find.text('one'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('three').last);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The value should update to selected, not the initial value.
|
||||
expect(find.text('three'), findsOneWidget);
|
||||
expect(fieldKey.currentState!.value, 'three');
|
||||
|
||||
fieldKey.currentState!.reset();
|
||||
await tester.pump();
|
||||
|
||||
// Reset to the initial value.
|
||||
expect(find.text('one'), findsOneWidget);
|
||||
expect(fieldKey.currentState!.value, 'one');
|
||||
});
|
||||
|
||||
testWidgets('Dropdown in ListView', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/12053
|
||||
// Positions a DropdownButton at the left and right edges of the screen,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user