您好,我尝试向端点发出带有两个参数的 GET HTTP 请求,但我不断收到此错误,我尝试了不同的方法,但仍然无法正常工作。请有人帮助我是新手,这是错误消息 - #I/flutter (11573): Text("Error Occured: FormatException: Invalid radix-10 number (at character 1)\n//api.ergagro.com: 112\n^\n")
服务功能
Future<CheckInventoryStatus> checkDailyStatus() async {
final queryParameters = {
'userId': 'b6caf34c-a425-4710-a3ee-aa22a382882a',
'agentId': '57',
};
final url = new Uri.http('http://api.ergagro.com:112',
'/CheckDailyStockTakingStatus', queryParameters);
final response = await http.get(url);
if (response.statusCode == 200) {
final jsonStatus = jsonDecode(response.body);
return CheckInventoryStatus.fromJson(jsonStatus);
} else {
throw Exception();
}
}
未来建设者:
FutureBuilder<CheckInventoryStatus>(
future: checkDailyStatus(),
builder: (context, snapshot) {
if (snapshot.hasData) {
final status = snapshot.data;
return Text("Name: ${status.message}");
} else{
return Text(snapshot.error.toString());
}
},
),
模型:
// To parse this JSON data, do
//
// final checkInventoryStatus = checkInventoryStatusFromJson(jsonString);
import 'dart:convert';
CheckInventoryStatus checkInventoryStatusFromJson(String str) => CheckInventoryStatus.fromJson(json.decode(str));
String checkInventoryStatusToJson(CheckInventoryStatus data) => json.encode(data.toJson());
class CheckInventoryStatus {
CheckInventoryStatus({
this.statusCode,
this.message,
this.success,
this.stock,
});
int statusCode;
String message;
bool success;
Stock stock;
factory CheckInventoryStatus.fromJson(Map<String, dynamic> json) => CheckInventoryStatus(
statusCode: json["StatusCode"],
message: json["Message"],
success: json["Success"],
stock: Stock.fromJson(json["Stock"]),
);
Map<String, dynamic> toJson() => {
"StatusCode": statusCode,
"Message": message,
"Success": success,
"Stock": stock.toJson(),
};
}
class Stock {
Stock({
this.oid,
this.createdBy,
this.createdOn,
this.modifiedBy,
this.modifiedOn,
this.season,
this.seasonTitle,
this.anchor,
this.anchorName,
this.anchorAcronym,
this.distributionCentre,
this.distributionCentreName,
this.agent,
this.stateCoordinator,
this.stockDate,
this.transId,
this.stateCoordinatorId,
this.agentId,
this.userId,
this.stockItems,
});
int oid;
String createdBy;
DateTime createdOn;
dynamic modifiedBy;
dynamic modifiedOn;
dynamic season;
dynamic seasonTitle;
int anchor;
dynamic anchorName;
dynamic anchorAcronym;
int distributionCentre;
dynamic distributionCentreName;
String agent;
String stateCoordinator;
DateTime stockDate;
String transId;
String stateCoordinatorId;
String agentId;
String userId;
List<dynamic> stockItems;
factory Stock.fromJson(Map<String, dynamic> json) => Stock(
oid: json["Oid"],
createdBy: json["CreatedBy"],
createdOn: DateTime.parse(json["CreatedOn"]),
modifiedBy: json["ModifiedBy"],
modifiedOn: json["ModifiedOn"],
season: json["Season"],
seasonTitle: json["SeasonTitle"],
anchor: json["Anchor"],
anchorName: json["AnchorName"],
anchorAcronym: json["AnchorAcronym"],
distributionCentre: json["DistributionCentre"],
distributionCentreName: json["DistributionCentreName"],
agent: json["Agent"],
stateCoordinator: json["StateCoordinator"],
stockDate: DateTime.parse(json["StockDate"]),
transId: json["TransId"],
stateCoordinatorId: json["StateCoordinatorId"],
agentId: json["AgentId"],
userId: json["UserId"],
stockItems: List<dynamic>.from(json["StockItems"].map((x) => x)),
);
Map<String, dynamic> toJson() => {
"Oid": oid,
"CreatedBy": createdBy,
"CreatedOn": createdOn.toIso8601String(),
"ModifiedBy": modifiedBy,
"ModifiedOn": modifiedOn,
"Season": season,
"SeasonTitle": seasonTitle,
"Anchor": anchor,
"AnchorName": anchorName,
"AnchorAcronym": anchorAcronym,
"DistributionCentre": distributionCentre,
"DistributionCentreName": distributionCentreName,
"Agent": agent,
"StateCoordinator": stateCoordinator,
"StockDate": stockDate.toIso8601String(),
"TransId": transId,
"StateCoordinatorId": stateCoordinatorId,
"AgentId": agentId,
"UserId": userId,
"StockItems": List<dynamic>.from(stockItems.map((x) => x)),
};
}