gpt4 book ai didi

flutter/ Material 3 : AppBar ignores icon themes

转载 作者:行者123 更新时间:2023-12-05 04:23:45 24 4
gpt4 key购买 nike

在我的 AppBar 中,标题显示为白色文本,但图标是深灰色或其他颜色。我也想让图标变成白色。

但是图标主题中的颜色没有效果!

直接添加到 AppBar 时不是...

Scaffold(
appBar: AppBar(automaticallyImplyLeading: false,
actionsIconTheme: IconThemeData(color: Colors.white),
iconTheme: IconThemeData(color: Colors.white),

而且也不在主题中...

appBarTheme: AppBarTheme(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
actionsIconTheme: IconThemeData(color: Colors.white),
iconTheme: IconThemeData(color: Colors.white),

),

我想让主题正常工作!在图标上单独设置颜色不是一种选择。

我做错了什么?Material 3 真的可以量产了吗?

谢谢!

注意:这是一个 Material 3 问题!在 Material 2 中,一切都按预期工作!

最佳答案

我已经测试了你的代码,它似乎一切正常,你确定你没有为 onPressed 提供 null 吗?这样它可能会被禁用

child: Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
actionsIconTheme: IconThemeData(color: Colors.white),
iconTheme: IconThemeData(color: Colors.white),
title: const Text('Screen A'),
actions: [
IconButton(
icon: Icon(Icons.add),
onPressed: () {},
),
const IconButton(
icon: Icon(Icons.add),
onPressed: null,
)
],
),

enter image description here

@编辑

在 material3 中也有效 - 你确定你没有覆盖图标的主题吗?

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
useMaterial3: true,
primarySwatch: Colors.blue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
actionsIconTheme: IconThemeData(color: Colors.white),
iconTheme: IconThemeData(color: Colors.white),
title: const Text('Screen A'),
actions: [
IconButton(
icon: Icon(Icons.add),
onPressed: () {},
),
const IconButton(
icon: Icon(Icons.add),
onPressed: null,
)
],
),
),
);
}
}

enter image description here

更新:

你是对的 - 它不能正常工作:

根据 documentation IconButton 的 Material3 正在为 Flutter 开发

关于 flutter/ Material 3 : AppBar ignores icon themes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73658347/

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