10

我使用Hive Packages,我在我的项目中实现模块化。首先我network使用运行命令创建具有名称的包flutter create --template=package network,我引用了这个

这个包包括我的项目模型。之后我创建模型用户,然后运行命令构建模型flutter packages pub run build_runner build --delete-conflicting-outputs

import 'package:hive/hive.dart';

part 'user_model_hive.g.dart';

@HiveType()
class UserModelHive extends HiveObject {
  @HiveField(0) 
  DateTime id;
  @HiveField(1)
  String giverName;
  @HiveField(2)
  String pinCodeNumber;

  UserModelHive({this.id, this.giverName, this.pinCodeNumber});
}

但我得到这样的错误

Could not find package "build_runner". Did you forget to add a dependency? pub finished with exit code 65

我确定已经包含build_runner在我的包裹network中。

发布规范.yaml

name: network
description: A new Flutter package project.
version: 0.0.1
author:
homepage:

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  hive: ^1.1.1
  hive_flutter: ^0.2.1
dev_dependencies:
  flutter_test:
    sdk: flutter
  hive_generator: ^0.5.2
  build_runner: ^1.7.2

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:
  # To add assets to your package, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg
  #
  # For details regarding assets in packages, see
  # https://flutter.dev/assets-and-images/#from-packages
  #
  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.
  # To add custom fonts to your package, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts in packages, see
  # https://flutter.dev/custom-fonts/#from-packages

我已经在使用此命令,但没有任何反应: flutter packages get&flutter pub get

如果需要,这是我的结构文件夹。 我的结构文件夹

4

4 回答 4

10

我也遇到了同样的错误。我已经通过在 pubspec.yaml 文件中的 dev_depndencies 中添加 build_runner 来解决它,例如 -

dev_dependencies:

build_runner:^1.3.1

mobx_codegen: ^0.3.9

于 2021-02-08T11:34:16.967 回答
2

你可以试试下面的代码:

flutter packages pub run build_runner build
于 2021-09-09T04:47:14.010 回答
0

我遇到过这个问题

我更改了我的模型类 @HiveType() 注释

@HiveType(0) 

就像那样。问题解决了。

(我在这里为面临这个问题的未来开发人员发帖)

于 2021-04-12T11:58:30.377 回答
0

正如评论中共享的 GitHub 问题中所述,该问题是由从不同目录运行应用程序引起的。在这种情况下,该应用程序在发布的问题中以 root 身份运行。通过从 运行应用程序已解决该问题/network

于 2020-12-21T19:57:43.987 回答