Flutter 下拉列表模型
特点
灵活的下拉列表模型,使用简单的模型列表,易于使用和自定义。
## 安装
- 将最新版本的包添加到您的 pubspec.yaml 文件中(并执行 dart pub get)
dart
dependencies:
flutter:
sdk: flutter
dropdown_model_list: any
- 导入包并在您的应用中使用它。
用法示例
import 'package:dropdown_model_list/dropdown_model_list.dart';
简短示例
SelectDropList(
itemSelected:optionItemSelected,
dropListModel:dropListModel,
showIcon: true, // Show Icon in DropDown Title
showArrowIcon: true, // Show Arrow Icon in DropDown
showBorder: true,
paddingTop: 0,
icon: const Icon(Icons.person,color: Colors.black),
onOptionSelected:(optionItem){
optionItemSelected = optionItem;
setState(() {});
},
)
示例
import 'package:dropdown_model_list/dropdown_model_list.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'DropDown Menu',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'DropDown Menu'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
DropListModel dropListModel = DropListModel([
OptionItem(id: "1", title: "Jatin Sharma"),
OptionItem(id: "2", title: "Puneet Chand"),
OptionItem(id: "3", title: "Vikas Bhardwaj"),
OptionItem(id: "4", title: "Rakesh Kumar"),
OptionItem(id: "5", title: "Nitish Kumar")
]);
OptionItem optionItemSelected = OptionItem(title: "Select User");
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Padding(
padding: const EdgeInsets.only(top: 20),
child: Column(
children: <Widget>[
SelectDropList(
itemSelected:optionItemSelected,
dropListModel:dropListModel,
showIcon: true, // Show Icon in DropDown Title
showArrowIcon: true, // Show Arrow Icon in DropDown
showBorder: true,
paddingTop: 0,
icon: const Icon(Icons.person,color: Colors.black),
onOptionSelected:(optionItem){
optionItemSelected = optionItem;
setState(() {});
},
)
],
),
),
);
}
}
贡献
欢迎 Pull requests。对于重大更改,请先打开一个 issue 来讨论您想进行的更改。

