Flutter – freezed利用時にエラー

バグ内容

モデルを定義し以下のコードを書いてbuild_runnerを実行したらコンパイルエラーが出てきました。

part 'todo.g.dart';
Target of URI hasn't been generated: 'todo.g.dart'. Try running the generator that will generate the file referenced by the URI

生成できない??

解決

以下のコマンドを順番に実行する。

flutter pub add json_serializable
flutter pub upgrade
flutter pub upgrade --major-versions
flutter pub run build_runner build --delete-conflicting-outputs

注意点


これを行うと、SlibableListTileがプロジェクト内にある場合は機能しなくなることに注意する注意する必要があるらしい。 flutter_slidableパッケージのバージョン0.6を使用するには、pubspec.yamlを変更する必要があります。 flutter_slidableパッケージのv1.1.0(現在の)バージョンでは、そのバージョンに移行するためにコードを大幅に変更する必要があります。

参考

https://community.flutterflow.io/c/discuss-and-get-help/target-of-uri-hasn-t-been-generated-activities_record-g-dart-try-running-the-generator-that-will-generate-the-file-referenced-by-the-uri

コメントを残す