下拉数据
描述
下拉式数据列表,允许进行单选或多选,并可在数据或标识符中进行搜索。
? 安装
要使用此插件,请将 drop_down_data 添加为 pubspec.yaml 文件中的依赖项。以下步骤将帮助您将此库添加为 Flutter 项目的依赖项。
- 运行
flutter pub add drop_down_data,或手动将 video_editor 添加到pubspec.yaml文件中。
dependencies:
drop_down_data: ^1.0.3
- 在您的代码中导入包
import 'package:drop_down_data/drop_down_data.dart';
? 截图
| 示例 | 视频 |
|---|---|
![]() |
![]() |
? 用法
List<DataDropDown> listData = [];
@override
void initState() {
super.initState();
List<Map<String, dynamic>> listMap = [];
listMap.add({"id": "1", "name": "agenda"});
listMap.add({"id": "2", "name": "contact"});
listData = List<DataDropDown>.from(listMap.map((model) => DataDropDown.fromJson(model)));
}
@override
Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
TextTheme textTheme = theme.textTheme;
ColorScheme colorScheme = theme.colorScheme;
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Selection", style: textTheme.bodyLarge!.copyWith(color: colorScheme.onSurface),),
Text("selectionID: $selectionID"),
Text("selectionValue: $selectionValue"),
DropDownData(
tooltip: "show menu",
title: selectionValue != "" ? " " : "selection",
value: selectionValue,
uuidValue: selectionID,
addFirstEmpty: true,
viewNumber: true,
research: false,
researchCallback: (String val) { setState(() {}); },
listData: listData,
selectionCallback: (DataDropDown selection){
if (kDebugMode) {
print(selection);
print(selection.id);
print(selection.name);
}
selectionValue = selection.name ?? "";
selectionID = selection.id ?? "";
setState(() { });
}),
],
),
),
);
}
✨ 致谢
由 Aylicrea seel-channel 创建。

