【Error Handling】How to Deal with When freezed.dart is Not Generated!

When designing immutable classes using freezed, even if you run “flutter pub run build_runner build –delete-conflicting-outputs” in the terminal, sometimes the ClassName.freezed.dart file is not automatically generated. Here’s how to handle it.

I will introduce the solution I found. I hope it helps you.

When an Error Occurs

If an error occurs when running “flutter pub run build_runner build –delete-conflicting-outputs”, it is easy to identify. Check the error content and remove the cause. Typically, the error location is displayed on the terminal as follows.

Error Information

Clicking on the “package:~dart:24:9” above will take you to the corresponding code.

When No Error Occurs But freezed.dart is Not Generated

When running “flutter pub run build_runner build –delete-conflicting-outputs”, sometimes the freezed.dart is not generated even though no error is output.

In my case, even when I created a new class file and executed the command, the file was not generated. The cause was that the cache from the previous command execution remained, and the new class file was not recognized as a target for updating.

In such cases, deleting the cache solved the problem.

Performing Cache Clean

You can clean the cache by executing the following commands in the terminal.

flutter clean
flutter pub run build_runner build --delete-conflicting-outputs

freezed.dart related to the new class file should be generated.

Copied title and URL