Flutter中移除dropdown_dropdown2组件下拉框下划线的方法咨询
你遇到的下划线问题,是因为DropdownButton2继承了原生DropdownButton的默认下划线样式,直接通过以下两种方法就能解决:
方法一:直接设置underline属性为空组件
在你的DropdownButton2组件里添加underline: const SizedBox.shrink(),就能直接去掉下划线:
DropdownButton2<String>( isExpanded: true, // 添加这一行移除下划线 underline: const SizedBox.shrink(), hint: Text( 'Select Item', style: TextStyle( fontSize: 14, color: Theme.of(context).hintColor, ), ), // 其他原有属性保持不变... )
方法二:通过Theme局部覆盖样式
如果你的全局Theme设置了输入框的下划线,也可以用Theme包裹DropdownButton2,局部取消下划线:
Theme( data: Theme.of(context).copyWith( dropdownMenuTheme: DropdownMenuThemeData( inputDecorationTheme: InputDecorationTheme( enabledBorder: InputBorder.none, focusedBorder: InputBorder.none, ), ), ), child: DropdownButton2<String>( // 你的原有代码... ), )
优先用方法一,操作更直接简单,修改后就能看到效果。
内容的提问来源于stack exchange,提问作者Naveen
相关产品推荐
相关产品推荐

