Service:
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();
},
),
Error: The argument type 'Future' can't be assigned to the parameter type 'Future<Deposit?>?'.
- 'Future' is from 'dart:async'.
- 'Deposit' is from 'package:ias/models/deposit_model.dart' ('lib/models/deposit_model.dart'). future: AuthService.addDeposit(amount, product, phone),
CodePudding user response:
Try to add data return type
Future<Deposit?> addDeposit(String amount, String product, String phone, String token) async {
More about null-safety