Future<List> getRouteDetail({
required String imei,
required String deviceId,
required String deviceType,
required String phoneType,
required String phoneBrand,
required String phoneOS,
required double latitude,
required double longitude,
required String appVersion,
required String timestamp,
required String activation,
required String signature,
required String route, // Passing the route
}) async {
const String url = Global.BASE_API + Global.FIND_SCHEDULE_TRANSPORT;
try {
// Create the JSON data
final Map<String, dynamic> requestData = {
'route': route, // The correct JSON format
};
print("Sending data: ${jsonEncode(requestData)}");
final response = await http.post(
Uri.parse(url),
body: jsonEncode(
requestData), // Ensure the data is properly encoded as JSON
headers: {
'X-IMEI': imei,
'X-DEVICE-ID': deviceId,
'X-DEVICE-TYPE': deviceType,
'X-PHONE-TYPE': phoneType,
'X-PHONE-BRAND': phoneBrand,
'X-PHONE-OS': phoneOS,
'X-LATITUDE': latitude.toString(),
'X-LONGITUDE': longitude.toString(),
'X-APP-VERSION': appVersion,
'X-API-ACTIVATION-CODE': activation,
'X-API-TIMESTAMP': timestamp,
'X-API-SIGNATURE': signature,
'Content-Type': 'application/json', // Correct Content-Type for JSON
},
);
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');
if (response.statusCode == 200) {
final List<dynamic> responseData = json.decode(response.body)['data'];
return responseData.map((json) => RouteData.fromJson(json)).toList();
} else {
throw Exception('Failed to load bus routes: ${response.reasonPhrase}');
}
} catch (e) {
throw Exception('Failed to load bus routes: $e');
}
}
Reloaded 1 of 2802 libraries in 2,964ms (compile: 75 ms, reload: 1120 ms, reassemble: 1660 ms).
I/flutter (13061): Headers:
I/flutter (13061): X-IMEI: 1dedbb40-5ba7-11ef-b2cd-adcc39c0def4
I/flutter (13061): X-DEVICE-ID: c50807a8-f410-4caa-8724-658a12c54217
I/flutter (13061): X-DEVICE-TYPE: Android
I/flutter (13061): X-PHONE-TYPE: 2201117TY
I/flutter (13061): X-PHONE-BRAND: Redmi
I/flutter (13061): X-PHONE-OS: Android 13
I/flutter (13061): X-LATITUDE: -6.2473951
I/flutter (13061): X-LONGITUDE: 106.7971141
I/flutter (13061): X-APP-VERSION: 1.0.0
I/flutter (13061): X-API-ACTIVATION-CODE: VTJGc2RHVmtYMThkcVNJc20vM3NsQVdDeGxqV01mdlkyNHFjaTJlTmR1ZW1iNCtzdHFPU29TMzFGYkw3djlMSU5qT2R1WmFmR0JnVEI2WHJSUXZrYVFQV2JqM29ZekF4TThGZVlHZ0dTRVE4b3YvZTNubG55bGtCTnRpVUNGQThzWmpIWTV6cjZUbDBqMkJKR3VuZmZTT0NLSUsvZDkxS0RyZ3hKRUg5dThVPQ==
I/flutter (13061): X-API-TIMESTAMP: 2024-08-17T05:25:54+00:00
I/flutter (13061): X-API-SIGNATURE: wWNE3wGV9exPHUMH7mPBayiASXmcAk6xZXYWeOMPIxgFp0RnKJ8v7O+od4+IKcVYdnCahbnE67v0CLwhAk9cyA==
I/flutter (13061): Sending data: {“route”:”BEKASI”}
I/flutter (13061): Response status: 500
[log] Error fetching routes: Exception: Failed to load bus routes: Exception: Failed to load bus routes: Internal Server Error
I/flutter (13061): Response body: {“status”:”500″,”message”:”Internal Server Error [Cannot deserialize value of type java.lang.String
from Object value (token JsonToken.START_OBJECT
)n at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION
disabled); line: 1, column: 1]]”,”data”:null,”error”:”Internal Server Error [Cannot deserialize value of type java.lang.String
from Object value (token JsonToken.START_OBJECT
)n at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION
disabled); line: 1, column: 1]]”,”timestamp”:1723872356036}
I was try in plain/text and application/json in dio and http and still error why is it?
Muhamad Iqbal Irsyad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.