2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Flutter]ThemeDataのprimaryColorが適用されない

2
Posted at

概要

FlutterでThemeDataを利用してアプリのテーマをカスタマイズしたい

課題

ThemeDataのprimaryColorがのpropertyだとAppBarの色が変更されなかった適用されなかった

main.dart
Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primaryColor: Color(0xFF0A0E21),
        scaffoldBackgroundColor: Color(0xFF0A0E21),
      ),
      home: home(),
    );
  }

対策

ThemeDataのcolorSchemeのpropertyを使う

main.dart
Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        colorScheme: ColorScheme.light(
          primary: Color(0xFF0A0E21),
        ),
        scaffoldBackgroundColor: Color(0xFF0A0E21),
      ),
      home: home(),
    );
  }

参考文献

Flutter ThemeData Primary color not changing from theme when trying to add a primary color

最後に

なぜこのような動作になるのかまでは確認できておりません。
そもそもprimaryColorを使うべきではないという話かもしれません。
理由やベストプラクティスをご存じであればコメントいただければ幸いです。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?