Dart & Freezed - 不生成文件

Dart & Freezed - not generating file

我有 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;
}

当我在做 pub 时 运行 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)

我正在尝试在 google 中找到的所有东西。删除 pubspec.lock 并创建新的,移动到 freezed_classes 到 lib 文件夹等。对我没有任何作用。你遇到过同样的问题吗?

您需要使用 @freezed 注释标记 class,以便 build_runner 生成 freezed 文件。

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;
}