Flutter – Evaluation of this constant expression throws an exception.

今回は、以下のエラーの解処方法についてメモしていきたいと思います。

エラー内容

Evaluation of this constant expression throws an exception.

この定数式の評価は例外をスローします??

 Padding(
     padding: const EdgeInsets.only(top: 100.0),
     child: const Center(
          child: Location(location: weather.location),
      ), // Center
), // Padding

Location(location: weather.location)でエラーが発生します。

対処法

 Padding(
     padding: const EdgeInsets.only(top: 100.0),
     child: const Center(
          child: Location(location: weather.location),
      ), // Center
), // Padding

取り消し線が引かれているconstを削除することで解処できまして。

子Widgetで使用されている「weather.location」がRuntime時に決まらないのに親WidgetがRuntime時に決まるconstを使用しているからエラーが発生したと考えられます。

「Flutter – Evaluation of this constant expression throws an exception.」への1件のフィードバック

아크몬드 への返信 コメントをキャンセル