From 1cc481a83eb043d933aa37edbf3dcf7ab79195c0 Mon Sep 17 00:00:00 2001 From: jantunemesssias Date: Fri, 31 Jan 2025 15:28:53 -0300 Subject: [PATCH] checkpoint --- .../card_item_template_component_widget.dart | 20 ++-- .../vehicle_history_screen.dart | 101 ++++++++++-------- .../vehicle_model.dart | 25 ++--- 3 files changed, 77 insertions(+), 69 deletions(-) diff --git a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart index 049f78e4..ded91f90 100644 --- a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart +++ b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart @@ -1,4 +1,5 @@ import 'dart:collection'; +import 'dart:developer'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; @@ -68,9 +69,10 @@ class CardItemTemplateComponentWidget extends StatefulWidget { super.key, required this.labelsHashMap, required this.statusHashMap, - this.imagePath, - this.icon, - this.pin, + this.imagePath, + this.icon, + this.pin, + this.itemWidthFactor = 0.25, required this.onTapCardItemAction, }); @@ -79,6 +81,7 @@ class CardItemTemplateComponentWidget extends StatefulWidget { final String? imagePath; final FreCardIcon? icon; final FreCardPin? pin; + final double itemWidthFactor; final Future Function()? onTapCardItemAction; @override @@ -195,19 +198,22 @@ class _CardItemTemplateComponentWidgetState List _generateStatus() { double limitedBodyTextSize = LimitedFontSizeUtil.getBodyFontSize(context); - int statusCount = statusLinkedHashMap.length; - double itemWidthFactor = statusCount == 1 ? 0.5 : 0.25; - + return statusLinkedHashMap.expand((statusLinked) { + + log('statusHashMap: ${statusLinked.length}'); + return statusLinked.entries.map((entry) { final text = entry.key; final color = entry.value; + + return Tooltip( message: text, child: Container( padding: const EdgeInsets.all(5), - width: MediaQuery.of(context).size.width * itemWidthFactor, + width: MediaQuery.of(context).size.width * widget.itemWidthFactor, decoration: BoxDecoration( color: color, borderRadius: BorderRadius.circular(5), diff --git a/lib/pages/vehicles_on_the_property/vehicle_history_screen.dart b/lib/pages/vehicles_on_the_property/vehicle_history_screen.dart index 8a618838..97666429 100644 --- a/lib/pages/vehicles_on_the_property/vehicle_history_screen.dart +++ b/lib/pages/vehicles_on_the_property/vehicle_history_screen.dart @@ -91,57 +91,64 @@ class _VehicleHistoryScreenState extends State { '${FFLocalizations.of(context).getVariableText(ptText: "Tag", enText: "Tag")}:': uItem['tag'] ?? '', }; - final List?> statusHashMap = [ - await widget.model.generateStatusColorMap(uItem, 2) - ]; - Future onTapCardItemAction() async { - await showDialog( - useSafeArea: true, - context: context, - builder: (context) { - return Dialog( - alignment: Alignment.center, - child: FutureBuilder( - future: widget.model.buildVehicleDetails( - icon: isOwner is bool ? cardIcon : null, - item: uItem, - context: context, - model: widget.model, - ), - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - return snapshot.data ?? Container(); - } else { - return Center(child: CircularProgressIndicator()); - } - }, - )); - }, - ).whenComplete(() { - safeSetState(() { - _pageNumber = 1; - _wrap = []; - _future = - _fetchVisits().then((value) => value!.jsonBody['vehicles'] ?? []); - }); - }).catchError((e, s) { - DialogUtil.errorDefault(context); - LogUtil.requestAPIFailed( - "proccessRequest.php", "", "Consulta de Veículos", e, s); - safeSetState(() { - _hasData = false; - _loading = false; - }); - }); - return null; - return null; - } + final Map? statusHashMap = await widget.model.generateStatusColorMap(uItem, 2); + final List?> statusHashMapList = [await widget.model.generateStatusColorMap(uItem, 2)]; + Future onTapCardItemAction() async { + final widgetFuture = widget.model.buildVehicleDetails( + 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, + ); + }, + ).whenComplete(() { + 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; + }); + }); + } + final statusLinkedHashMap = statusHashMapList + .map((map) => LinkedHashMap.from(map ?? {})) + .toList(); + print('CardItemTemplateComponentWidget: ${statusLinkedHashMap}'); return CardItemTemplateComponentWidget( icon: cardIcon, labelsHashMap: labelsHashMap, - statusHashMap: statusHashMap, - onTapCardItemAction: onTapCardItemAction); + 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; + // } + } Future _fetchVisits() async { diff --git a/lib/pages/vehicles_on_the_property/vehicle_model.dart b/lib/pages/vehicles_on_the_property/vehicle_model.dart index 2a643014..5c828797 100644 --- a/lib/pages/vehicles_on_the_property/vehicle_model.dart +++ b/lib/pages/vehicles_on_the_property/vehicle_model.dart @@ -251,23 +251,14 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage { byLanguage(en, pt) => localization.getVariableText(enText: en, ptText: pt); - final preFixStatusMap = { - "ATI": { - "text": '', - "color": theme.success, - }, - "INA": { - "text": '', - "color": theme.accent2, - }, - + final preFixStatusMap = { "APR_CREATE": { "text": byLanguage('Awaiting', 'Aguardando'), - "color": theme.success, + "color": theme.warning, }, "APR_DELETE": { "text": byLanguage('Awaiting', 'Aguardando'), - "color": theme.error, + "color": theme.warning, }, "APR_UPDATE": { "text": byLanguage('Awaiting', 'Aguardando'), @@ -294,7 +285,7 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage { }, "APR_DELETE": { "text": byLanguage('Deletion', 'Exclusão'), - "color": theme.error, + "color": theme.warning, }, "APR_UPDATE": { "text": byLanguage('Update', 'Atualização'), @@ -321,12 +312,16 @@ mixin _VehicleHistoryScreenModel on _BaseVehiclePage { 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)) + // if (ownerStatusMap.containsKey(isOwner) && (status != 'ATI' || status != 'INA')) // ownerStatusMap[isOwner]!['text'] as String: ownerStatusMap[isOwner]!['color'] as Color }; - else return { + 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 }; }