FLOOR 数据库中缺少部分 'Appdatabase.g.dart' flutter

Missing part 'Appdatabase.g.dart' flutter in FLOOR database

我按照 flutter floor 教程做了,这里是我的数据库文件

import 'package:floor/floor.dart';
import 'package:news_app/database/daos/Userdao.dart';
import 'package:news_app/database/entities/User.dart';
part "AppDatabase.g.dart";


@Database(entities: [User], version: 1)
abstract class ApplicationDatabase extends FloorDatabase {
  Userdao get userDao;
}

这是我的dao文件,

import 'package:floor/floor.dart';
import 'package:news_app/database/entities/User.dart';

@dao
abstract class Userdao{

  @Query("select * from table_user")
  Future<List<User>> getUsersList();

  @insert
  Future<void> insertUser(User user);

}

这是我的实体文件,

import 'package:floor/floor.dart';

@Entity(tableName: 'table_user')
class User{

  @PrimaryKey(autoGenerate: true)
  int id;

  String name;

  String password;

  User({this.id,this.name,this.password});

}


dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  fluttertoast: 3.1.3
  shared_preferences: 0.5.6
  retrofit: any
  logger: any
  dio: 3.0.8
  http: 0.12.0+4
  json_serializable: any
  floor: ^0.9.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  retrofit_generator: any
  build_runner: any
  floor_generator: ^0.9.0

每当我尝试 运行 这个命令时 flutter pub 运行 build_runner build 命令我都会得到这个错误

[INFO] Running build... [INFO] 1.7s elapsed, 0/1 actions completed. [WARNING] floor_generator:floor_generator on lib/database/ApplicationDatabase.dart: Missing "part 'ApplicationDatabase.g.dart';".

对于未来的读者,要创建 database.g.dart,您必须在终端中 运行 下面的命令,

flutter packages pub run build_runner build

或自动 运行 它,每当文件更改时,使用

flutter packages pub run build_runner watch

要阅读完整程序,请访问 floor documentation

您是否为数据库使用相同的文件名

喜欢appdatabase.dartappdatabase.g.dart