颤动停泊:添加停泊文件以制作索引时出错

Flutter moor: Got error when adding moor file to make index

我正在尝试在我的应用程序中使用 flutter moor。所以在创建一个列之后:

import 'package:moor_flutter/moor_flutter.dart';

@DataClassName("LocationTable")
class LocationTables extends Table {
  TextColumn get locationUuid => text()();
  RealColumn get latitude => real()();

现在我想将 locationUuid 作为索引。所以根据它 official site 我创建了一个停泊文件来添加索引:

CREATE INDEX location_uuid_index ON LocationTables (locationUuid);

之后我在 db calss 中添加了这个文件:

@UseMoor(include: {
  'index.moor'
}, tables: [
  UserTables,
  LocationTables,
], daos: [
  UserDao,

])
class Database extends _$Database {

但是在 运行 构建之后 运行ner:

pub run build_runner build --delete-conflicting-outputs

我收到这个错误:

[WARNING] moor_generator:moor_generator on lib/database/database.dart:
line 3, column 37: Target table LocationTables could not be found.
  ╷
3 │ CREATE INDEX location_uuid_index ON LocationTables (locationUuid);

我找到了解决办法。我回答是为了帮助别人:

在停泊文件中,我必须这样写 table 名称:

CREATE INDEX location_uuid_index ON location_tables (location_uuid);

然后 build runner 就成功了。

并在 database.g.dart 中添加:

abstract class _$Database extends GeneratedDatabase {
  _$Database(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e);
  $LocationTablesTable _locationTables;
  $LocationTablesTable get locationTables =>
      _locationTables ??= $LocationTablesTable(this);
  Index _locationUuidIndex;
  Index get locationUuidIndex => _locationUuidIndex ??= Index(
      'location_uuid_index',
      'CREATE INDEX location_uuid_index ON location_tables (locationUuid);');

关注:

  • location_tables

  • location_uuid