我将我的项目移至 sdk 2.12 并尝试使用不可为空的废话更新我的代码。
现在我不明白如何修复 Dartz 包中的东西......
例子:
import 'package:dartz/dartz.dart';
import 'package:mobile_100asa/http.dart';
class StatusApi {
String endpoint = 'https://myApi.net';
Future<Either<Exception, String>?> getStatus() async { // Forced to make nullable response here
try {
var response = await dio.get('$endpoint/test');
return Right(response);
} catch (error) {
print(error);
return (Left(error)); // Error Here
}
}
}
我被迫做出可以为空的响应,然后我不知道catch(error)
.
它说:参数类型“对象”不能分配给参数类型“异常*”。
这应该如何解决?