代码报错import dartconvert;import darttyped_data;import packagefluttermaterialdart;import packagediodiodart;class StreamTextPage extends StatefulWidget override _StreamTextPageState createState = _Stre
在Flutter中,当一个函数返回一个Stream类型时,需要使用async*关键字来定义这个函数,表示它是一个异步生成器函数。所以,需要将_getTextStream()函数改成异步生成器函数:
Stream<Uint8List> _getTextStream() async* {
final dio = Dio();
final response = await dio.get(
'http://127.0.0.1:9000/?content=%E7%BB%99%E6%88%91%E5%86%99%E4%B8%80%E7%AF%87300%E5%AD%97%E7%9A%84%E6%96%87%E7%AB%A0%EF%BC%8C%E5%85%B3%E4%BA%8E%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD',
options: Options(responseType: ResponseType.stream));
yield* response.data.stream();
}
原文地址: http://www.cveoy.top/t/topic/d1mT 著作权归作者所有。请勿转载和采集!