flutter - 对 DropdownButtons 的项目列表的边缘进行四舍五入
问题描述
如何使包含 DropDownButtonItems 的 DropdownButton 的打开列表的边缘变圆?
这就是我所拥有的:
String selectedValue;
DropdownButtonHideUnderline(
child: DropdownButton<String>(
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18,
color: Colors.black,
),
isExpanded: true,
value: selectedValue, //var that
items: getDropdownItems4(), //simple function that holds the values of all the items
onChanged: (String value) {
setState(() {
selectedValue = value;
});
},
),
),
解决方案
的代码在DropdownButton
这里:https ://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/dropdown.dart
当我们阅读它时,我们发现大部分与组件外观相关的代码都是私有的,并且样式是硬编码在文件中的。
例如,这是定义边界半径的地方:https ://github.com/flutter/flutter/blob/2f993d70c178f4a927da5d7d76bd527115920695/packages/flutter/lib/src/material/dropdown.dart#L49
因此,剩下的唯一选择是复制/粘贴该代码并根据需要编辑样式。
- 将整个“dropdown.dart”文件复制粘贴到项目的“my_dropdown.dart”中。
- 更改文件中的相对导入(请参阅下面的要点)
- 在你想使用组件的地方导入“my_dropdown.dart”并隐藏“官方”组件:
import 'package:flutter/material.dart'
hide DropdownButton, DropdownMenuItem, DropdownButtonHideUnderline;
import 'my_dropdown.dart';
示例要点:https ://gist.github.com/xvrh/29b7ddf5e4dbd47f6382b241c64b8843
请注意,这种技术有很多缺点。您正在向项目中添加 1500 行代码,这些代码将不再由颤振团队维护/更新/测试。
推荐阅读
- android - API 15 (4.04) 蓝牙与 pin 自动配对
- javascript - Webpack 中的第 3 方 Javascript 和 CSS 文件。奇怪的行为
- android - TileOverlay 资源文件的 URL
- c# - 我应该如何在 InputManager 中配置 Sprint?
- java - 嵌套对象的 Java Jackson 反序列化
- json - 使用杰克逊将csv转换为json
- python - Python循环内存泄漏
- datatables - jQuery数据表不显示数据库中的数据
- java - 如何解决java中方法的通用输入参数
- c# - 从 DataTable 到 DataGridView 的字符串:“\n”不被解释为新行