WIP
This commit is contained in:
parent
7dd7ed7a32
commit
a79b165635
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hub/components/templates_components/details_component/details_component_widget.dart';
|
import 'package:hub/components/templates_components/details_component/details_component_widget.dart';
|
||||||
import 'package:hub/features/backend/index.dart';
|
import 'package:hub/features/backend/index.dart';
|
||||||
|
@ -7,7 +9,11 @@ import 'package:hub/shared/utils/index.dart';
|
||||||
|
|
||||||
/// [VehicleModel] is a class that contains the business logic of the vehicle page.
|
/// [VehicleModel] is a class that contains the business logic of the vehicle page.
|
||||||
class VehicleModel extends FlutterFlowModel<VehiclePage>
|
class VehicleModel extends FlutterFlowModel<VehiclePage>
|
||||||
with _BaseVehiclePage, _VehicleHistoryScreenModel, _VehicleRegisterScreenModel, _VehicleUpdateScreenModel {
|
with
|
||||||
|
_BaseVehiclePage,
|
||||||
|
_VehicleHistoryScreenModel,
|
||||||
|
_VehicleRegisterScreenModel,
|
||||||
|
_VehicleUpdateScreenModel {
|
||||||
/// [VehicleModel] is a singleton class that contains the business logic of the vehicle page.
|
/// [VehicleModel] is a singleton class that contains the business logic of the vehicle page.
|
||||||
static VehicleModel? _instance = VehicleModel._internal();
|
static VehicleModel? _instance = VehicleModel._internal();
|
||||||
VehicleModel._internal();
|
VehicleModel._internal();
|
||||||
|
@ -31,6 +37,10 @@ class VehicleModel extends FlutterFlowModel<VehiclePage>
|
||||||
|
|
||||||
textFieldFocusModel = FocusNode();
|
textFieldFocusModel = FocusNode();
|
||||||
textFieldControllerModel = TextEditingController();
|
textFieldControllerModel = TextEditingController();
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||||
|
vehicleAmountRegister = 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -60,11 +70,12 @@ mixin class _BaseVehiclePage {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
late final VehicleModel model;
|
late final VehicleModel model;
|
||||||
late final TabController tabBarController;
|
late final TabController tabBarController;
|
||||||
dynamic item;
|
// dynamic item;
|
||||||
BuildContext context = navigatorKey.currentContext!;
|
BuildContext context = navigatorKey.currentContext!;
|
||||||
bool isEditing = false;
|
bool isEditing = false;
|
||||||
String? vehicleId;
|
String? vehicleId;
|
||||||
ApiCallResponse? vehicleResponse;
|
ApiCallResponse? vehicleResponse;
|
||||||
|
late final vehicleAmountRegister;
|
||||||
|
|
||||||
VoidCallback? onUpdateVehicle;
|
VoidCallback? onUpdateVehicle;
|
||||||
VoidCallback? onRegisterVehicle;
|
VoidCallback? onRegisterVehicle;
|
||||||
|
@ -72,7 +83,8 @@ mixin class _BaseVehiclePage {
|
||||||
|
|
||||||
FocusNode? textFieldFocusLicensePlate;
|
FocusNode? textFieldFocusLicensePlate;
|
||||||
TextEditingController? textFieldControllerLicensePlate;
|
TextEditingController? textFieldControllerLicensePlate;
|
||||||
String? textControllerLicensePlateValidator(BuildContext context, String? value) {
|
String? textControllerLicensePlateValidator(
|
||||||
|
BuildContext context, String? value) {
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
return FFLocalizations.of(context).getVariableText(
|
return FFLocalizations.of(context).getVariableText(
|
||||||
ptText: 'Placa é obrigatória',
|
ptText: 'Placa é obrigatória',
|
||||||
|
@ -85,7 +97,8 @@ mixin class _BaseVehiclePage {
|
||||||
// (ABC1D23)
|
// (ABC1D23)
|
||||||
final mercosurPlateRegex = RegExp(r'^[A-Z]{3}\d[A-Z]\d{2}$');
|
final mercosurPlateRegex = RegExp(r'^[A-Z]{3}\d[A-Z]\d{2}$');
|
||||||
|
|
||||||
if (!brazilianPlateRegex.hasMatch(value) && !mercosurPlateRegex.hasMatch(value)) {
|
if (!brazilianPlateRegex.hasMatch(value) &&
|
||||||
|
!mercosurPlateRegex.hasMatch(value)) {
|
||||||
return FFLocalizations.of(context).getVariableText(
|
return FFLocalizations.of(context).getVariableText(
|
||||||
ptText: 'Placa inválida',
|
ptText: 'Placa inválida',
|
||||||
enText: 'Invalid license plate',
|
enText: 'Invalid license plate',
|
||||||
|
@ -126,9 +139,9 @@ mixin class _BaseVehiclePage {
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearFields() async {
|
void clearFields() async {
|
||||||
textFieldControllerLicensePlate!.clear();
|
textFieldControllerLicensePlate = TextEditingController(text: '');
|
||||||
textFieldControllerColor!.clear();
|
textFieldControllerColor = TextEditingController(text: '');
|
||||||
textFieldControllerModel!.clear();
|
textFieldControllerModel = TextEditingController(text: '');
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleEditingChanged(bool editing) {
|
void handleEditingChanged(bool editing) {
|
||||||
|
@ -136,12 +149,18 @@ mixin class _BaseVehiclePage {
|
||||||
clearFields();
|
clearFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEditForm() {
|
void setEditForm(dynamic item) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
vehicleId = item['vehicleId'];
|
vehicleId = item['vehicleId'];
|
||||||
textFieldControllerLicensePlate!.text = item['licensePlate'];
|
log("setEditForm ");
|
||||||
textFieldControllerColor!.text = item['color'];
|
log("setEditForm -> ${item.toString()}");
|
||||||
textFieldControllerModel!.text = item['model'];
|
|
||||||
|
textFieldControllerLicensePlate = TextEditingController(
|
||||||
|
text: item != null ? item['licensePlate'] ?? '' : '');
|
||||||
|
textFieldControllerColor =
|
||||||
|
TextEditingController(text: item != null ? item['color'] ?? '' : '');
|
||||||
|
textFieldControllerModel =
|
||||||
|
TextEditingController(text: item != null ? item['model'] ?? '' : '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,6 +168,9 @@ mixin class _BaseVehiclePage {
|
||||||
/// [_VehicleHistoryScreenModel] is a mixin that contains the business logic of the vehicle history page.
|
/// [_VehicleHistoryScreenModel] is a mixin that contains the business logic of the vehicle history page.
|
||||||
mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
||||||
Map<String, Color>? generateStatusColorMap(dynamic uItem) {
|
Map<String, Color>? generateStatusColorMap(dynamic uItem) {
|
||||||
|
final autoApproval = uItem['autoApproval'];
|
||||||
|
if (autoApproval == true) return null;
|
||||||
|
|
||||||
final statusMap = {
|
final statusMap = {
|
||||||
"ATI": {
|
"ATI": {
|
||||||
"text": FFLocalizations.of(context).getVariableText(
|
"text": FFLocalizations.of(context).getVariableText(
|
||||||
|
@ -197,7 +219,8 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
||||||
final status = uItem['status'];
|
final status = uItem['status'];
|
||||||
if (statusMap.containsKey(status)) {
|
if (statusMap.containsKey(status)) {
|
||||||
return {
|
return {
|
||||||
statusMap[status]!['text'] as String: statusMap[status]!['color'] as Color,
|
statusMap[status]!['text'] as String:
|
||||||
|
statusMap[status]!['color'] as Color,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
|
@ -220,18 +243,19 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final updateText = FFLocalizations.of(context).getVariableText(ptText: 'Editar', enText: 'Edit');
|
final updateText = FFLocalizations.of(context)
|
||||||
|
.getVariableText(ptText: 'Editar', enText: 'Edit');
|
||||||
final updateIcon = Icon(Icons.edit, color: iconButtonColor);
|
final updateIcon = Icon(Icons.edit, color: iconButtonColor);
|
||||||
Future updateOnPressed() async {
|
Future updateOnPressed() async {
|
||||||
context.pop();
|
context.pop();
|
||||||
isEditing = true;
|
isEditing = true;
|
||||||
item = item;
|
|
||||||
|
|
||||||
switchTab(1);
|
switchTab(1);
|
||||||
setEditForm();
|
setEditForm(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
final cancelText = FFLocalizations.of(context).getVariableText(ptText: 'Cancelar', enText: 'Cancel');
|
final cancelText = FFLocalizations.of(context)
|
||||||
|
.getVariableText(ptText: 'Cancelar', enText: 'Cancel');
|
||||||
final cancelIcon = Icon(Icons.close, color: iconButtonColor);
|
final cancelIcon = Icon(Icons.close, color: iconButtonColor);
|
||||||
Future cancelOnPressed() async {
|
Future cancelOnPressed() async {
|
||||||
showAlertDialog(
|
showAlertDialog(
|
||||||
|
@ -244,11 +268,12 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
||||||
ptText: 'Você tem certeza que deseja cancelar essa solicitação?',
|
ptText: 'Você tem certeza que deseja cancelar essa solicitação?',
|
||||||
enText: 'Are you sure you want to delete this request?',
|
enText: 'Are you sure you want to delete this request?',
|
||||||
),
|
),
|
||||||
() async => await processCancelRequest(item['status']),
|
() async => await processCancelRequest(item['status'], item),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final deleteText = FFLocalizations.of(context).getVariableText(ptText: 'Excluir', enText: 'Delete');
|
final deleteText = FFLocalizations.of(context)
|
||||||
|
.getVariableText(ptText: 'Excluir', enText: 'Delete');
|
||||||
final deleteIcon = Icon(Icons.delete, color: iconButtonColor);
|
final deleteIcon = Icon(Icons.delete, color: iconButtonColor);
|
||||||
Future deleteOnPressed() async {
|
Future deleteOnPressed() async {
|
||||||
showAlertDialog(
|
showAlertDialog(
|
||||||
|
@ -261,7 +286,7 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
||||||
ptText: 'Você tem certeza que deseja excluir esse veículo?',
|
ptText: 'Você tem certeza que deseja excluir esse veículo?',
|
||||||
enText: 'Are you sure you want to delete this vehicle?',
|
enText: 'Are you sure you want to delete this vehicle?',
|
||||||
),
|
),
|
||||||
() async => await processDeleteRequest(),
|
() async => await processDeleteRequest(item),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +315,7 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> processDeleteRequest() async {
|
Future<void> processDeleteRequest(dynamic item) async {
|
||||||
int id = item['vehicleId'];
|
int id = item['vehicleId'];
|
||||||
await PhpGroup.deleteVehicle.call(vehicleId: id).then((value) {
|
await PhpGroup.deleteVehicle.call(vehicleId: id).then((value) {
|
||||||
context.pop(value);
|
context.pop(value);
|
||||||
|
@ -330,18 +355,18 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> processCancelRequest(String status) async {
|
Future<void> processCancelRequest(String status, dynamic item) async {
|
||||||
late final ApiCallResponse value;
|
late final ApiCallResponse value;
|
||||||
try {
|
try {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 'APR_CREATE':
|
case 'APR_CREATE':
|
||||||
value = await processCancelDeleteRequest();
|
value = await processCancelDeleteRequest(item);
|
||||||
break;
|
break;
|
||||||
case 'AGU_CHANGE':
|
case 'AGU_CHANGE':
|
||||||
value = await processCancelUpdateRequest();
|
value = await processCancelUpdateRequest(item);
|
||||||
break;
|
break;
|
||||||
case 'APR_DELETE':
|
case 'APR_DELETE':
|
||||||
value = await processCancelCreateRequest();
|
value = await processCancelCreateRequest(item);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -382,17 +407,17 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ApiCallResponse> processCancelDeleteRequest() async {
|
Future<ApiCallResponse> processCancelDeleteRequest(dynamic item) async {
|
||||||
final int id = item['vehicleId'];
|
final int id = item['vehicleId'];
|
||||||
return await PhpGroup.deleteVehicle.call(vehicleId: id);
|
return await PhpGroup.deleteVehicle.call(vehicleId: id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ApiCallResponse> processCancelUpdateRequest() async {
|
Future<ApiCallResponse> processCancelUpdateRequest(dynamic item) async {
|
||||||
final int id = item['vehicleId'];
|
final int id = item['vehicleId'];
|
||||||
return await PhpGroup.deleteVehicle.call(vehicleId: id);
|
return await PhpGroup.deleteVehicle.call(vehicleId: id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ApiCallResponse> processCancelCreateRequest() async {
|
Future<ApiCallResponse> processCancelCreateRequest(dynamic item) async {
|
||||||
final int id = item['vehicleId'];
|
final int id = item['vehicleId'];
|
||||||
return await PhpGroup.deleteVehicle.call(vehicleId: id);
|
return await PhpGroup.deleteVehicle.call(vehicleId: id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue