[Flutter]AppBarのforegroundColorが機能しない時の解決方法

Flutter

どうも、ちょげ(@chogetarou)です。

AppBarのforegroundColorが機能しない時には、どうしたらいいのでしょうか?

スポンサーリンク

方法

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Sample'),
          foregroundColor: Colors.yellow,
          backwardsCompatibility: false,
        ),
        body: Center());
  }

foregroundColorが機能しない時には、引数「backwardsCompatibility」に「false」を指定します。

foregroundColorが機能しないのは、デフォルトのテキスト設定が使われているからです。

「backwardsCompatibility」は、デフォルトの設定を使うかどうかを指定する引数です。

この引数に「false」を指定することで、デフォルトの設定ではなく、「foregroundColor」の設定を使うようになります。

コメント

タイトルとURLをコピーしました