Nov*_*evi 13 dart flutter flutter-layout
因此,在我的 flutter 应用程序中,我创建 TextFormField 用作输入,如下所示(并将其返回到脚手架中):
final password = TextFormField(
controller: passController,
autofocus: false,
obscureText: true,
decoration: InputDecoration(hintText: 'Password'),
style: new TextStyle(color: Colors.orange),
);
Run Code Online (Sandbox Code Playgroud)
我想更改stylea 内的属性themeData,但找不到要指定的属性。
我能找到的最接近的一个是textTheme: new TextTheme(body1: new TextStyle(color: Colors.orange)),但是这个对我的 TextFormField 没有任何作用。
如何设置 TextFormField 样式?请帮忙,我对 Dart 和编程都很陌生。我现在 13 岁,没有人能帮我解决这些事情。
PS:如果需要,完整的代码位于 GitHub 上: https: //github.com/Legolaszstudio/novynotifier
Bli*_*Dev 11
更新:
如果您想按 Flutter 应用程序的主题更改 TextField 中的文本。现在是 TextTheme 的 subtitle1。
textTheme: TextTheme(
subtitle1: TextStyle(color: Colors.blue),
)
Run Code Online (Sandbox Code Playgroud)
嗯!这是一个很长的问题。TextFormField是 的子类TextField。默认样式为TextField可以从下面的源中找到。
final TextStyle style = themeData.textTheme.subhead.merge(widget.style);\nRun Code Online (Sandbox Code Playgroud)\n\n因此,您的源代码有两种解决方案。
\n\nstyle属性输入到password.final password = TextFormField(\n controller: passController,\n autofocus: false,\n obscureText: true,\n decoration: InputDecoration(hintText: 'Password'),\n style: new TextStyle(color: Colors.orange), // \xe2\x98\x85 => Delete this.\n);\nRun Code Online (Sandbox Code Playgroud)\n\nsubhead样式DataTheme样式并将其输入到其中。MaterialApp(\n theme: ThemeData(\n textTheme: TextTheme(\n subhead: TextStyle(color: Colors.orange),\n ),\n ),\n home: null,\n)\nRun Code Online (Sandbox Code Playgroud)\n\nsubhead样式DataTheme样式并将其输入到其中。MaterialApp(\n theme: ThemeData(\n textTheme: TextTheme(\n subhead: TextStyle(color: Colors.orange),\n ),\n ),\n home: null,\n)\nRun Code Online (Sandbox Code Playgroud)\n\npasswordfinal themes = Theme.of(context);\nfinal password = TextFormField(\n controller: passController,\n autofocus: false,\n obscureText: true,\n decoration: InputDecoration(hintText: 'Password'),\n style: themes.textTheme.subhead, // \xe2\x98\x85 => Update this.\n);\nRun Code Online (Sandbox Code Playgroud)\n
排版的 Material 规范在2021 年发生了显着变化,现在使用显示、标题、标题、正文和标签类型。titleMedium 会影响所有 TextFields 和 TextFormFields。
TextTheme 类文档中也强调了这一事实。
如果您将 titleMedium TextStyle 用于其他用途,您可以轻松地将 TextFields 和 TextFormFields 包装在主题小部件中,并专门为这些小部件更新此样式,如下所示:
Theme(
data: Theme.of(context).copyWith(
textTheme: Theme.of(context).textTheme.copyWith(
titleMedium: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w300,
),
)),
child: TextField()
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12119 次 |
| 最近记录: |