Skip to content

设置项与选择器 Preferences & Pickers

MiuixArrowPreference

带右箭头的偏好设置行,末尾追加 10×16 右箭头图标(RTL 下自动翻转),复用基础行的点击/按压语义。

参数类型默认值说明
titleString必填行标题
titleColorMiuixBasicComponentColors?null标题颜色,null 取 MiuixBasicComponentDefaults.titleColor
summaryString?null行摘要
summaryColorMiuixBasicComponentColors?null摘要颜色,null 取 MiuixBasicComponentDefaults.summaryColor
startActionWidget?null起始侧内容
endActionsList<Widget>?null末尾箭头之前的额外内容
bottomActionWidget?null底部内容,位于主行下方
insideMarginEdgeInsetsGeometryMiuixBasicComponentDefaults.insideMargin内边距
onClickVoidCallback?null点击回调,null 时不可点击
holdDownStateboolfalse是否处于按压态
enabledbooltrue是否启用

示例:

dart
MiuixArrowPreference(
  title: '关于',
  summary: '版本、许可与开源信息',
  onClick: () {},
)

MiuixArrowPreferenceEndActionColors

ArrowPreference 末尾箭头的颜色配置。根据 enabled 在启用色与禁用色之间切换。

字段类型说明
colorColor启用态颜色
disabledColorColor禁用态颜色
方法签名说明
resolveColor resolve(bool enabled)enabled 为 true 返回 color,否则返回 disabledColor

MiuixArrowPreferenceDefaults

ArrowPreference 的默认值集合。私有构造,仅提供静态方法。

方法签名说明
endActionColorsMiuixArrowPreferenceEndActionColors endActionColors(BuildContext context)末尾箭头的默认颜色:color 取主题 onSurfaceVariantActionsdisabledColordisabledOnSecondaryVariant

MiuixSwitchPreference

带开关的偏好设置行,行末追加 MiuixSwitch;点击整行会切换 value 并触发 onChanged

参数类型默认值说明
valuebool必填当前开关状态
onChangedValueChanged<bool>必填状态变更回调
titleString必填行标题
titleColorMiuixBasicComponentColors?null标题颜色,null 取默认
summaryString?null行摘要
summaryColorMiuixBasicComponentColors?null摘要颜色,null 取默认
startActionWidget?null起始侧内容
endActionsList<Widget>?null开关之前的额外内容
bottomActionWidget?null底部内容
switchColorsMiuixSwitchColors?null开关颜色,null 取 MiuixSwitchDefaults.switchColors
insideMarginEdgeInsetsGeometryMiuixBasicComponentDefaults.insideMargin内边距
holdDownStateboolfalse是否处于按压态
enabledbooltrue是否启用

示例:

dart
MiuixSwitchPreference(
  title: '飞行模式',
  value: enabled,
  onChanged: (v) => setState(() => enabled = v),
)

MiuixCheckboxLocation

MiuixCheckboxPreference 中复选框的位置枚举。RTL 下 start/end 会自动镜像。

说明
start起始侧(标题之前)
end末尾侧(endActions 之后)

MiuixCheckboxPreference

带复选框的偏好设置行,复选框位置由 checkboxLocation 决定;点击整行切换 value 并触发 onChanged

参数类型默认值说明
titleString必填行标题
valuebool必填当前复选框状态
onChangedValueChanged<bool>?必填状态变更回调,null 时不可交互
titleColorMiuixBasicComponentColors?null标题颜色,null 取默认
summaryString?null行摘要
summaryColorMiuixBasicComponentColors?null摘要颜色,null 取默认
checkboxColorsMiuixCheckboxColors?null复选框颜色,null 取 MiuixCheckboxDefaults.checkboxColors
startActionWidget?null起始侧额外内容(复选框之后,5dp 间距)
endActionsList<Widget>?null末尾额外内容(复选框之前,8dp 间距)
checkboxLocationMiuixCheckboxLocationMiuixCheckboxLocation.start复选框位置
bottomActionWidget?null底部内容
insideMarginEdgeInsetsGeometryMiuixBasicComponentDefaults.insideMargin内边距
holdDownStateboolfalse是否处于按压态
enabledbooltrue是否启用

枚举 MiuixCheckboxLocationstart(起始侧,标题之前)、end(末尾侧,endActions 之后)。

示例:

dart
MiuixCheckboxPreference(
  title: '接受条款',
  value: agreed,
  onChanged: (v) => setState(() => agreed = v),
)

MiuixRadioButtonLocation

MiuixRadioButtonPreference 中单选按钮的位置枚举。RTL 下 start/end 会自动镜像。

说明
start起始侧(标题之前)
end末尾侧(endActions 之后)

MiuixRadioButtonPreference

带单选按钮的偏好设置行,单选按钮位置由 radioButtonLocation 决定;选中时标题/摘要色切换为 primary,点击整行触发 onClick 并给出触感反馈。

参数类型默认值说明
titleString必填行标题
selectedbool必填是否处于选中态
onClickVoidCallback?null点击回调,null 时不可点击
summaryString?null行摘要
colorsMiuixRadioButtonPreferenceColors?null标题/摘要颜色,null 取 MiuixRadioButtonPreferenceDefaults.radioButtonPreferenceColors
radioButtonColorsMiuixRadioButtonColors?null单选按钮颜色,null 取 MiuixRadioButtonDefaults.radioButtonColors
startActionWidget?null起始侧额外内容(单选按钮之后,5dp 间距)
endActionsList<Widget>?null末尾额外内容(单选按钮之前,8dp 间距)
radioButtonLocationMiuixRadioButtonLocationMiuixRadioButtonLocation.start单选按钮位置
bottomActionWidget?null底部内容
insideMarginEdgeInsetsGeometryMiuixBasicComponentDefaults.insideMargin内边距
holdDownStateboolfalse是否处于按压态
enabledbooltrue是否启用

枚举 MiuixRadioButtonLocationstart(起始侧,标题之前)、end(末尾侧,endActions 之后)。

示例:

dart
MiuixRadioButtonPreference(
  title: '选项 A',
  selected: index == 0,
  onClick: () => setState(() => index = 0),
)

MiuixRadioButtonPreferenceColors

RadioButtonPreference 标题与摘要的颜色配置。根据 selected 在基础色与选中色之间切换。

字段类型说明
titleColorMiuixBasicComponentColors未选中标题颜色
selectedTitleColorMiuixBasicComponentColors选中标题颜色
summaryColorMiuixBasicComponentColors未选中摘要颜色
selectedSummaryColorMiuixBasicComponentColors选中摘要颜色
方法签名说明
resolveTitleColorMiuixBasicComponentColors resolveTitleColor(bool selected)selected 为 true 返回 selectedTitleColor,否则返回 titleColor
resolveSummaryColorMiuixBasicComponentColors resolveSummaryColor(bool selected)selected 为 true 返回 selectedSummaryColor,否则返回 summaryColor

MiuixRadioButtonPreferenceDefaults

RadioButtonPreference 的默认值集合。私有构造,仅提供静态方法。

方法签名说明
radioButtonPreferenceColorsMiuixRadioButtonPreferenceColors radioButtonPreferenceColors(BuildContext context)标题与摘要的默认颜色:未选中标题取 onBackground、未选中摘要取 onSurfaceVariantSummary,选中态均取 primary;禁用色统一为 disabledOnSecondaryVariant

MiuixSliderPreference

带滑块的偏好设置行,MiuixSlider 放在底部区域;末尾可显示 valueTextonClick 非空时追加右箭头图标。断言 steps >= 0min < max

参数类型默认值说明
valuedouble必填当前滑块值,会被夹到 min..max
onValueChangeValueChanged<double>必填值变更回调
titleString?null行标题
titleColorMiuixBasicComponentColors?null标题颜色,null 取默认
summaryString?null行摘要
summaryColorMiuixBasicComponentColors?null摘要颜色,null 取默认
startActionWidget?null起始侧内容
valueTextString?null末尾区域当前值文本
endActionsList<Widget>?nullvalueText 之后的额外内容
bottomActionWidget?null滑块上方的额外内容
onClickVoidCallback?null点击回调,非空时末尾追加右箭头
holdDownStateboolfalse是否处于按压态
enabledbooltrue是否启用
mindouble0.0滑块最小值
maxdouble1.0滑块最大值
stepsint0离散步进数,0 表示连续
onValueChangeFinishedVoidCallback?null值变更结束回调
reverseDirectionboolfalse是否反向(从右向左递增)
sliderHeightdoubleMiuixSliderDefaults.minHeight(28)滑块高度
sliderColorsMiuixSliderColors?null滑块颜色,null 取 MiuixSliderDefaults.sliderColors
hapticEffectMiuixSliderHapticEffectMiuixSliderDefaults.defaultHapticEffectedge触感反馈类型
showKeyPointsboolfalse是否显示关键点
keyPointsList<double>?null自定义关键点,null 时由 steps 推导
magnetThresholddouble0.02磁吸阈值(0..1)
insideMarginEdgeInsetsGeometryMiuixBasicComponentDefaults.insideMargin内边距

示例:

dart
MiuixSliderPreference(
  title: '亮度',
  value: brightness,
  valueText: '${(brightness * 100).round()}%',
  onValueChange: (v) => setState(() => brightness = v),
)

MiuixRangeSliderPreference

带范围滑块的偏好设置行,MiuixRangeSlider 放在底部区域;末尾可显示 valueTextonClick 非空时追加右箭头图标。断言 steps >= 0min < max

参数类型默认值说明
startValuedouble必填起始值,会被夹到 min..max
endValuedouble必填结束值,会被夹到 min..max
onValueChangeValueChanged<(double, double)>必填值变更回调,参数为 (newStart, newEnd)
titleString?null行标题
titleColorMiuixBasicComponentColors?null标题颜色
summaryString?null行摘要
summaryColorMiuixBasicComponentColors?null摘要颜色
startActionWidget?null起始侧内容
valueTextString?null末尾区域当前值文本
endActionsList<Widget>?null末尾区域额外内容
bottomActionWidget?null滑块上方的额外内容
onClickVoidCallback?null点击回调,非空时末尾追加右箭头
holdDownStateboolfalse是否处于按压态
enabledbooltrue是否启用
mindouble0.0滑块最小值
maxdouble1.0滑块最大值
stepsint0离散步进数
onValueChangeFinishedVoidCallback?null值变更结束回调
sliderHeightdoubleMiuixSliderDefaults.minHeight(28)滑块高度
sliderColorsMiuixSliderColors?null滑块颜色
hapticEffectMiuixSliderHapticEffectMiuixSliderDefaults.defaultHapticEffectedge触感反馈类型
showKeyPointsboolfalse是否显示关键点
keyPointsList<double>?null自定义关键点
magnetThresholddouble0.02磁吸阈值
insideMarginEdgeInsetsGeometryMiuixBasicComponentDefaults.insideMargin内边距

示例:

dart
MiuixRangeSliderPreference(
  title: '价格区间',
  startValue: lo,
  endValue: hi,
  onValueChange: (r) => setState(() { lo = r.$1; hi = r.$2; }),
)

MiuixOverlayDropdownPreference

Scaffold 内下拉偏好行,行末显示选中值文本与下拉箭头,点击展开下拉弹窗(在根 Scaffold 内渲染)。默认构造函数接收 items + selectedIndex

参数类型默认值说明
itemsList<String>必填下拉项文本列表
selectedIndexint必填当前选中索引
titleString必填行标题
titleColorMiuixBasicComponentColors?null标题颜色
summaryString?null行摘要
summaryColorMiuixBasicComponentColors?null摘要颜色
dropdownColorsMiuixDropdownColors?null下拉颜色,null 取 MiuixDropdownDefaults.dropdownColors
startActionWidget?null起始侧内容
bottomActionWidget?null底部内容
insideMarginEdgeInsetsGeometryMiuixBasicComponentDefaults.insideMargin内边距
maxHeightdouble?null弹窗最大高度
enabledbooltrue是否启用
showValuebooltrue是否显示选中值文本
renderInRootScaffoldbooltrue是否在根 Scaffold 内渲染弹窗
collapseOnSelectionbool?true选中后是否收起(默认构造函数为 true
onExpandedChangeValueChanged<bool>?null展开状态变更回调
onSelectedIndexChangeValueChanged<int>?null选中索引变更回调

命名构造函数:.entry({required MiuixDropdownEntry entry, ...}) 单分组、.entries({required List<MiuixDropdownEntry> entries, ...}) 多分组;.entriescollapseOnSelection 默认 null(据分组数自动决定),且不接收 onSelectedIndexChange

示例:

dart
MiuixOverlayDropdownPreference(
  title: '语言',
  items: const ['简体中文', 'English'],
  selectedIndex: langIndex,
  onSelectedIndexChange: (i) => setState(() => langIndex = i),
)

MiuixWindowDropdownPreference

窗口级下拉偏好行,行为同 MiuixOverlayDropdownPreference,但弹窗以根 Overlay 渲染,故无 renderInRootScaffold 参数。

参数类型默认值说明
itemsList<String>必填下拉项文本列表
selectedIndexint必填当前选中索引
titleString必填行标题
titleColorMiuixBasicComponentColors?null标题颜色
summaryString?null行摘要
summaryColorMiuixBasicComponentColors?null摘要颜色
dropdownColorsMiuixDropdownColors?null下拉颜色,null 取默认
startActionWidget?null起始侧内容
bottomActionWidget?null底部内容
insideMarginEdgeInsetsGeometryMiuixBasicComponentDefaults.insideMargin内边距
maxHeightdouble?null弹窗最大高度
enabledbooltrue是否启用
showValuebooltrue是否显示选中值文本
collapseOnSelectionbool?true选中后是否收起
onExpandedChangeValueChanged<bool>?null展开状态变更回调
onSelectedIndexChangeValueChanged<int>?null选中索引变更回调

命名构造函数:.entry(单分组)、.entries(多分组,collapseOnSelection 默认 null)。

示例:

dart
MiuixWindowDropdownPreference(
  title: '主题',
  items: const ['浅色', '深色', '跟随系统'],
  selectedIndex: themeIndex,
  onSelectedIndexChange: (i) => setState(() => themeIndex = i),
)

MiuixOverlaySpinnerPreference

Scaffold 内下拉选择偏好行。与 Dropdown 的区别:itemsList<MiuixDropdownItem>(保留 icon/summary 等),且 dialogButtonString 非空时改用对话框模式(否则弹窗模式)。默认构造函数接收 items + selectedIndex

参数类型默认值说明
itemsList<MiuixDropdownItem>必填下拉项列表
selectedIndexint必填当前选中索引
titleString必填行标题
dialogButtonStringString?null非空时使用对话框模式并作为按钮文本
titleColorMiuixBasicComponentColors?null标题颜色
summaryString?null行摘要
summaryColorMiuixBasicComponentColors?null摘要颜色
spinnerColorsMiuixDropdownColors?null颜色,null 时对话框取 dialogDropdownColors、弹窗取 dropdownColors
startActionWidget?null起始侧内容
bottomActionWidget?null底部内容
insideMarginEdgeInsetsGeometryMiuixBasicComponentDefaults.insideMargin内边距
maxHeightdouble?null弹窗最大高度
enabledbooltrue是否启用
showValuebooltrue是否显示选中值文本
renderInRootScaffoldbooltrue是否在根 Scaffold 内渲染
collapseOnSelectionbool?null选中后是否收起
onExpandedChangeValueChanged<bool>?null展开状态变更回调
onSelectedIndexChangeValueChanged<int>?null选中索引变更回调

命名构造函数:.entry(单分组,collapseOnSelection 默认 true)、.entries(多分组,collapseOnSelection 默认 null);二者均不接收 onSelectedIndexChange

示例:

dart
MiuixOverlaySpinnerPreference(
  title: '排序方式',
  items: const [MiuixDropdownItem(text: '按名称'), MiuixDropdownItem(text: '按日期')],
  selectedIndex: sortIndex,
  onSelectedIndexChange: (i) => setState(() => sortIndex = i),
)

MiuixWindowSpinnerPreference

窗口级下拉选择偏好行,行为同 MiuixOverlaySpinnerPreference,但弹窗以根 Overlay 渲染,故无 renderInRootScaffold 参数。

参数类型默认值说明
itemsList<MiuixDropdownItem>必填下拉项列表
selectedIndexint必填当前选中索引
titleString必填行标题
dialogButtonStringString?null非空时使用对话框模式并作为按钮文本
titleColorMiuixBasicComponentColors?null标题颜色
summaryString?null行摘要
summaryColorMiuixBasicComponentColors?null摘要颜色
spinnerColorsMiuixDropdownColors?null颜色,null 时按模式取默认
startActionWidget?null起始侧内容
bottomActionWidget?null底部内容
insideMarginEdgeInsetsGeometryMiuixBasicComponentDefaults.insideMargin内边距
maxHeightdouble?null弹窗最大高度
enabledbooltrue是否启用
showValuebooltrue是否显示选中值文本
collapseOnSelectionbool?null选中后是否收起
onExpandedChangeValueChanged<bool>?null展开状态变更回调
onSelectedIndexChangeValueChanged<int>?null选中索引变更回调

命名构造函数:.entry(单分组,collapseOnSelection 默认 true)、.entries(多分组,默认 null)。

示例:

dart
MiuixWindowSpinnerPreference(
  title: '账户',
  items: const [MiuixDropdownItem(text: '张三'), MiuixDropdownItem(text: '李四')],
  selectedIndex: 0,
  dialogButtonString: '取消',
  onSelectedIndexChange: (i) {},
)

MiuixColorSpace

MiuixColorPicker 使用的色彩空间枚举。

说明
hsv传统 HSV
okhsv基于 OkLab 的 OkHSV,感知均匀性更好
oklabOkLab(明度 + 绿红轴 + 蓝黄轴)
oklchOkLCH(明度 + 色度 + 色相)

MiuixColorPicker

Miuix 风格、支持多色彩空间的滑块取色器,根据 colorSpace 分派到对应子取色器;含 H/S/V(或对应通道)与透明度滑块。

参数类型默认值说明
colorColor必填当前颜色
onColorChangedValueChanged<Color>必填颜色变化回调
showPreviewbooltrue是否显示所选颜色预览条
hapticEffectMiuixSliderHapticEffectMiuixSliderDefaults.defaultHapticEffectedge滑块触感反馈类型
colorSpaceMiuixColorSpaceMiuixColorSpace.hsv使用的色彩空间

枚举 MiuixColorSpacehsv(传统 HSV)、okhsv(基于 OkLab 的 OkHSV,感知均匀性更好)、oklab(明度 + 绿红轴 + 蓝黄轴)、oklch(明度 + 色度 + 色相)。

针对单一色彩空间也提供等价的直接组件(构造参数同上,无 colorSpace):MiuixHsvColorPickerMiuixOkHsvColorPickerMiuixOkLabColorPickerMiuixOkLchColorPicker

示例:

dart
MiuixColorPicker(
  color: current,
  colorSpace: MiuixColorSpace.okhsv,
  onColorChanged: (c) => setState(() => current = c),
)

MiuixHsvColorPicker

HSV 色彩空间的 Miuix 取色器。参数与 MiuixColorPicker 相同,但无 colorSpace 字段,固定使用 HSV 色彩空间。

参数类型默认值说明
colorColor必填当前颜色
onColorChangedValueChanged<Color>必填颜色变化回调
showPreviewbooltrue是否显示所选颜色预览条
hapticEffectMiuixSliderHapticEffectMiuixSliderDefaults.defaultHapticEffectedge滑块触感反馈类型

MiuixOkHsvColorPicker

OkHSV 色彩空间的 Miuix 取色器。参数与 MiuixColorPicker 相同,但无 colorSpace 字段,固定使用 OkHSV 色彩空间(基于 OkLab,感知均匀性更好)。

参数类型默认值说明
colorColor必填当前颜色
onColorChangedValueChanged<Color>必填颜色变化回调
showPreviewbooltrue是否显示所选颜色预览条
hapticEffectMiuixSliderHapticEffectMiuixSliderDefaults.defaultHapticEffectedge滑块触感反馈类型

MiuixOkLabColorPicker

OkLab 色彩空间的 Miuix 取色器。参数与 MiuixColorPicker 相同,但无 colorSpace 字段,固定使用 OkLab 色彩空间(明度 + 绿红轴 + 蓝黄轴)。

参数类型默认值说明
colorColor必填当前颜色
onColorChangedValueChanged<Color>必填颜色变化回调
showPreviewbooltrue是否显示所选颜色预览条
hapticEffectMiuixSliderHapticEffectMiuixSliderDefaults.defaultHapticEffectedge滑块触感反馈类型

MiuixOkLchColorPicker

OkLch 色彩空间的 Miuix 取色器。参数与 MiuixColorPicker 相同,但无 colorSpace 字段,固定使用 OkLch 色彩空间(明度 + 色度 + 色相)。

参数类型默认值说明
colorColor必填当前颜色
onColorChangedValueChanged<Color>必填颜色变化回调
showPreviewbooltrue是否显示所选颜色预览条
hapticEffectMiuixSliderHapticEffectMiuixSliderDefaults.defaultHapticEffectedge滑块触感反馈类型

MiuixColorPalette

Miuix 风格的 HSV 网格调色板,color 外部受控;在网格中按下/拖动或调节透明度时通过 onColorChanged 返回新颜色。默认 7 行、12 个色相列并附加灰阶列。断言 rows > 0hueColumns > 0cornerRadius >= 0indicatorRadius >= 0

参数类型默认值说明
colorColor必填当前颜色
onColorChangedValueChanged<Color>必填选色或调节透明度时调用
rowsintMiuixColorPaletteDefaults.rows(7)色彩网格行数
hueColumnsintMiuixColorPaletteDefaults.hueColumns(12)色相列数
includeGrayColumnboolMiuixColorPaletteDefaults.includeGrayColumn(true)是否在色相列后显示灰阶列
showPreviewboolMiuixColorPaletteDefaults.showPreview(true)是否显示顶部颜色预览
cornerRadiusdoubleMiuixColorPaletteDefaults.cornerRadius(16)网格 squircle 圆角半径
indicatorRadiusdoubleMiuixColorPaletteDefaults.indicatorRadius(10)选中指示器圆环半径

示例:

dart
MiuixColorPalette(
  color: current,
  onColorChanged: (c) => setState(() => current = c),
)

MiuixColorPaletteDefaults

MiuixColorPalette 的默认尺寸与网格参数。私有构造,仅含静态常量。

常量说明
rows7默认色彩行数
hueColumns12默认色相列数
includeGrayColumntrue默认显示灰阶列
showPreviewtrue默认显示颜色预览
cornerRadius16调色板网格默认圆角半径
indicatorRadius10选中指示器默认半径
controlHeight26颜色预览和透明度滑块的高度
paletteHeight180调色板网格高度
spacing12子项之间的垂直间距

Released under the Apache-2.0 License.