Home > Software design >  Dart & Freezed - not generating file
Dart & Freezed - not generating file

Time:04-11

I have freezed_classes.dart :

import 'package:meta/meta.dart';
import 'package:freezed/builder.dart';
part 'freezed_classes.freezed.dart';


@immutable
abstract class User with _$User {
  const factory User(int id, String firstName, String lastName, int age,
      int phoneNumber, String email, String country) = _User;
}

and when im doing pub run build_runner build it not build freezed_classes.freezed.dart file

[INFO] Generating build script completed, took 515ms
[INFO] Reading cached asset graph completed, took 62ms
[INFO] Checking for updates since last build completed, took 569ms
[INFO] Running build completed, took 8.3s
[INFO] Caching finalized dependency graph completed, took 28ms
[INFO] Succeeded after 8.3s with 0 outputs (3 actions)

I was trying every thing i found in the google. Deleting pubspec.lock and creating new, moving to freezed_classes to lib folder etc. nothing work for me. Have u ever have the same problem?

CodePudding user response:

You need to mark the class with the @freezed annotation in order for the build_runner to generate the freezed file.

import 'package:freezed_annotation/freezed_annotation.dart';

part 'freezed_classes.freezed.dart';

@freezed
abstract class User with _$User {
  const factory User(
    int id,
    String firstName,
    String lastName,
    int age,
    int phoneNumber,
    String email,
    String country,
  ) = _User;
}
  • Related