kos*_*aku 2 appbar dart flutter
我无法使用 AppBar titleTextStyle 更改我的 AppBar 标题文本颜色。我知道我可以通过某些方式设置 AppBar 标题样式,例如在 textWidget 中使用样式或在 AppBar 中设置 textTheme,但我只想知道为什么不能通过设置 titleTextStyle 来更改它。
代码如下。尽管设置了 titleTextStyle 和 foregroundColor,AppBar 标题仍然是白色的。
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
foregroundColor: Colors.black,
titleTextStyle: TextStyle(color: Colors.black),
title: const Text('AppBar Color'),),
body: const Center(
child: Text('sample'),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这个问题是 1 个月前的,但这个问题的答案是:
使用backwardsCompatibility: false,
的AppBarTheme
appBarTheme: AppBarTheme(
backwardsCompatibility: false,
titleTextStyle: TextStyle(
color: Colors.red,
),
),
Run Code Online (Sandbox Code Playgroud)
或另一种方式:
appBarTheme: AppBarTheme(
textTheme: TextTheme(
headline6: TextStyle(
color: Colors.red,
)
)
),
Run Code Online (Sandbox Code Playgroud)
我认为你需要删除标题的 const
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
foregroundColor: Colors.black,
titleTextStyle: TextStyle(color: Colors.black),
title: Text('AppBar Color'),
),
body: const Center(
child: Text('sample'),
),
);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1121 次 |
最近记录: |