我对颤振很陌生,所以如果有人需要更多信息,请告诉我。我一直在尝试将 Hive 与我的颤振应用程序一起使用。我想为我编写的名为 Product 的类生成一个自定义适配器。当我运行“flutter packages pub run build_runner build”时,这是我得到的输出:
NoSuchMethodError: The getter 'element' was called on null.
Receiver: null
Tried calling: element
[SEVERE] hive_generator:hive_generator on lib/Pages/Content Cards/productCard.dart:
NoSuchMethodError: The getter 'element' was called on null.
Receiver: null
Tried calling: element
[SEVERE] hive_generator:hive_generator on lib/Pages/Content Cards/featuredCard.dart:
NoSuchMethodError: The getter 'element' was called on null.
Receiver: null
Tried calling: element
[INFO] 19.8s elapsed, 5/14 actions completed.
[WARNING] hive_generator:hive_generator on lib/Models/product.dart:
Missing "part 'product.g.dart';".
[INFO] Running build completed, took 20.2s
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 42ms
[SEVERE] Failed after 20.2s
pub finished with exit code 1
这是产品类:https ://pastebin.com/0a0W18ep
这是 productCard.dart:https ://pastebin.com/gV7kP2YG
这是featuredCard.dart:https ://pastebin.com/7tke6V17
这是我的 pubsec.yaml 的相关部分:
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.3
http: ^0.12.2
hive: ^1.4.4
hive_flutter: ^0.3.1
# For OS-specific directory paths
path_provider: ^1.6.18
dev_dependencies:
build_runner:
flutter_test:
sdk: flutter
hive_generator:
dependency_overrides:
analyzer:
我尝试更改 build_runner 和分析器的版本,并在从中提取值之前检查产品对象是否为空。不幸的是,没有一个工作。