Skip to content

输入 Inputs

MiuixTextField

Miuix 风格的文本输入框,支持浮动标签、聚焦时的 squircle 边框动画、前后置图标。

参数类型默认值说明
controllerTextEditingController?null文本编辑控制器,未提供时内部自建
focusNodeFocusNode?null焦点节点,未提供时内部自建
onChangedValueChanged<String>?null文本变化回调
labelString''标签文字(浮动标签)
useLabelAsPlaceholderboolfalse是否把标签当作占位符(有输入后隐藏而非浮动)
enabledbooltrue是否启用
readOnlyboolfalse是否只读
textStyleTextStyle?null文本样式,默认取主题 main
leadingIconWidget?null前置图标
trailingIconWidget?null后置图标
singleLineboolfalse是否强制单行
maxLinesint?null最大行数
minLinesint?null最小行数
colorsMiuixTextFieldColors?null颜色配置,默认取主题
cornerRadiusdouble16圆角半径
insideMarginEdgeInsetsEdgeInsets.all(16)内边距(每侧)
keyboardTypeTextInputType?null键盘类型
textInputActionTextInputAction?null键盘 action 按钮类型
textCapitalizationTextCapitalizationTextCapitalization.none输入大小写策略
onSubmittedValueChanged<String>?null键盘 action 触发时回调
obscureTextboolfalse是否隐藏输入(密码)
cursorColorColor?null光标颜色,默认取聚焦边框色

示例:

dart
MiuixTextField(
  label: '用户名',
  onChanged: (v) {},
)

MiuixTextFieldColors

TextField 颜色配置。所有字段为必填。

参数类型默认值说明
backgroundColorColor必填背景色;textFieldColors 中取主题 secondaryContainer
labelColorColor必填标签色;textFieldColors 中取主题 onSecondaryContainer
borderColorColor必填聚焦边框色;textFieldColors 中取主题 primary

MiuixTextFieldDefaults

TextField 默认值集合。私有构造,仅 static 字段/方法。

常量说明
cornerRadius16默认圆角
insideMarginEdgeInsets.all(16)默认内边距(水平/垂直)
borderWidth2聚焦时边框宽度
labelFontSizeFloating10标签浮动时字号
labelFontSizeNormal17标签正常时字号
静态方法返回说明
textFieldColors(BuildContext context)MiuixTextFieldColors基于当前主题构造默认颜色配置

MiuixSwitch

Miuix 风格的开关,49x28 胶囊轨道加圆形 thumb,支持点击与水平拖拽切换。

参数类型默认值说明
valuebool必填当前是否打开
onChangedValueChanged<bool>?必填切换回调,为 null 时禁用交互
enabledbooltrue是否启用
colorsMiuixSwitchColors?null颜色配置,默认取主题

示例:

dart
MiuixSwitch(
  value: isOn,
  onChanged: (v) => setState(() => isOn = v),
)

MiuixSwitchColors

Switch 颜色配置。所有字段为必填。

参数类型默认值说明
checkedThumbColorColor必填选中时 thumb 颜色;switchColors 中取主题 onPrimary
uncheckedThumbColorColor必填未选时 thumb 颜色;switchColors 中取主题 onSecondary
disabledCheckedThumbColorColor必填禁用且选中时 thumb 颜色;取 disabledOnPrimary
disabledUncheckedThumbColorColor必填禁用且未选时 thumb 颜色;取 disabledOnSecondary
checkedTrackColorColor必填选中时轨道颜色;switchColors 中取主题 primary
uncheckedTrackColorColor必填未选时轨道颜色;switchColors 中取主题 secondary
disabledCheckedTrackColorColor必填禁用且选中时轨道颜色;取 disabledPrimary
disabledUncheckedTrackColorColor必填禁用且未选时轨道颜色;取 disabledSecondary

MiuixSwitchDefaults

Switch 默认值集合。私有构造,仅 static 字段/方法。

常量说明
trackWidth49轨道宽度
trackHeight28轨道高度
thumbSize20thumb 直径
thumbOffsetOff4thumb 关闭时偏移
thumbOffsetOn25thumb 开启时偏移
thumbScaleActive1.127thumb 按下/悬停/拖拽时放大系数
静态方法返回说明
switchColors(BuildContext context)MiuixSwitchColors基于当前主题构造默认颜色配置

