gpt4 book ai didi

dart - Flutter 测试 MissingPluginException

转载 作者:IT老高 更新时间:2023-10-28 12:33:50 26 4
gpt4 key购买 nike

运行依赖于 SharedPreferences 插件的测试总是会导致

MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)

我的 pubspec.yaml

dev_dependencies:
flutter_test:
sdk: flutter

dependencies:
flutter:
sdk: flutter
shared_preferences: 0.2.3

的代码在应用程序本身中运行良好。为了运行使用插件的测试,我是否遗漏了一些我需要做的事情?

最佳答案

如果您使用的是 shared_preferences 0.2.4 及更高版本,请使用 setMockInitialValues:

SharedPreferences.setMockInitialValues({}); // set initial values here if desired

对于早期版本,您可以手动完成:

const MethodChannel('plugins.flutter.io/shared_preferences')
.setMockMethodCallHandler((MethodCall methodCall) async {
if (methodCall.method == 'getAll') {
return <String, dynamic>{}; // set initial values here if desired
}
return null;
});

关于dart - Flutter 测试 MissingPluginException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44357053/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com