【Flutter】「The getter ‘buttonColor’ isn’t defined for the type ‘ThemeData’.」の原因と対策

Flutterのエラー「The getter ‘buttonColor’ isn’t defined for the type ‘ThemeData’.」の原因と対策について紹介します。

スポンサーリンク

「The getter ‘buttonColor’ isn’t defined for the type ‘ThemeData’.」の原因と対策

Flutterでデバッグすると以下のエラーが出ました。

The getter 'buttonColor' isn't defined for the type 'ThemeData'. (Documentation)  Try importing the library that defines 'buttonColor', correcting the name to the name of an existing getter, or defining a getter or field named 'buttonColor'.

buttonColorがFlutter v2.3.0 -0.1.pre 以降から非推奨になったことが原因でした。
代わりに「colorScheme.secondary」を使用することでエラーが解消されました。

修正前

Theme.of(context).colorScheme.secondary

修正後

Theme.of(context).accentColor
スポンサーリンク

関連ページ

【Flutter入門】iOS、Android、Windowsアプリ開発
FlutterによるiOS、Android、Windowsアプリ開発について入門者向けに紹介します。
flutter
スポンサーリンク

コメント