Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 无法在标题文本小部件上应用AppBar titleTextStyle_Flutter_Dart_Appbar - Fatal编程技术网

Flutter 无法在标题文本小部件上应用AppBar titleTextStyle

Flutter 无法在标题文本小部件上应用AppBar titleTextStyle,flutter,dart,appbar,Flutter,Dart,Appbar,我无法使用AppBar titleTextStyle更改AppBar标题文本颜色。 我知道我可以通过一些方式设置AppBar标题样式,比如在textWidget中使用样式或在AppBar中设置textTheme,但我只想知道为什么不能通过设置titleTextStyle来更改它 代码如下。虽然设置了titleTextStyle和foregroundColor,但AppBar标题仍然为白色 class MyStatelessWidget extends StatelessWidget { co

我无法使用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'),
      ),
    );
  }
}

我认为你需要删除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'),
      ),
    );
  }

我认为你需要删除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'),
      ),
    );
  }

如果您只想更改AppBar标题文本颜色,则这可能会帮助您:

appBar: AppBar(
        title: Text(
          'To Do List',
          style: TextStyle(color: Colors.black),
        ),
      ),


如果您只想更改AppBar标题文本的颜色,那么这可能会帮助您:

appBar: AppBar(
        title: Text(
          'To Do List',
          style: TextStyle(color: Colors.black),
        ),
      ),


我知道这个问题是一个月前提的,但这个问题的答案是:

使用
backwards兼容性:false,
用于
AppBarTheme

appBarTheme:appBarTheme(
后向兼容性:false,
titleTextStyle:TextStyle(
颜色:颜色,红色,
),
),
或者另一种方式:

appBarTheme:appBarTheme(
textTheme:textTheme(
标题6:文本样式(
颜色:颜色,红色,
)
)
),

我知道这个问题是一个月前提的,但这个问题的答案是:

使用
backwards兼容性:false,
用于
AppBarTheme

appBarTheme:appBarTheme(
后向兼容性:false,
titleTextStyle:TextStyle(
颜色:颜色,红色,
),
),
或者另一种方式:

appBarTheme:appBarTheme(
textTheme:textTheme(
标题6:文本样式(
颜色:颜色,红色,
)
)
),

您的代码在
标题中有一个额外的逗号,它无法编译,这可能是您的更改无法生效的原因我很抱歉没有设置格式并且不容易阅读,但我认为逗号不是额外的。您的代码在
标题中有一个额外的逗号,它无法编译,可能是您的更改没有生效的原因我很抱歉没有设置格式,也不容易阅读,但我认为逗号不是多余的。谢谢,但至少对我来说不起作用。TitleExtStyle是一个新道具。要使其工作,您需要将backwardsCompatibility设置为false,以便它使用新的道具。请看@DJafari的回答谢谢,但至少对我来说不起作用。titleTextStyle是一个新道具。要使其工作,您需要将backwardsCompatibility设置为false,以便它使用新的道具。请参阅@DJafari的回答谢谢“BackardsCompatibility:false”。如中所述:“鼓励应用程序开发人员选择新功能,将其设置为false,并根据需要使用foregroundColor和SystemOverlyStyle属性。AppBar.textTheme已过时”。顺便说一下,如果您只想更改文本颜色,foregroundColor就足够了,不需要titleTextStyle。感谢“Backwards兼容性:false”。如中所述:“鼓励应用程序开发人员选择新功能,将其设置为false,并根据需要使用foregroundColor和SystemOverlyStyle属性。AppBar.textTheme已过时”。顺便说一下,如果您只想更改文本颜色,foregroundColor就足够了,titleTextStyle就不需要了。