[英]Can't get Future Value from DIO Flutter
我是 Flutter 編程的新手。 我在嘗試從 Future 獲得價值時遇到問題。 得到它之后,我想反序列化它以進行進一步處理。
Future 的返回值在 JSON 數組上。
我應該怎么做才能解決這種情況?
class _MyAppState extends State<BodyWidget>
{
bool loading = true;
List<Widget> listArray = [];
Dio dio = new Dio();
dynamic isicontent = null;
Future<dynamic> getOrderHistory() async {
final String pathUrl = "http://p.q.r.s/mobile/QIXGetShipmentHistory/" + await FlutterSession().get("MobileUsername");
var responseDio = await dio.get(pathUrl, options: Options( headers: {'Content-Type': 'application/json; charset=UTF-8' } ) );
print(responseDio.data); // It's works fine here...
return responseDio.data;
}
void renderIconShipmentOrderHistory()
{
var resultRespon = getOrderHistory();
print(resultRespon); //the problem is here...
}
}
return
語句需要返回一個Future
; 類似的東西:
return dio.get(
pathUrl,
options: Options(
headers: {
'Content-Type': 'application/json; charset=UTF-8'
}
)
)
簽名中的async
關鍵字可能可以刪除,因為不再有await
。
顯然,不返回Future
而是等待結果可能是另一種選擇。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.