Flutter 2 发布后,我将代码迁移到了sdk: '>=2.12.0 <3.0.0',现在所有代码都是“声音零安全”。但是我在使用 mockito 5.0.0 进行单元测试时遇到了错误
例如:
when(mockClient.login(any)).thenThrow(GrpcError.unavailable());
Run Code Online (Sandbox Code Playgroud)
之前还可以,但是现在,编译器在 下显示错误any,表明:
The argument type 'Null' can't be assigned to the parameter type 'LoginRequest'
我从 mockito repo阅读了这个链接,但我希望有一种更简单的方法来编写像以前一样具有“不可为空”参数的方法的测试。
我使用的是 Android Studio 4.1.1,新的“数据库检查器”组件对我的工作至关重要。它适用于 Android Studio 的模拟器,但不适用于 Genymotion,并且不显示任何内容。
我在 Windows10 上使用最新版本的 Genymotion(3.1.2),所有设备图像的 API 级别为 +26(数据库检查器需要)
有没有办法在 Genymotion 中使用“数据库检查器”?
我正在开发一个使用 Grpc 连接到服务器的 flutter 应用程序。有些服务需要额外的元数据进行身份验证,因此我首先想到的是实现一个拦截器以将元数据添加到这些请求中,如下所示:
class MyClientInterceptor implements ClientInterceptor {
@override
ResponseFuture<R> interceptUnary<Q, R>(ClientMethod<Q, R> method, Q request, CallOptions options, invoker) {
var newOptions = CallOptions.from([options])
..metadata.putIfAbsent('token', () => 'Some-Token');
return invoker(method, request, newOptions);
}
}
Run Code Online (Sandbox Code Playgroud)
但我明白了Caught error: Unsupported operation: Cannot modify unmodifiable map,因为 CallOptions 使用不可修改的映射。
第一个问题:向某些请求添加身份验证而不是使用这些元数据创建客户端存根的最佳实践是什么?
第二:如何从选项中复制元数据,修改它并使用修改后的对象?