服務:
static Future addDeposit(String amount, String product, String phone, String token) async {
assert(token.isNotEmpty);
try{
Response<String> response = await _dio.post(
'url',
data: <String, String>{
'amount': amount,
'product': product,
'phone': phone,
},
);
if (response.statusCode == 200){
return Deposit.fromJson(jsonDecode(response.data ?? '{}'));
}else if(response.statusCode == 400){
return Deposit.fromJson(response.data ?? '');
}else{
throw Exception(response.statusMessage);
}
}catch (e){
print(e);
}
}
child: FutureBuilder<Deposit?>(
future: AuthService.addDeposit(amount, product, phone,),
builder: (BuildContext context, AsyncSnapshot<Deposit?> snapshot){
if(snapshot.hasData){
return _snapshotHasData(snapshot.data!);
}else if(snapshot.hasError){
return Text('${snapshot.error}');
}
return const LinearProgressIndicator();
},
),
錯誤:無法將引數型別“Future”分配給引數型別“Future<Deposit?>?”。
- “未來”來自“飛鏢:異步”。
- “存款”來自“package:ias/models/deposit_model.dart”(“lib/models/deposit_model.dart”)。未來:AuthService.addDeposit(金額,產品,電話),
uj5u.com熱心網友回復:
嘗試添加資料回傳型別
Future<Deposit?> addDeposit(String amount, String product, String phone, String token) async {
更多關于空安全
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/535788.html
標籤:扑镖飞镖空安全