79 lines
1.9 KiB
Dart
79 lines
1.9 KiB
Dart
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:SEFER/views/widgets/error_snakbar.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') {
|
|
mySnackbarSuccess('');
|
|
|
|
fetchCatrsForDrivers();
|
|
} else {
|
|
mySnackeBarError('');
|
|
}
|
|
}
|
|
|
|
removeCar(String car) async {}
|
|
@override
|
|
void onInit() {
|
|
fetchCatrsForDrivers();
|
|
super.onInit();
|
|
}
|
|
}
|