Update: 2026-08-08 14:26:43
This commit is contained in:
@@ -56,7 +56,7 @@ class LeaderboardController extends GetxController {
|
||||
payload: {'type': 'trips'},
|
||||
);
|
||||
if (resTrips != null && resTrips != 'failure') {
|
||||
var data = jsonDecode(resTrips);
|
||||
var data = _decode(resTrips);
|
||||
if (data['message'] is List) {
|
||||
tripLeaderboard = (data['message'] as List).map((e) => LeaderboardEntry(
|
||||
driverId: e['driver_id'].toString(),
|
||||
@@ -75,7 +75,7 @@ class LeaderboardController extends GetxController {
|
||||
payload: {'type': 'earnings'},
|
||||
);
|
||||
if (resEarnings != null && resEarnings != 'failure') {
|
||||
var data = jsonDecode(resEarnings);
|
||||
var data = _decode(resEarnings);
|
||||
if (data['message'] is List) {
|
||||
earningsLeaderboard = (data['message'] as List).map((e) => LeaderboardEntry(
|
||||
driverId: e['driver_id'].toString(),
|
||||
@@ -99,4 +99,17 @@ class LeaderboardController extends GetxController {
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
/// CRUD().post تُرجع الردّ **مفكوكاً** أصلاً (Map)، بينما CRUD().get
|
||||
/// تُرجع نصاً. تمرير الـ Map إلى jsonDecode كان يرمي
|
||||
/// "type '_Map<String, dynamic>' is not a subtype of type 'String'"،
|
||||
/// فتُبتلع لوحة الصدارة في catch وتظهر فارغة دائماً مهما صحّ الردّ.
|
||||
Map<String, dynamic> _decode(dynamic res) {
|
||||
if (res is Map) return Map<String, dynamic>.from(res);
|
||||
if (res is String && res.isNotEmpty) {
|
||||
final decoded = jsonDecode(res);
|
||||
if (decoded is Map) return Map<String, dynamic>.from(decoded);
|
||||
}
|
||||
return <String, dynamic>{};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user