shadcn_ui-select
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseShadcn UI — Select
Shadcn UI — Select
Instructions
使用说明
ShadSelect<T>optionsShadOption<T>PaddingplaceholderselectedOptionBuilder: (context, value) => ...onChangedinitialValueminWidthmaxWidthmaxHeightShadSelectFormField<T>idvalidatorallowDeselection: trueShadSelect<T>optionsShadOption<T>PaddingplaceholderselectedOptionBuilder: (context, value) => ...onChangedinitialValueminWidthmaxWidthmaxHeightidvalidatorShadSelectFormField<T>allowDeselection: trueBasic
基础用法
dart
final fruits = {'apple': 'Apple', 'banana': 'Banana', ...};
ShadSelect<String>(
placeholder: const Text('Select a fruit'),
options: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
child: Text(
'Fruits',
style: theme.textTheme.muted.copyWith(
fontWeight: FontWeight.w600,
color: theme.colorScheme.popoverForeground,
),
textAlign: TextAlign.start,
),
),
...fruits.entries.map((e) => ShadOption(value: e.key, child: Text(e.value))),
],
selectedOptionBuilder: (context, value) => Text(fruits[value]!),
onChanged: print,
)dart
final fruits = {'apple': 'Apple', 'banana': 'Banana', ...};
ShadSelect<String>(
placeholder: const Text('Select a fruit'),
options: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
child: Text(
'Fruits',
style: theme.textTheme.muted.copyWith(
fontWeight: FontWeight.w600,
color: theme.colorScheme.popoverForeground,
),
textAlign: TextAlign.start,
),
),
...fruits.entries.map((e) => ShadOption(value: e.key, child: Text(e.value))),
],
selectedOptionBuilder: (context, value) => Text(fruits[value]!),
onChanged: print,
)Form field
表单字段
dart
ShadSelectFormField<String>(
id: 'email',
minWidth: 350,
initialValue: null,
options: verifiedEmails
.map((email) => ShadOption(value: email, child: Text(email)))
.toList(),
selectedOptionBuilder: (context, value) =>
value == 'none' ? const Text('Select a verified email to display') : Text(value),
placeholder: const Text('Select a verified email to display'),
validator: (v) {
if (v == null) return 'Please select an email to display';
return null;
},
)dart
ShadSelectFormField<String>(
id: 'email',
minWidth: 350,
initialValue: null,
options: verifiedEmails
.map((email) => ShadOption(value: email, child: Text(email)))
.toList(),
selectedOptionBuilder: (context, value) =>
value == 'none' ? const Text('Select a verified email to display') : Text(value),
placeholder: const Text('Select a verified email to display'),
validator: (v) {
if (v == null) return 'Please select an email to display';
return null;
},
)With search
带搜索功能
Use . Pass , , and filter options in state (e.g. wrap options in to avoid focus loss when results change).
ShadSelect.withSearchonSearchChangedsearchPlaceholderOffstage(offstage: !filtered.containsKey(key), child: ShadOption(...))使用。传入、,并在状态中过滤选项(例如,将选项包裹在中,避免结果变化时失去焦点)。
ShadSelect.withSearchonSearchChangedsearchPlaceholderOffstage(offstage: !filtered.containsKey(key), child: ShadOption(...))Multiple
多选功能
Use . Pass , , and optionally , to keep popover open after selection.
ShadSelect.multipleselectedOptionsBuilder: (context, values) => ...onChangedallowDeselection: truecloseOnSelect: false使用。传入、,还可选择设置、,使选中后保持弹出框打开状态。
ShadSelect.multipleselectedOptionsBuilder: (context, values) => ...onChangedallowDeselection: truecloseOnSelect: falseAdditional resources
额外资源
Scrollable option lists (grouped sections) and full search/multiple examples: reference.md.
可滚动选项列表(分组分段)以及完整的搜索/多选示例:reference.md。