gpt4 book ai didi

flutter - 有没有办法为输入装饰前缀图标设置主题?

转载 作者:行者123 更新时间:2023-12-03 02:42:31 24 4
gpt4 key购买 nike

我有一个带有前缀 Icon 的输入字段,但我似乎无法弄清楚如何在未选择该字段时设置主题。这是未选中时的样子

enter image description here

如您所见,图标具有深色,而它应该具有边框的浅色。当我选择该字段时,我得到了这个

enter image description here

哪个好得多,因为现在我实际上可以看到图标了。文档说

The size and color of the prefix icon is configured automatically using an [IconTheme] and therefore does not need to be explicitly given in the icon widget.

但是当我设置图标主题时
iconTheme: IconThemeData(color: _primaryColorLight),
primaryIconTheme: IconThemeData(color: _primaryColorLight),
accentIconTheme: IconThemeData(color: _primaryColorLight),

没有什么改变?
  Widget _buildNameField(BuildContext context) {
final ThemeData theme = Theme.of(context);
return TextFormField(
onSaved: (String value) => _phoneNumber = value,
keyboardType: TextInputType.text,
style: theme.textTheme.body1,
decoration: InputDecoration(
prefixIcon: Icon(Icons.person),
hintText: 'Name',
),
validator: (String value) {
if (value.isEmpty || value.length < 2) return 'Please enter a name with two letters or more';
},
);
}

那是我的名字字段。现在我当然可以给图标一个颜色。但我碰巧使用了一个包,它有一个选择菜单,它也使用 TextFormField 并且也面临同样的问题。所以我当然可以 fork 那个 repo 并更改那里的图标颜色。但这似乎很费力,而且相当笨拙。

那么如何设置主题呢?

编辑

文档说 TextFormField 的前缀图标主题来自 IconTheme。
return IconTheme(
data: theme.iconTheme,
child: ListTileTheme(
iconColor: theme.iconTheme.color,
child: MaterialApp(
home: TheRootPage(),
theme: theme,
debugShowCheckedModeBanner: false,
),
),
);

这适用于 ListTileTheme 但不适用于 IconTheme 为什么会这样?

最佳答案

答案是将其添加到您的主题数据 brightness: Brightness.dark,brightness: Brightness.light,取决于你的背景颜色。

关于flutter - 有没有办法为输入装饰前缀图标设置主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61611987/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com