mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Pass-through maxLines
in DropdownMenu
(#161903)
Pass-through `maxLines` in `DropdownMenu`. Fixes #161881 ## 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. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Taha Tesser <tessertaha@gmail.com>
This commit is contained in:
parent
46f96a44e4
commit
bcd4ecedea
@ -188,6 +188,7 @@ class DropdownMenu<T> extends StatefulWidget {
|
|||||||
required this.dropdownMenuEntries,
|
required this.dropdownMenuEntries,
|
||||||
this.inputFormatters,
|
this.inputFormatters,
|
||||||
this.closeBehavior = DropdownMenuCloseBehavior.all,
|
this.closeBehavior = DropdownMenuCloseBehavior.all,
|
||||||
|
this.maxLines = 1,
|
||||||
}) : assert(filterCallback == null || enableFilter);
|
}) : assert(filterCallback == null || enableFilter);
|
||||||
|
|
||||||
/// Determine if the [DropdownMenu] is enabled.
|
/// Determine if the [DropdownMenu] is enabled.
|
||||||
@ -502,6 +503,26 @@ class DropdownMenu<T> extends StatefulWidget {
|
|||||||
/// Defaults to [DropdownMenuCloseBehavior.all].
|
/// Defaults to [DropdownMenuCloseBehavior.all].
|
||||||
final DropdownMenuCloseBehavior closeBehavior;
|
final DropdownMenuCloseBehavior closeBehavior;
|
||||||
|
|
||||||
|
/// Specifies the maximum number of lines the selected value can display
|
||||||
|
/// in the [DropdownMenu].
|
||||||
|
///
|
||||||
|
/// If the provided value is 1, then the text will not wrap, but will scroll
|
||||||
|
/// horizontally instead. Defaults to 1.
|
||||||
|
///
|
||||||
|
/// If this is null, there is no limit to the number of lines, and the text
|
||||||
|
/// container will start with enough vertical space for one line and
|
||||||
|
/// automatically grow to accommodate additional lines as they are entered, up
|
||||||
|
/// to the height of its constraints.
|
||||||
|
///
|
||||||
|
/// If this is not null, the provided value must be greater than zero. The text
|
||||||
|
/// field will restrict the input to the given number of lines and take up enough
|
||||||
|
/// horizontal space to accommodate that number of lines.
|
||||||
|
///
|
||||||
|
/// See also:
|
||||||
|
/// * [TextField.maxLines], which specifies the maximum number of lines
|
||||||
|
/// the [TextField] can display.
|
||||||
|
final int? maxLines;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<DropdownMenu<T>> createState() => _DropdownMenuState<T>();
|
State<DropdownMenu<T>> createState() => _DropdownMenuState<T>();
|
||||||
}
|
}
|
||||||
@ -1005,6 +1026,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
|||||||
keyboardType: widget.keyboardType,
|
keyboardType: widget.keyboardType,
|
||||||
textAlign: widget.textAlign,
|
textAlign: widget.textAlign,
|
||||||
textAlignVertical: TextAlignVertical.center,
|
textAlignVertical: TextAlignVertical.center,
|
||||||
|
maxLines: widget.maxLines,
|
||||||
style: effectiveTextStyle,
|
style: effectiveTextStyle,
|
||||||
controller: _localTextEditingController,
|
controller: _localTextEditingController,
|
||||||
onEditingComplete: _handleEditingComplete,
|
onEditingComplete: _handleEditingComplete,
|
||||||
|
@ -3901,6 +3901,35 @@ void main() {
|
|||||||
},
|
},
|
||||||
variant: TargetPlatformVariant.all(),
|
variant: TargetPlatformVariant.all(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
testWidgets('DropdownMenu passes maxLines to TextField', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(home: Scaffold(body: DropdownMenu<TestMenu>(dropdownMenuEntries: menuChildren))),
|
||||||
|
);
|
||||||
|
TextField textField = tester.widget(find.byType(TextField));
|
||||||
|
// Default behavior.
|
||||||
|
expect(textField.maxLines, 1);
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: DropdownMenu<TestMenu>(dropdownMenuEntries: menuChildren, maxLines: null),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
textField = tester.widget(find.byType(TextField));
|
||||||
|
expect(textField.maxLines, null);
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: DropdownMenu<TestMenu>(dropdownMenuEntries: menuChildren, maxLines: 2),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
textField = tester.widget(find.byType(TextField));
|
||||||
|
expect(textField.maxLines, 2);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
enum TestMenu {
|
enum TestMenu {
|
||||||
|
Loading…
Reference in New Issue
Block a user