简体   繁体   English

如何获得未来的权利<either<error, list<dynamic> &gt;&gt; 在 Flutter? </either<error,>

[英]How to get Right of Future<Either<Error, List<dynamic>>> in Flutter?

I fetch data with code as below:我使用以下代码获取数据:

Future<Either<ResponseError, List<dynamic>>> _getResult(url) {
  return  RequestApi(url).fetchList();
}

I want to get List and use it to do something else, I knew how to use FutureBuilder to build Widget, but I want to try to use use Future, what can I do to get Right of Either?我想获取 List 并用它来做其他事情,我知道如何使用 FutureBuilder 来构建 Widget,但我想尝试使用 Future,我该怎么做才能获得 Right of Either? I tried我试过了

I personally use a try catch and return left or right我个人使用 try catch 并返回左或右

Future<Either<List<dynamic>>, Exception> _getResult(url) async {
 try {
      final response = await http.post(url);
      if (response == null) throw ResponseNullException();
      return Left(response.asList());
    } catch (e, s) {
      return Right(e);
    }
}

暂无
暂无

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

相关问题 Flutter:未来出错<list<dynamic> > 类型</list<dynamic> - Flutter: Error in Future<List<dynamic>> type Flutter:隔离Future的右手<either></either> - Flutter : isolate the right hand of Future<Either> Dartz,颤振测试 - 无法获得未来的正确部分<Either<L, R> &gt;,而不是那个 - Future 的实例<Either<L, R> &gt; 作为实际结果 - Dartz, flutter test - Can't get a Right part of Future<Either<L, R>>, instead of that - instance of Future<Either<L, R>> as a actual result 错误:输入“未来”<dynamic> ' 不是类型 'List 的子类型<dynamic> '。 Flutter</dynamic></dynamic> - error : type 'Future<dynamic>' is not a subtype of type 'List<dynamic>'. Flutter 如何从 Future 获取值<list>在 Flutter</list> - How to get values from Future<List> in Flutter Flutter错误:输入&#39;Future <dynamic> &#39;不是&#39;List类型的子类型 <Game> “ - Flutter Error: type 'Future<dynamic>' is not a subtype of type 'List<Game>' “未来”的实例<dynamic> ' flutter 错误</dynamic> - Instance of 'Future<dynamic>' flutter error 如何摆脱“未来”的实例<dynamic> &#39; 在颤振/飞镖中? - how to get rid of Instance of 'Future<dynamic>' in Flutter/dart? 如何获取“未来”实例中的值<Response<dynamic> ?&gt;&#39; 在颤振中? - how to get the values inside Instance of 'Future<Response<dynamic>?>' in Flutter? 颤动我将如何获得未来<List<Placemark> &gt; 到<List<Placemark> ? - Flutter how I will get Future<List<Placemark>> to <List<Placemark>?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM