![](/img/trans.png)
[英]How to write tests for Either<> from dartz package in flutter
[英]Fix Dartz package with non nullable
我將我的項目移至 sdk 2.12 並嘗試使用不可為空的廢話更新我的代碼。
現在我不明白如何修復 Dartz package 中的問題......
例子:
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)
有什么問題。
它說:參數類型“對象”不能分配給參數類型“異常*”。
這應該如何解決?
您是否嘗試過使用dartz: ^0.10.0-nullsafety.2
,這是 null 安全的預發布版本。 請在pub.dev上查看最新版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.