Dart:'Null'类型不是Mockito中类型'Future<String?>'的子类型
下面的代码曾经在空安全之前工作,但现在我得到“类型 'Null' 不是类型 'Future<String?>' 的子类型”,我完全不知道为什么以及该怎么做。请帮忙,这应该很容易(除了我),因为您只需复制代码并将其作为测试运行即可获得异常:
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
class MockMethodChannel extends Mock implements MethodChannel {}
void main() {
group('all', () {
test('test', () async {
final mockMethodChannel = MockMethodChannel();
when(mockMethodChannel
.invokeMethod<String>("GET com.eight/preference-management/preferences"))
.thenAnswer((_) async => "test");
});
});
}
THE END
二维码