基本属性

  1. DropdownButton({
  2. Key key,
  3. @required this.items, // 每一项的数据列
  4. this.selectedItemBuilder,
  5. this.value, // 显示信息内容
  6. this.hint, // 默认提示文本 当value = null时。
  7. this.disabledHint, // 禁用状态下的提示文本【没有onChanged事件】
  8. @required this.onChanged, // 选择的时候触发。
  9. this.onTap, // 点击的时候触发。
  10. this.elevation = 8,
  11. this.style,
  12. this.underline, // 下划线
  13. this.icon, // 下拉的图标
  14. this.iconDisabledColor,
  15. this.iconEnabledColor,
  16. this.iconSize = 24.0, // 图标大小
  17. this.isDense = false,
  18. this.isExpanded = false,
  19. this.itemHeight = kMinInteractiveDimension,
  20. this.focusColor, //
  21. this.focusNode, //
  22. this.autofocus = false,
  23. this.dropdownColor, // 点击后背景色。
  24. })

写了备注的都是我本人觉得比较用的上的。

基本用法

默认提示 && 禁用提示

  1. DropdownButton(
  2. value: _DropdownButtonValue, // 显示信息内容
  3. hint: Text('请选择具体项!'), // 默认提示文本
  4. disabledHint : Text("你无选择权!"), // 禁用状态下的提示文本【没有onChanged事件】
  5. style: TextStyle(
  6. fontFamily: "",
  7. color: Color(0xff333333),
  8. ),
  9. items: [ // 每一项的数据列
  10. DropdownMenuItem(
  11. child: Text("托尼", style: TextStyle(fontSize: 22.0 , fontWeight: FontWeight.w400 ) ), // 展示给用户看的信息。
  12. value:"乔巴" , // 匹配显示信息 输出信息
  13. onTap: (){
  14. print("乔巴被点击了,即将死亡!");
  15. },
  16. ),
  17. DropdownMenuItem(child: Text("娜美",
  18. style: TextStyle(
  19. inherit: false,
  20. fontSize: 22.0 ,
  21. fontWeight: FontWeight.w400
  22. )
  23. ),
  24. value:"娜美" ),
  25. DropdownMenuItem(child: Text("布鲁克",softWrap : false , style: TextStyle(fontSize: 22.0 , fontWeight: FontWeight.w400 )), value:"布鲁克" ),
  26. DropdownMenuItem(child: Text("路飞", style: TextStyle(fontSize: 22.0 , fontWeight: FontWeight.w400 )), value:"路飞" ),
  27. DropdownMenuItem(child: Text("索隆", style: TextStyle(fontSize: 22.0 , fontWeight: FontWeight.w400 )), value:"索隆" ),
  28. ],
  29. onTap: (){ // 点击的时候触发。
  30. print("123456123456");
  31. },
  32. onChanged: (e){ // 选择的时候触发。
  33. setState(() {
  34. _DropdownButtonValue = e;
  35. print(_DropdownButtonValue);
  36. });
  37. },
  38. ),

image.pngimage.pngimage.png

添加下划线

image.png

更改下拉箭头Icon

image.png

更改下拉背景色

image.png
这里会发现,娜美的字体颜色是白色的,是因为在Text()中将字体的继承关系取消了,所以是默认字体颜色【white】。

其余的属性看上面的属性描述。