flutter 我想更改``` titleTextStyle的颜色:Theme.of(context).textTheme.titleLarge

r8xiu3jd  于 2023-05-19  发布在  Flutter
关注(0)|答案(2)|浏览(212)

我想设置文本样式使用titleTextStyle: Theme.of(context).textTheme.titleLarge,在我的应用程序栏,但我需要改变de颜色,我现在不知道怎么做。

gopyfrb3

gopyfrb31#

基本上,您堆叠Theme.of(context)copyWith方法,每次进行一次更改。如果你有很多事情要改变,这可能会变得非常冗长。例如,要使titleLarge具有错误颜色

Text(
    'ERROR',
         style: Theme.of(context).textTheme.titleLarge?.copyWith(
         color: Theme.of(context).colorScheme.error),
    )
xtupzzrd

xtupzzrd2#

你可以这样做,更多关于design/themes

Widget build(BuildContext context) {
  return MaterialApp(
    theme: Theme.of(context).copyWith(
        appBarTheme: Theme.of(context).appBarTheme.copyWith(
          backgroundColor: Colors.yellow,// appBar background color
              titleTextStyle: TextStyle(
                color: Colors.red,
              ),
            )),
    home: ... (),
  );
}

相关问题