milestone
This commit is contained in:
parent
1cc481a83e
commit
a07edd0c21
|
@ -74,9 +74,12 @@ class _VehicleHistoryScreenState extends State<VehicleHistoryScreen> {
|
|||
late final IconData? iconData;
|
||||
late final FreCardIcon? cardIcon;
|
||||
|
||||
if(isOwner is bool) {
|
||||
iconData = isOwner ? Symbols.no_crash :Symbols.directions_car;
|
||||
cardIcon = FreCardIcon(height: 50, width: 100, icon: Icon(iconData, size: 80, opticalSize: 10));
|
||||
if (isOwner is bool) {
|
||||
iconData = isOwner ? Symbols.no_crash : Symbols.directions_car;
|
||||
cardIcon = FreCardIcon(
|
||||
height: 50,
|
||||
width: 100,
|
||||
icon: Icon(iconData, size: 80, opticalSize: 10));
|
||||
}
|
||||
final String? tag = uItem['tag'];
|
||||
final bool containTag = tag.isNotNullAndEmpty;
|
||||
|
@ -91,64 +94,68 @@ class _VehicleHistoryScreenState extends State<VehicleHistoryScreen> {
|
|||
'${FFLocalizations.of(context).getVariableText(ptText: "Tag", enText: "Tag")}:':
|
||||
uItem['tag'] ?? '',
|
||||
};
|
||||
final Map<String, Color>? statusHashMap = await widget.model.generateStatusColorMap(uItem, 2);
|
||||
final List<Map<String, Color>?> statusHashMapList = [await widget.model.generateStatusColorMap(uItem, 2)];
|
||||
final Map<String, Color>? statusHashMap =
|
||||
await widget.model.generateStatusColorMap(uItem, 2);
|
||||
final List<Map<String, Color>?> statusHashMapList = [
|
||||
await widget.model.generateStatusColorMap(uItem, 2)
|
||||
];
|
||||
Future<void> onTapCardItemAction() async {
|
||||
final widgetFuture = widget.model.buildVehicleDetails(
|
||||
icon: isOwner is bool ? cardIcon : null,
|
||||
item: uItem,
|
||||
context: context,
|
||||
model: widget.model,
|
||||
icon: isOwner is bool ? cardIcon : null,
|
||||
item: uItem,
|
||||
context: context,
|
||||
model: widget.model,
|
||||
);
|
||||
|
||||
final dialogContent = await widgetFuture;
|
||||
|
||||
await showDialog(
|
||||
useSafeArea: true,
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return Dialog(
|
||||
alignment: Alignment.center,
|
||||
child: dialogContent,
|
||||
);
|
||||
},
|
||||
useSafeArea: true,
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return Dialog(
|
||||
alignment: Alignment.center,
|
||||
child: dialogContent,
|
||||
);
|
||||
},
|
||||
).whenComplete(() {
|
||||
safeSetState(() {
|
||||
_pageNumber = 1;
|
||||
_wrap = [];
|
||||
_future = _fetchVisits();
|
||||
});
|
||||
safeSetState(() {
|
||||
_pageNumber = 1;
|
||||
_wrap = [];
|
||||
_future = _fetchVisits();
|
||||
});
|
||||
}).catchError((e, s) {
|
||||
DialogUtil.errorDefault(context);
|
||||
LogUtil.requestAPIFailed(
|
||||
"proccessRequest.php", "", "Consulta de Veículos", e, s);
|
||||
safeSetState(() {
|
||||
_hasData = false;
|
||||
_loading = false;
|
||||
});
|
||||
DialogUtil.errorDefault(context);
|
||||
LogUtil.requestAPIFailed(
|
||||
"proccessRequest.php", "", "Consulta de Veículos", e, s);
|
||||
safeSetState(() {
|
||||
_hasData = false;
|
||||
_loading = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
final statusLinkedHashMap = statusHashMapList
|
||||
|
||||
final statusLinkedHashMap = statusHashMapList
|
||||
.map((map) => LinkedHashMap<String, Color>.from(map ?? {}))
|
||||
.toList();
|
||||
print('CardItemTemplateComponentWidget: ${statusLinkedHashMap}');
|
||||
final length = statusLinkedHashMap.expand((e) => [e.length]);
|
||||
print('CardItemTemplateComponentWidget: ${length}');
|
||||
return CardItemTemplateComponentWidget(
|
||||
icon: cardIcon,
|
||||
labelsHashMap: labelsHashMap,
|
||||
statusHashMap: statusHashMapList,
|
||||
onTapCardItemAction: onTapCardItemAction,
|
||||
itemWidthFactor: statusLinkedHashMap!.length == 1 ? 0.25 : 0.50
|
||||
);
|
||||
// double itemWidthFactor = statusHashMap.length == 1 ? 0.5 : 0.5;
|
||||
// double itemWidthFactor;
|
||||
// if (statusCount >= 3 && statusCount % 3 != 0) {
|
||||
// itemWidthFactor = (index % 3 == 2) ? 0.5 : 0.25;
|
||||
// } else if (statusCount == 3) {
|
||||
// itemWidthFactor = (index == 2) ? 0.52 : 0.25;
|
||||
// } else {
|
||||
// itemWidthFactor = statusCount == 1 ? 0.5 : 0.25;
|
||||
// }
|
||||
|
||||
icon: cardIcon,
|
||||
labelsHashMap: labelsHashMap,
|
||||
statusHashMap: statusHashMapList,
|
||||
onTapCardItemAction: onTapCardItemAction,
|
||||
itemWidthFactor: length == 1 ? 0.25 : 0.50,
|
||||
);
|
||||
// double itemWidthFactor = statusHashMap.length == 1 ? 0.5 : 0.5;
|
||||
// double itemWidthFactor;
|
||||
// if (statusCount >= 3 && statusCount % 3 != 0) {
|
||||
// itemWidthFactor = (index % 3 == 2) ? 0.5 : 0.25;
|
||||
// } else if (statusCount == 3) {
|
||||
// itemWidthFactor = (index == 2) ? 0.52 : 0.25;
|
||||
// } else {
|
||||
// itemWidthFactor = statusCount == 1 ? 0.5 : 0.25;
|
||||
// }
|
||||
}
|
||||
|
||||
Future<ApiCallResponse?> _fetchVisits() async {
|
||||
|
|
|
@ -61,8 +61,8 @@ class VehicleModel extends FlutterFlowModel<VehiclePage>
|
|||
final GlobalKey<FormState> updateFormKey = GlobalKey<FormState>();
|
||||
|
||||
Future<void> initAsync() async {
|
||||
|
||||
amountRegister = await StorageHelper().get(LocalsStorageKey.vehicleAmountRegister.key);
|
||||
amountRegister =
|
||||
await StorageHelper().get(LocalsStorageKey.vehicleAmountRegister.key);
|
||||
}
|
||||
|
||||
bool isFormValid(BuildContext context) {
|
||||
|
@ -171,7 +171,6 @@ mixin class _BaseVehiclePage {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// [_VehicleRegisterScreenModel] is a mixin that contains the business logic of the vehicle register page.
|
||||
mixin _VehicleRegisterScreenModel on _BaseVehiclePage {
|
||||
Future<void> registerVehicle() async {
|
||||
|
@ -239,19 +238,18 @@ mixin _VehicleUpdateScreenModel on _BaseVehiclePage {
|
|||
|
||||
/// [_VehicleHistoryScreenModel] is a mixin that contains the business logic of the vehicle history page.
|
||||
mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
||||
|
||||
Future<Map<String, Color>?> generateStatusColorMap(dynamic uItem, int count) async {
|
||||
final autoApproval = await StorageHelper().get(LocalsStorageKey.vehicleAutoApproval.key);
|
||||
if(autoApproval.toBoolean == true) return null;
|
||||
Future<Map<String, Color>?> generateStatusColorMap(
|
||||
dynamic uItem, int count) async {
|
||||
final autoApproval =
|
||||
await StorageHelper().get(LocalsStorageKey.vehicleAutoApproval.key);
|
||||
if (autoApproval.toBoolean == true) return null;
|
||||
|
||||
final theme = FlutterFlowTheme.of(context);
|
||||
final localization = FFLocalizations.of(context);
|
||||
|
||||
|
||||
byLanguage(en, pt) => localization.getVariableText(enText: en, ptText: pt);
|
||||
|
||||
|
||||
final preFixStatusMap = {
|
||||
final preFixStatusMap = {
|
||||
"APR_CREATE": {
|
||||
"text": byLanguage('Awaiting', 'Aguardando'),
|
||||
"color": theme.warning,
|
||||
|
@ -278,13 +276,12 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
|||
"text": byLanguage('Inactive', 'Inativo'),
|
||||
"color": theme.accent2,
|
||||
},
|
||||
|
||||
"APR_CREATE": {
|
||||
"text": byLanguage('Creation', 'Criação'),
|
||||
"color": theme.success,
|
||||
},
|
||||
"APR_DELETE": {
|
||||
"text": byLanguage('Deletion', 'Exclusão'),
|
||||
"text": byLanguage('Awaiting Deletion', 'Exclusão'),
|
||||
"color": theme.warning,
|
||||
},
|
||||
"APR_UPDATE": {
|
||||
|
@ -301,28 +298,31 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
|||
"text": byLanguage('My Vehicle', 'Meu Veículo'),
|
||||
"color": theme.primaryText,
|
||||
},
|
||||
false: {
|
||||
"text": byLanguage('', ''),
|
||||
"color": theme.accent2,
|
||||
},
|
||||
};
|
||||
|
||||
final status = uItem['status'];
|
||||
final isOwner = uItem['isOwnerVehicle'];
|
||||
|
||||
if (vehicleStatusMap.containsKey(status)) {
|
||||
if(count > 1) return {
|
||||
if (preFixStatusMap.containsKey(status))
|
||||
preFixStatusMap[status]!['text'] as String: preFixStatusMap[status]!['color'] as Color,
|
||||
vehicleStatusMap[status]!['text'] as String: vehicleStatusMap[status]!['color'] as Color,
|
||||
// if (ownerStatusMap.containsKey(isOwner) && (status != 'ATI' || status != 'INA'))
|
||||
// ownerStatusMap[isOwner]!['text'] as String: ownerStatusMap[isOwner]!['color'] as Color
|
||||
};
|
||||
if(status == 'ATI' || status == 'INA') return {
|
||||
vehicleStatusMap[status]!['text'] as String: vehicleStatusMap[status]!['color'] as Color,
|
||||
};
|
||||
if (count > 1)
|
||||
return {
|
||||
// if (preFixStatusMap.containsKey(status))
|
||||
// preFixStatusMap[status]!['text'] as String: preFixStatusMap[status]!['color'] as Color,
|
||||
vehicleStatusMap[status]!['text'] as String:
|
||||
vehicleStatusMap[status]!['color'] as Color,
|
||||
if (ownerStatusMap.containsKey(isOwner) &&
|
||||
(status != 'ATI' || status != 'INA'))
|
||||
ownerStatusMap[isOwner]!['text'] as String:
|
||||
ownerStatusMap[isOwner]!['color'] as Color
|
||||
};
|
||||
if (status == 'ATI' || status == 'INA')
|
||||
return {
|
||||
vehicleStatusMap[status]!['text'] as String:
|
||||
vehicleStatusMap[status]!['color'] as Color,
|
||||
};
|
||||
return {
|
||||
"${preFixStatusMap[status]!['text']} ${vehicleStatusMap[status]!['text']}": vehicleStatusMap[status]!['color'] as Color
|
||||
"${preFixStatusMap[status]!['text']} ${vehicleStatusMap[status]!['text']}":
|
||||
vehicleStatusMap[status]!['color'] as Color
|
||||
};
|
||||
}
|
||||
return {};
|
||||
|
@ -361,17 +361,16 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
|||
final cancelIcon = Icon(Icons.close, color: iconButtonColor);
|
||||
Future cancelOnPressed() async {
|
||||
showAlertDialog(
|
||||
context,
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Cancelar Solicitação',
|
||||
enText: 'Cancel Request',
|
||||
),
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Você tem certeza que deseja cancelar essa solicitação?',
|
||||
enText: 'Are you sure you want to delete this request?',
|
||||
),
|
||||
() async => await processCancelRequest(item['status'], item)
|
||||
);
|
||||
context,
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Cancelar Solicitação',
|
||||
enText: 'Cancel Request',
|
||||
),
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Você tem certeza que deseja cancelar essa solicitação?',
|
||||
enText: 'Are you sure you want to delete this request?',
|
||||
),
|
||||
() async => await processCancelRequest(item['status'], item));
|
||||
}
|
||||
|
||||
final deleteText = FFLocalizations.of(context)
|
||||
|
@ -398,14 +397,15 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
|||
final bool isAPR = item['status'].contains('APR');
|
||||
final bool isATI = item['status'].contains('ATI');
|
||||
|
||||
if(containStatus) return [
|
||||
if (containStatus)
|
||||
return [
|
||||
FFButtonWidget(
|
||||
text: deleteText,
|
||||
icon: deleteIcon,
|
||||
onPressed: deleteOnPressed,
|
||||
options: buttonOptions,
|
||||
),
|
||||
];
|
||||
];
|
||||
|
||||
return [
|
||||
if (isAGU && isOwnerVehicle)
|
||||
|
@ -434,15 +434,14 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
|||
|
||||
Future<void> processDeleteRequest(dynamic item) async {
|
||||
log('processDeleteRequest -> item[$item]');
|
||||
return await PhpGroup.deleteVehicle.call(
|
||||
vehicleId: item['vehicleId'],
|
||||
licensePlate: item['licensePlate'],
|
||||
model: item['model'],
|
||||
color: item['color'],
|
||||
)
|
||||
.then((value) {
|
||||
|
||||
|
||||
return await PhpGroup.deleteVehicle
|
||||
.call(
|
||||
vehicleId: item['vehicleId'],
|
||||
licensePlate: item['licensePlate'],
|
||||
model: item['model'],
|
||||
color: item['color'],
|
||||
)
|
||||
.then((value) {
|
||||
context.pop(value);
|
||||
context.pop(value);
|
||||
|
||||
|
@ -460,14 +459,13 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
|||
// ignore: unrelated_type_equality_checks
|
||||
}
|
||||
return showSnackbar(
|
||||
context,
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Success deleting vehicle',
|
||||
ptText: 'Succeso ao excluir veículo',
|
||||
),
|
||||
false,
|
||||
);
|
||||
|
||||
context,
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Success deleting vehicle',
|
||||
ptText: 'Succeso ao excluir veículo',
|
||||
),
|
||||
false,
|
||||
);
|
||||
}).catchError((err, stack) {
|
||||
context.pop();
|
||||
return showSnackbar(
|
||||
|
@ -502,7 +500,7 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
|||
context.pop(value);
|
||||
|
||||
if (value.jsonBody['error'] == true) {
|
||||
final String errorMsg = value.jsonBody['error_msg'] ;
|
||||
final String errorMsg = value.jsonBody['error_msg'];
|
||||
return showSnackbar(
|
||||
context,
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
|
@ -512,15 +510,14 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
|||
true,
|
||||
);
|
||||
}
|
||||
return showSnackbar(
|
||||
context,
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Success canceling request',
|
||||
ptText: 'Succeso ao cancelar solicitação',
|
||||
),
|
||||
false,
|
||||
);
|
||||
|
||||
return showSnackbar(
|
||||
context,
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Success canceling request',
|
||||
ptText: 'Succeso ao cancelar solicitação',
|
||||
),
|
||||
false,
|
||||
);
|
||||
} catch (err) {
|
||||
context.pop();
|
||||
return showSnackbar(
|
||||
|
@ -536,30 +533,29 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
|||
|
||||
Future<ApiCallResponse> processCancelDeleteRequest(dynamic item) async {
|
||||
return await PhpGroup.deleteVehicle.call(
|
||||
vehicleId: item['vehicleId'],
|
||||
licensePlate: item['licensePlate'],
|
||||
model: item['model'],
|
||||
color: item['color'],
|
||||
);
|
||||
vehicleId: item['vehicleId'],
|
||||
licensePlate: item['licensePlate'],
|
||||
model: item['model'],
|
||||
color: item['color'],
|
||||
);
|
||||
}
|
||||
|
||||
Future<ApiCallResponse> processCancelUpdateRequest(dynamic item) async {
|
||||
return await PhpGroup.deleteVehicle.call(
|
||||
vehicleId: item['vehicleId'],
|
||||
licensePlate: item['licensePlate'],
|
||||
model: item['model'],
|
||||
color: item['color'],
|
||||
|
||||
);
|
||||
vehicleId: item['vehicleId'],
|
||||
licensePlate: item['licensePlate'],
|
||||
model: item['model'],
|
||||
color: item['color'],
|
||||
);
|
||||
}
|
||||
|
||||
Future<ApiCallResponse> processCancelCreateRequest(dynamic item) async {
|
||||
return await PhpGroup.deleteVehicle.call(
|
||||
vehicleId: item['vehicleId'],
|
||||
licensePlate: item['licensePlate'],
|
||||
model: item['model'],
|
||||
color: item['color'],
|
||||
);
|
||||
vehicleId: item['vehicleId'],
|
||||
licensePlate: item['licensePlate'],
|
||||
model: item['model'],
|
||||
color: item['color'],
|
||||
);
|
||||
}
|
||||
|
||||
Future<Map<String, String>> generateLabelsHashMap(dynamic item) async {
|
||||
|
@ -588,7 +584,6 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage {
|
|||
required VehicleModel model,
|
||||
required FreCardIcon? icon,
|
||||
}) async {
|
||||
|
||||
final status = await generateStatusColorMap(item, 1);
|
||||
final buttons = await generateActionButtons(item);
|
||||
final labels = await generateLabelsHashMap(item);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:hub/components/atomic_components/shared_components_atoms/custom_input.dart';
|
||||
|
|
Loading…
Reference in New Issue