gpt4 book ai didi

Dart BoundSinkStream 异常

转载 作者:IT王子 更新时间:2023-10-29 07:06:59 27 4
gpt4 key购买 nike

我最近在试验 flutter。试图显示一些数据以测试 flutter 的 ui 概念。但是,每当我想为某事调用 rest 时,它都会返回奇怪的异常(对我来说很难阅读)。

下面是一个示例代码(主要来自 https://flutter.io/networking/ )

 loadData(String url) async {
var uri = Uri.parse(url);
var request = await httpClient.getUrl(uri);
var response = await request.close();
if (response.statusCode == HttpStatus.OK) {
var responseBody = await response.transform(UTF8.decoder).join();

await print(responseBody);
}
}

及其返回的异常:

type '_BoundSinkStream<dynamic, List<int>>' is not a subtype of type '_HttpIncoming' where
_BoundSinkStream is from dart:async
List is from dart:core
int is from dart:core
List is from dart:core
int is from dart:core
_HttpIncoming is from dart:_http
List is from dart:core
int is from dart:core
#0_HttpClientResponse.listen (dart:_http/http_impl.dart:382:23)
#1new _SinkTransformerStreamSubscription (dart:async/stream_transformers.dart:49:16)
#2_BoundSinkStream.listen (dart:async/stream_transformers.dart:185:13)
#3Stream.join (dart:async/stream.dart:741:25)
#4HttpConnector.loadData (package:flutter_app/providers/HttpConnector.dart:26:63)
<asynchronous suspension>
#5WeatherProvider.loadWeather (package:flutter_app/providers/WeatherProvider.dart:12:42)
<asynchronous suspension>
#6 _MyHomePageState._loadData (file:///Users/krzysztofbalana/Private/flutter_app/lib/main.dart:64:21)

最佳答案

根据您构建和获取数据的方式,存在类型不匹配。我创建了一个可以帮助您的虚拟示例:

class FakeApi extends StatelessWidget {
_loadData() async{
String url = "https://jsonplaceholder.typicode.com/users";
var httpClinet = createHttpClient();
var response = await httpClinet.get(url);
var _myRequest = JSON.decode(response.body);
print(_myRequest);
print(_myRequest[0]);
///so forth

}
@override
Widget build(BuildContext context) {
return new Container(
child: new Center(
child: new RaisedButton(onPressed: _loadData,child: new Text("Fetch"),),
),
);
}

关于Dart BoundSinkStream 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48976657/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com