MiuixCheckbox

Miuix 风格的复选框,26dp 圆形背景加带 trim 动画的勾号,支持选中/未选/半选三态。

参数类型默认值说明
valuebool?必填true=选中,false=未选,null=半选
onChangedValueChanged<bool?>?null状态变化回调,为 null 时禁用交互
enabledbooltrue是否启用
colorsMiuixCheckboxColors?null颜色配置,默认取主题

示例:

dart
MiuixCheckbox(
  value: checked,
  onChanged: (v) => setState(() => checked = v ?? false),
)

MiuixCheckboxColors

Checkbox 颜色配置。所有字段为必填。

参数类型默认值说明
checkedForegroundColorColor必填选中时前景色(勾号);checkboxColors 中取 onPrimary
uncheckedForegroundColorColor必填未选时前景色;checkboxColors 中取 secondary
disabledCheckedForegroundColorColor必填禁用且选中时前景色;取 disabledOnPrimary
disabledUncheckedForegroundColorColor必填禁用且未选时前景色;取 disabledOnPrimary
checkedBackgroundColorColor必填选中时背景色;checkboxColors 中取 primary
uncheckedBackgroundColorColor必填未选时背景色;checkboxColors 中取 secondary
disabledCheckedBackgroundColorColor必填禁用且选中时背景色;取 disabledPrimary
disabledUncheckedBackgroundColorColor必填禁用且未选时背景色;取 disabledSecondary

MiuixCheckboxDefaults

Checkbox 默认值集合。私有构造,仅 static 字段/方法。

常量说明
size26复选框尺寸(宽=高)
静态方法返回说明
checkboxColors(BuildContext context)MiuixCheckboxColors基于当前主题构造默认颜色配置

MiuixRadioButton

Miuix 风格的单选按钮,26dp,选中时显示带 trim 动画的勾号(无背景圆)。

参数类型默认值说明
selectedbool必填是否选中
onChangedValueChanged<bool>?null选中回调(仅从未选到选中触发),为 null 时禁用交互
enabledbooltrue是否启用
colorsMiuixRadioButtonColors?null颜色配置,默认取主题

示例:

dart
MiuixRadioButton(
  selected: value == 0,
  onChanged: (_) => setState(() => value = 0),
)

MiuixRadioButtonColors

RadioButton 颜色配置。所有字段为必填。

参数类型默认值说明
selectedColorColor必填选中时颜色(勾号与笔触);radioButtonColors 中取 primary
disabledSelectedColorColor必填禁用时选中颜色;取 disabledPrimary

MiuixRadioButtonDefaults

RadioButton 默认值集合。私有构造,仅 static 字段/方法。

常量说明
size26单选按钮尺寸(宽=高)
静态方法返回说明
radioButtonColors(BuildContext context)MiuixRadioButtonColors基于当前主题构造默认颜色配置

MiuixSlider

Miuix 风格的水平滑块,支持步进、关键点显示、磁性吸附、触感反馈、反向方向与禁用态。

参数类型默认值说明
valuedouble必填当前值
onValueChangedValueChanged<double>?必填值变化回调,为 null 时禁用交互
enabledbooltrue是否启用
mindouble0.0最小值
maxdouble1.0最大值
stepsint0步进数(0 为连续)
onValueChangeFinishedVoidCallback?null拖拽结束回调
reverseDirectionboolfalse是否反向
heightdoubleMiuixSliderDefaults.minHeight(28)轨道高度
colorsMiuixSliderColors?null颜色配置,默认取主题
hapticEffectMiuixSliderHapticEffectMiuixSliderHapticEffect.edge触感反馈类型
showKeyPointsboolfalse是否显示关键点
keyPointsList<double>?null自定义关键点值列表
magnetThresholddouble0.02磁性吸附阈值

示例:

dart
MiuixSlider(
  value: progress,
  onValueChanged: (v) => setState(() => progress = v),
)

MiuixSliderColors

Slider 颜色配置。所有字段为必填。MiuixVerticalSliderMiuixRangeSlider 也复用此配置。

参数类型默认值说明
foregroundColorColor必填前景色(已选中段);sliderColors 中取主题 primary
disabledForegroundColorColor必填禁用时前景色;取 disabledPrimarySlider
backgroundColorColor必填轨道背景色;sliderColors 中取 sliderBackground
disabledBackgroundColorColor必填禁用时轨道背景色;取 disabledSecondary
thumbColorColor必填thumb 颜色;sliderColors 中取 onPrimary
disabledThumbColorColor必填禁用时 thumb 颜色;取 disabledOnPrimary
keyPointColorColor必填关键点颜色;sliderColors 中取 sliderKeyPoint
keyPointForegroundColorColor必填已选中关键点颜色;取 sliderKeyPointForeground

MiuixSliderDefaults

Slider 默认值集合。私有构造,仅 static 字段/方法。

常量说明
minHeight28Slider / RangeSlider 的最小高度(水平)或宽度(垂直)
keyPointRadius3.855关键点半径
defaultHapticEffectMiuixSliderHapticEffect.edge默认触感反馈类型
thumbScaleActive1.127thumb 在按下/拖拽/悬停时的放大系数
thumbRadiusRatio0.72thumb 实际半径相对轨道半径的比例
dragOverlayAlpha0.044拖拽时的背景压暗 alpha
静态方法返回说明
sliderColors(BuildContext context)MiuixSliderColors基于当前主题构造默认颜色配置

MiuixVerticalSlider

Miuix 风格的垂直滑块,参数与 MiuixSlider 基本一致,方向为纵向。

参数类型默认值说明
valuedouble必填当前值
onValueChangedValueChanged<double>?必填值变化回调,为 null 时禁用交互
enabledbooltrue是否启用
mindouble0.0最小值
maxdouble1.0最大值
stepsint0步进数(0 为连续)
onValueChangeFinishedVoidCallback?null拖拽结束回调
reverseDirectionboolfalse是否反向
widthdoubleMiuixSliderDefaults.minHeight(28)轨道宽度
colorsMiuixSliderColors?null颜色配置,默认取主题
effectboolfalse保留参数(上游暂未启用任何视觉效果),维持 API 对齐
hapticEffectMiuixSliderHapticEffectMiuixSliderHapticEffect.edge触感反馈类型
showKeyPointsboolfalse是否显示关键点
keyPointsList<double>?null自定义关键点值列表
magnetThresholddouble0.02磁性吸附阈值

示例:

dart
SizedBox(
  height: 200,
  child: MiuixVerticalSlider(
    value: volume,
    onValueChanged: (v) => setState(() => volume = v),
  ),
)

MiuixRangeSlider

Miuix 风格的范围滑块,两个 thumb 分别控制起止值。

参数类型默认值说明
startValuedouble必填起始值
endValuedouble必填结束值
onValueChangedValueChanged<(double, double)>?必填值变化回调(起, 止),为 null 时禁用交互
enabledbooltrue是否启用
mindouble0.0最小值
maxdouble1.0最大值
stepsint0步进数(0 为连续)
onValueChangeFinishedVoidCallback?null拖拽结束回调
heightdoubleMiuixSliderDefaults.minHeight(28)轨道高度
colorsMiuixSliderColors?null颜色配置,默认取主题
hapticEffectMiuixSliderHapticEffectMiuixSliderHapticEffect.edge触感反馈类型
showKeyPointsboolfalse是否显示关键点
keyPointsList<double>?null自定义关键点值列表
magnetThresholddouble0.02磁性吸附阈值

示例:

dart
MiuixRangeSlider(
  startValue: lo,
  endValue: hi,
  onValueChanged: (r) => setState(() { lo = r.$1; hi = r.$2; }),
)

MiuixSliderHapticEffect(枚举)

Slider 触感反馈类型。

枚举值说明
none无触感反馈
edge在 0% 和 100% 端点触发
step在步进点触发

MiuixSearchBar

Miuix 风格的搜索栏容器,展开时显示尾部动作与结果内容,并拦截系统返回以先收起搜索栏。

参数类型默认值说明
inputFieldWidget必填输入框组件(通常为 MiuixInputField
onExpandedChangeValueChanged<bool>必填展开状态变化回调
contentWidget必填展开后显示的结果内容
insideMarginEdgeInsetsEdgeInsets.symmetric(horizontal: 12)输入框内边距
expandedboolfalse是否展开
outsideEndActionWidget?null展开时显示在尾部的动作组件

示例:

dart
MiuixSearchBar(
  expanded: expanded,
  onExpandedChange: (v) => setState(() => expanded = v),
  inputField: MiuixInputField(
    query: query,
    onQueryChange: (v) => setState(() => query = v),
    onSearch: (v) {},
    expanded: expanded,
    onExpandedChange: (v) => setState(() => expanded = v),
  ),
  content: const SizedBox(),
)

MiuixSearchBarDefaults

SearchBar 默认值集合。私有构造,仅 static 字段/方法。

常量说明
insideMarginEdgeInsets.symmetric(horizontal: 12)输入框内边距
inputFieldMinHeight45输入框最小高度
inputFieldFontSize17输入框字号
leadingIconStartPadding16前置图标起始 padding
leadingIconEndPadding8前置图标结束 padding
trailingIconStartPadding8后置图标起始 padding
trailingIconEndPadding16后置图标结束 padding
visibilityDurationDuration(milliseconds: 275)展开/收起动画时长
textFadeDurationDuration(milliseconds: 150)文本淡入淡出时长

MiuixInputField

Miuix 搜索输入框,配合 MiuixSearchBar 使用,提供搜索图标、清除按钮与占位标签。

参数类型默认值说明
queryString必填当前查询文本
onQueryChangeValueChanged<String>必填查询文本变化回调
onSearchValueChanged<String>必填提交搜索回调
expandedbool必填是否展开(聚焦)
onExpandedChangeValueChanged<bool>必填展开状态变化回调
labelString''占位标签文字
enabledbooltrue是否启用
textStyleTextStyle?null文本样式
colorColor?null背景色,默认取主题
leadingIconWidget?null前置图标,默认为搜索图标
trailingIconWidget?null后置图标,null 时用带淡入淡出的默认清除按钮
focusNodeFocusNode?null焦点节点,未提供时内部自建

示例:

dart
MiuixInputField(
  query: query,
  onQueryChange: (v) => setState(() => query = v),
  onSearch: (v) {},
  expanded: expanded,
  onExpandedChange: (v) => setState(() => expanded = v),
  label: '搜索',
)

MiuixNumberPicker

Miuix 风格的垂直数字选择器,中心选中,远离中心的项渐隐缩小,支持循环与惯性 snap。

参数类型默认值说明
valueint必填当前值
onValueChangedValueChanged<int>?必填值变化回调,为 null 时禁用交互
enabledbooltrue是否启用
minint0最小值
maxint10最大值
labelString Function(int)?null值到显示文本的映射,默认为 value.toString()
visibleItemCountint5可见项数(必须为奇数且 >= 3)
wrapAroundboolfalse是否循环滚动
colorsMiuixNumberPickerColors?null颜色配置,默认取主题
textStyleTextStyle?null文本样式,默认取主题 title1
itemHeightdoubleMiuixNumberPickerDefaults.itemHeight(45)每项高度

示例:

dart
MiuixNumberPicker(
  value: hour,
  min: 0,
  max: 23,
  onValueChanged: (v) => setState(() => hour = v),
)

MiuixNumberPickerColors

NumberPicker 颜色配置。所有字段为必填。

参数类型默认值说明
selectedTextColorColor必填选中项文本色;colors 中取主题 onSurface
unselectedTextColorColor必填未选中项文本色;colors 中取 onSurfaceSecondary
disabledSelectedTextColorColor必填禁用时选中文本色;取 disabledOnSecondary
disabledUnselectedTextColorColor必填禁用时未选中文本色;取 disabledOnSecondary

MiuixNumberPickerDefaults

NumberPicker 默认值集合。私有构造,仅 static 字段/方法。

常量说明
itemHeight45每项高度
静态方法返回说明
colors(BuildContext context)MiuixNumberPickerColors基于当前主题构造默认颜色配置

Released under the Apache-2.0 License.