new backend 29-04-2026
This commit is contained in:
@@ -9,6 +9,8 @@ import 'package:sefer_driver/controller/functions/crud.dart';
|
||||
import 'package:sefer_driver/main.dart';
|
||||
import 'package:sefer_driver/models/model/driver/rides_summary_model.dart';
|
||||
|
||||
import '../../../views/widgets/error_snakbar.dart';
|
||||
|
||||
class DurationController extends GetxController {
|
||||
final data = DurationData;
|
||||
// late AnimationController animationController;
|
||||
@@ -38,41 +40,56 @@ class DurationController extends GetxController {
|
||||
var res = await CRUD().get(
|
||||
link: AppLink.driverStatistic,
|
||||
payload: {'driverID': box.read(BoxName.driverID)});
|
||||
if (res == 'failure') {
|
||||
monthlyList = [];
|
||||
isLoading = false;
|
||||
update();
|
||||
|
||||
if (res == 'success') {
|
||||
try {
|
||||
monthlyList = jsonDecode(res)['message'];
|
||||
} catch (e) {
|
||||
monthlyList = [];
|
||||
}
|
||||
} else {
|
||||
monthlyList = jsonDecode(res)['message'];
|
||||
isLoading = false;
|
||||
update();
|
||||
monthlyList = [];
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> fetchData() async {
|
||||
isLoading = true;
|
||||
update(); // Notify the observers about the loading state change
|
||||
update();
|
||||
|
||||
var res = await CRUD().get(
|
||||
link: AppLink.getTotalDriverDuration,
|
||||
payload: {'driver_id': box.read(BoxName.driverID)},
|
||||
);
|
||||
jsonData1 = jsonDecode(res);
|
||||
var jsonResponse = jsonDecode(res) as Map<String, dynamic>;
|
||||
isLoading = false;
|
||||
final List<dynamic> jsonData = jsonResponse['message'];
|
||||
rideData = jsonData.map<MonthlyDataModel>((item) {
|
||||
return MonthlyDataModel.fromJson(item);
|
||||
}).toList();
|
||||
final List<FlSpot> spots = rideData
|
||||
.map((data) => FlSpot(
|
||||
data.day.toDouble(),
|
||||
data.totalDuration.toDouble(),
|
||||
))
|
||||
.toList();
|
||||
chartData = spots;
|
||||
|
||||
update(); // Notify the observers about the data and loading state change
|
||||
if (res == 'success') {
|
||||
try {
|
||||
jsonData1 = jsonDecode(res);
|
||||
final List<dynamic> jsonData = jsonData1['message'];
|
||||
rideData = jsonData.map<MonthlyDataModel>((item) {
|
||||
return MonthlyDataModel.fromJson(item);
|
||||
}).toList();
|
||||
|
||||
final List<FlSpot> spots = rideData
|
||||
.map((data) => FlSpot(
|
||||
data.day.toDouble(),
|
||||
data.totalDuration.toDouble(),
|
||||
))
|
||||
.toList();
|
||||
chartData = spots;
|
||||
} catch (e) {
|
||||
jsonData1 = {};
|
||||
chartData = <FlSpot>[];
|
||||
}
|
||||
} else {
|
||||
jsonData1 = {};
|
||||
chartData = <FlSpot>[];
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> fetchRideDriver() async {
|
||||
@@ -83,9 +100,9 @@ class DurationController extends GetxController {
|
||||
link: AppLink.getRidesDriverByDay,
|
||||
payload: {'driver_id': box.read(BoxName.driverID)},
|
||||
);
|
||||
if (res != 'failure') {
|
||||
if (res != 'failure' && res != 'no_internet' && res != 'token_expired') {
|
||||
jsonData2 = jsonDecode(res);
|
||||
var jsonResponse = jsonDecode(res) as Map<String, dynamic>;
|
||||
var jsonResponse = jsonData2 as Map<String, dynamic>;
|
||||
isLoading = false;
|
||||
final List<dynamic> jsonData = jsonResponse['message'];
|
||||
rideCountData = jsonData.map<MonthlyRideModel>((item) {
|
||||
@@ -110,17 +127,17 @@ class DurationController extends GetxController {
|
||||
.toList();
|
||||
chartRidePriceDriver = spotsDriverPrices;
|
||||
|
||||
update(); // Notify the observers about the data and loading state change
|
||||
update();
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
title: 'No data yet!'.tr,
|
||||
middleText: '',
|
||||
confirm: MyElevatedButton(
|
||||
title: 'OK'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
Get.back();
|
||||
}));
|
||||
isLoading = false;
|
||||
jsonData2 = {};
|
||||
chartRideCount = <FlSpot>[];
|
||||
chartRidePriceDriver = <FlSpot>[];
|
||||
update();
|
||||
|
||||
if (res == 'no_internet') {
|
||||
mySnackeBarError('No internet connection'.tr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user