简体   繁体   English

修复 Dartz package 不可为空

[英]Fix Dartz package with non nullable

I moved my project to the sdk 2.12 and trying to update my code with the non-nullable crap.我将我的项目移至 sdk 2.12 并尝试使用不可为空的废话更新我的代码。

Now I don't understand how to fix things in Dartz package...现在我不明白如何修复 Dartz package 中的问题......

Example:例子:

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
    }
  }
}

I'm forced to make a nullable response and then I don't know what is wrong with the catch(error) .我被迫做出可以为空的响应,然后我不知道catch(error)有什么问题。

It says: The argument type 'Object' can't be assigned to the parameter type 'Exception*'.它说:参数类型“对象”不能分配给参数类型“异常*”。

How this should be fixed?这应该如何解决?

Have you tried using dartz: ^0.10.0-nullsafety.2 , which is the pre-release version for null safety.您是否尝试过使用dartz: ^0.10.0-nullsafety.2 ,这是 null 安全的预发布版本。 Please check for the latest version on pub.dev .请在pub.dev上查看最新版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM