我的 Flutter 应用程序的主题在 TextFields 周围添加边框:
ThemeData(
...
inputDecorationTheme: InputDecorationTheme(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1.0),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1.0),
),
)
Run Code Online (Sandbox Code Playgroud)
但是,我确实有一个不需要边框的 TextField,因此我尝试覆盖 TextField 中的边框:
TextField(
decoration: InputDecoration.collapsed(
hintText: _hintText,
border: InputBorder.none,
),
controller: _textController,
),
Run Code Online (Sandbox Code Playgroud)
但我仍然得到边界?下面是部分图像。“请输入!” 字段使用主题默认值,“问题”字段是我试图覆盖的字段。
小智 9
用主题小部件包装要覆盖的小部件,并为数据属性放置一个新的 ThemeData 小部件。
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.orange,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Scaffold(
body: Column(children: [
TextFormField(), // Takes the theme of the overall MaterialApp
Theme(
data: ThemeData(
primarySwatch: Colors.blue,
),
child: TextFormField(), // Takes the theme of its direct parent
),
]),
),
);
Run Code Online (Sandbox Code Playgroud)
这个基本示例只是更改颜色,因此请使用您喜欢的任何 ThemeData。
| 归档时间: |
|
| 查看次数: |
2028 次 |
| 最近记录: |