11/10/1
This commit is contained in:
76
lib/views/auth/captin/driver_car_controller.dart
Normal file
76
lib/views/auth/captin/driver_car_controller.dart
Normal file
@@ -0,0 +1,76 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:SEFER/constant/box_name.dart';
|
||||
import 'package:SEFER/constant/colors.dart';
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:SEFER/main.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class DriverCarController extends GetxController {
|
||||
bool isLoading = false;
|
||||
List cars = [];
|
||||
int? carId;
|
||||
fetchCatrsForDrivers() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
var res = await CRUD().get(link: AppLink.getNewCarsDrivers, payload: {
|
||||
"driverID": box.read(BoxName.driverID).toString(),
|
||||
});
|
||||
if (res != 'failure') {
|
||||
var d = jsonDecode(res)['message'];
|
||||
cars = d;
|
||||
carId = cars.isEmpty ? 1 : cars.length + 1;
|
||||
}
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
addCarsForDrivers(
|
||||
String vin,
|
||||
String car_plate,
|
||||
String make,
|
||||
String model,
|
||||
String year,
|
||||
String expiration_date,
|
||||
String color,
|
||||
String color_hex,
|
||||
String address,
|
||||
String owner,
|
||||
String registration_date,
|
||||
String displacement,
|
||||
String fuel) async {
|
||||
var res = await CRUD().post(
|
||||
link: AppLink.addNewCarsDrivers,
|
||||
payload: {
|
||||
"driverID": box.read(BoxName.driverID).toString(),
|
||||
"vin": vin,
|
||||
"car_plate": car_plate,
|
||||
"make": make,
|
||||
"model": model,
|
||||
"year": year,
|
||||
"expiration_date": expiration_date,
|
||||
"color": color,
|
||||
"owner": owner,
|
||||
"color_hex": color_hex,
|
||||
"address": address,
|
||||
"displacement": displacement,
|
||||
"fuel": fuel,
|
||||
"registration_date": registration_date,
|
||||
},
|
||||
);
|
||||
if (res != 'failure') {
|
||||
Get.snackbar('Success'.tr, '', backgroundColor: AppColor.greenColor);
|
||||
fetchCatrsForDrivers();
|
||||
} else {
|
||||
Get.snackbar('Error'.tr, '', backgroundColor: AppColor.redColor);
|
||||
}
|
||||
}
|
||||
|
||||
removeCar(String car) async {}
|
||||
@override
|
||||
void onInit() {
|
||||
fetchCatrsForDrivers();
|
||||
super.onInit();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user