DropdownMenu cleanup (#147860)
## Description This PR cleans up some typos and formatting issues in `DropdownMenu` implementation. ## Tests No semantic change.
This commit is contained in:
parent
a7272028c6
commit
986c5a9d7f
@ -376,7 +376,7 @@ class DropdownMenu<T> extends StatefulWidget {
|
||||
/// Defaults to null.
|
||||
final EdgeInsets? expandedInsets;
|
||||
|
||||
/// When [DropdownMenu.enableSearch] is true, this callback is used to compute
|
||||
/// When [DropdownMenu.enableSearch] is true, this callback is used to compute
|
||||
/// the index of the search result to be highlighted.
|
||||
///
|
||||
/// {@tool snippet}
|
||||
@ -460,10 +460,10 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (widget.controller == null) {
|
||||
_localTextEditingController?.dispose();
|
||||
_localTextEditingController = null;
|
||||
}
|
||||
if (widget.controller == null) {
|
||||
_localTextEditingController?.dispose();
|
||||
_localTextEditingController = null;
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@ -557,9 +557,10 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
||||
|
||||
List<Widget> _buildButtons(
|
||||
List<DropdownMenuEntry<T>> filteredEntries,
|
||||
TextDirection textDirection,
|
||||
{ int? focusedIndex, bool enableScrollToHighlight = true}
|
||||
) {
|
||||
TextDirection textDirection, {
|
||||
int? focusedIndex,
|
||||
bool enableScrollToHighlight = true,
|
||||
}) {
|
||||
final List<Widget> result = <Widget>[];
|
||||
for (int i = 0; i < filteredEntries.length; i++) {
|
||||
final DropdownMenuEntry<T> entry = filteredEntries[i];
|
||||
@ -699,9 +700,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
||||
|
||||
final TextStyle? effectiveTextStyle = widget.textStyle ?? theme.textStyle ?? defaults.textStyle;
|
||||
|
||||
MenuStyle? effectiveMenuStyle = widget.menuStyle
|
||||
?? theme.menuStyle
|
||||
?? defaults.menuStyle!;
|
||||
MenuStyle? effectiveMenuStyle = widget.menuStyle ?? theme.menuStyle ?? defaults.menuStyle!;
|
||||
|
||||
final double? anchorWidth = getWidth(_anchorKey);
|
||||
if (widget.width != null) {
|
||||
@ -742,60 +741,60 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
||||
);
|
||||
|
||||
final Widget leadingButton = Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: widget.leadingIcon ?? const SizedBox()
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: widget.leadingIcon ?? const SizedBox.shrink()
|
||||
);
|
||||
|
||||
final Widget textField = TextField(
|
||||
key: _anchorKey,
|
||||
mouseCursor: effectiveMouseCursor,
|
||||
focusNode: widget.focusNode,
|
||||
canRequestFocus: canRequestFocus(),
|
||||
enableInteractiveSelection: canRequestFocus(),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
style: effectiveTextStyle,
|
||||
controller: _localTextEditingController,
|
||||
onEditingComplete: () {
|
||||
if (currentHighlight != null) {
|
||||
final DropdownMenuEntry<T> entry = filteredEntries[currentHighlight!];
|
||||
if (entry.enabled) {
|
||||
_localTextEditingController?.value = TextEditingValue(
|
||||
text: entry.label,
|
||||
selection: TextSelection.collapsed(offset: entry.label.length),
|
||||
);
|
||||
widget.onSelected?.call(entry.value);
|
||||
}
|
||||
} else {
|
||||
widget.onSelected?.call(null);
|
||||
key: _anchorKey,
|
||||
mouseCursor: effectiveMouseCursor,
|
||||
focusNode: widget.focusNode,
|
||||
canRequestFocus: canRequestFocus(),
|
||||
enableInteractiveSelection: canRequestFocus(),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
style: effectiveTextStyle,
|
||||
controller: _localTextEditingController,
|
||||
onEditingComplete: () {
|
||||
if (currentHighlight != null) {
|
||||
final DropdownMenuEntry<T> entry = filteredEntries[currentHighlight!];
|
||||
if (entry.enabled) {
|
||||
_localTextEditingController?.value = TextEditingValue(
|
||||
text: entry.label,
|
||||
selection: TextSelection.collapsed(offset: entry.label.length),
|
||||
);
|
||||
widget.onSelected?.call(entry.value);
|
||||
}
|
||||
if (!widget.enableSearch) {
|
||||
currentHighlight = null;
|
||||
}
|
||||
controller.close();
|
||||
},
|
||||
onTap: () {
|
||||
handlePressed(controller);
|
||||
},
|
||||
onChanged: (String text) {
|
||||
controller.open();
|
||||
setState(() {
|
||||
filteredEntries = widget.dropdownMenuEntries;
|
||||
_enableFilter = widget.enableFilter;
|
||||
});
|
||||
},
|
||||
inputFormatters: widget.inputFormatters,
|
||||
decoration: InputDecoration(
|
||||
enabled: widget.enabled,
|
||||
label: widget.label,
|
||||
hintText: widget.hintText,
|
||||
helperText: widget.helperText,
|
||||
errorText: widget.errorText,
|
||||
prefixIcon: widget.leadingIcon != null ? Container(
|
||||
key: _leadingKey,
|
||||
child: widget.leadingIcon
|
||||
) : null,
|
||||
suffixIcon: trailingButton,
|
||||
).applyDefaults(effectiveInputDecorationTheme)
|
||||
} else {
|
||||
widget.onSelected?.call(null);
|
||||
}
|
||||
if (!widget.enableSearch) {
|
||||
currentHighlight = null;
|
||||
}
|
||||
controller.close();
|
||||
},
|
||||
onTap: () {
|
||||
handlePressed(controller);
|
||||
},
|
||||
onChanged: (String text) {
|
||||
controller.open();
|
||||
setState(() {
|
||||
filteredEntries = widget.dropdownMenuEntries;
|
||||
_enableFilter = widget.enableFilter;
|
||||
});
|
||||
},
|
||||
inputFormatters: widget.inputFormatters,
|
||||
decoration: InputDecoration(
|
||||
enabled: widget.enabled,
|
||||
label: widget.label,
|
||||
hintText: widget.hintText,
|
||||
helperText: widget.helperText,
|
||||
errorText: widget.errorText,
|
||||
prefixIcon: widget.leadingIcon != null ? Container(
|
||||
key: _leadingKey,
|
||||
child: widget.leadingIcon
|
||||
) : null,
|
||||
suffixIcon: trailingButton,
|
||||
).applyDefaults(effectiveInputDecorationTheme)
|
||||
);
|
||||
|
||||
if (widget.expandedInsets != null) {
|
||||
@ -809,7 +808,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
||||
width: widget.width,
|
||||
children: <Widget>[
|
||||
textField,
|
||||
for (final Widget item in _initialMenu!) item,
|
||||
..._initialMenu!,
|
||||
trailingButton,
|
||||
leadingButton,
|
||||
],
|
||||
@ -1032,21 +1031,21 @@ class _RenderDropdownMenuBody extends RenderBox
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicHeight(double height) {
|
||||
double computeMinIntrinsicHeight(double width) {
|
||||
final RenderBox? child = firstChild;
|
||||
double width = 0;
|
||||
if (child != null) {
|
||||
width = math.max(width, child.getMinIntrinsicHeight(height));
|
||||
width = math.max(width, child.getMinIntrinsicHeight(width));
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double height) {
|
||||
double computeMaxIntrinsicHeight(double width) {
|
||||
final RenderBox? child = firstChild;
|
||||
double width = 0;
|
||||
if (child != null) {
|
||||
width = math.max(width, child.getMaxIntrinsicHeight(height));
|
||||
width = math.max(width, child.getMaxIntrinsicHeight(width));
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user