From 268c4c897be0995593272de6f06c7881e92b188d Mon Sep 17 00:00:00 2001 From: jantunemesssias Date: Fri, 31 Jan 2025 14:30:52 -0300 Subject: [PATCH] WIP --- .vscode/launch.json | 29 + integration_test/app_test.dart | 7 - integration_test/auth_test.dart | 4 +- .../shared_components_atoms/custom_input.dart | 1 + .../media_upload_button.dart | 10 +- .../shared_components_atoms/toast.dart | 1 - ..._arrow_linked_locals_component_widget.dart | 1 + .../card_item_template_component_widget.dart | 134 +++- .../details_component_widget.dart | 42 +- ...item_details_template_component_model.dart | 1 - .../provisional_schedule_template_model.dart | 1 - ...siter_vistor_template_component_model.dart | 1 - ...iter_vistor_template_component_widget.dart | 2 +- .../view_visit_detail_model.dart | 1 - ...search_modal_template_component_model.dart | 1 - lib/core/meta/anotations.dart | 1 - .../backend/api_requests/api_calls.dart | 5 +- .../backend/schema/structs/device_struct.dart | 1 - .../widgets/provisional_filter_modal.dart | 1 - .../home/presentation/pages/about_system.dart | 2 + .../home/presentation/pages/home_page.dart | 1 - .../locals_local_data_source.dart | 2 +- .../local_profile/local_profile_widget.dart | 2 +- lib/features/local/utils/local_util.dart | 7 + .../menu/presentation/mappers/menu_entry.dart | 4 + .../widgets/menu_item/menu_item_button.dart | 17 +- .../license_local_data_source.dart | 2 +- .../module/data/models/license_model.dart | 1 - .../module/data/models/module_model.dart | 1 - .../module/domain/entities/base_module.dart | 2 - .../module/domain/entities/license.dart | 6 +- .../notification/deep_link_service.dart | 1 - .../profile_local_data_source.dart | 2 - .../storage/enums/database_storage_key.dart | 4 +- .../repositories/storage_repository_impl.dart | 1 - lib/flutter_flow/flutter_flow_widgets.dart | 1 - lib/initialization.dart | 1 - lib/main.dart | 1 - .../reception_page/reception_page_widget.dart | 1 - .../residents_on_the_property_screen.dart | 2 +- .../vehicle_history_screen.dart | 153 ++-- .../vehicle_model.dart | 695 ++++++++++-------- .../vehicles_on_the_property.dart | 5 +- lib/pages/visits_on_the_property/model.dart | 2 +- lib/shared/extensions/string_extensions.dart | 11 +- lib/shared/utils/text_util.dart | 4 +- 46 files changed, 713 insertions(+), 462 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..3bfc4b44 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "flutter-freaccesss-hub", + "request": "launch", + "type": "dart", + "args": [ + "--no-enable-impeller" + ] + }, + { + "name": "flutter-freaccesss-hub (profile mode)", + "request": "launch", + "type": "dart", + "flutterMode": "profile" + }, + { + "name": "flutter-freaccesss-hub (release mode)", + "request": "launch", + "type": "dart", + "flutterMode": "release" + } + ] +} \ No newline at end of file diff --git a/integration_test/app_test.dart b/integration_test/app_test.dart index 028840ca..fe7ff027 100644 --- a/integration_test/app_test.dart +++ b/integration_test/app_test.dart @@ -7,13 +7,10 @@ import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:go_router/go_router.dart'; import 'package:hub/components/molecular_components/throw_exception/throw_exception_widget.dart'; import 'package:hub/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart'; import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart'; import 'package:hub/components/templates_components/details_component/details_component_widget.dart'; -import 'package:hub/components/templates_components/forgot_password_template_component/forgot_password_template_component_widget.dart'; import 'package:hub/features/backend/api_requests/index.dart'; import 'package:hub/features/local/index.dart'; import 'package:hub/features/menu/index.dart'; @@ -23,14 +20,10 @@ import 'package:hub/features/notification/index.dart'; import 'package:hub/features/storage/index.dart'; import 'package:hub/flutter_flow/index.dart' as ff; import 'package:hub/flutter_flow/index.dart'; -import 'package:hub/initialization.dart'; import 'package:hub/main.dart'; -import 'package:hub/pages/forgot_password_page/forgot_password_screen.dart'; -import 'package:hub/pages/vehicles_on_the_property/vehicle_model.dart'; import 'package:hub/pages/vehicles_on_the_property/vehicles_on_the_property.dart'; import 'package:integration_test/integration_test.dart'; import 'package:material_symbols_icons/symbols.dart'; -import 'package:patrol/patrol.dart'; import 'package:flutter_web_plugins/url_strategy.dart'; import 'app_test.dart'; diff --git a/integration_test/auth_test.dart b/integration_test/auth_test.dart index e18a3916..b1105a8b 100644 --- a/integration_test/auth_test.dart +++ b/integration_test/auth_test.dart @@ -34,7 +34,7 @@ class AuthenticationTest { ); Map concat(String username, String domain, String password) { return { - 'emailTextFormField': '${username}@${domain}.test', + 'emailTextFormField': '$username@$domain.test', 'passwordTextFormField': password, }; } @@ -138,7 +138,7 @@ class AuthenticationTest { Map concat(String name, String username, String domain, String password) { return { 'nameTextFormField': name, - 'emailTextFormField': '${username}@${domain}.test', + 'emailTextFormField': '$username@$domain.test', 'passwordTextFormField': password, }; } diff --git a/lib/components/atomic_components/shared_components_atoms/custom_input.dart b/lib/components/atomic_components/shared_components_atoms/custom_input.dart index cac159f4..02634611 100644 --- a/lib/components/atomic_components/shared_components_atoms/custom_input.dart +++ b/lib/components/atomic_components/shared_components_atoms/custom_input.dart @@ -150,6 +150,7 @@ class _CustomInputUtilState extends State { maxLines: null, maxLength: widget.haveMaxLength ? widget.maxLength : null, keyboardType: widget.keyboardType, + inputFormatters: [ LengthLimitingTextInputFormatter(widget.maxLength), ], diff --git a/lib/components/atomic_components/shared_components_atoms/media_upload_button.dart b/lib/components/atomic_components/shared_components_atoms/media_upload_button.dart index ec1c5af3..c2424e70 100644 --- a/lib/components/atomic_components/shared_components_atoms/media_upload_button.dart +++ b/lib/components/atomic_components/shared_components_atoms/media_upload_button.dart @@ -33,7 +33,7 @@ class _MediaUploadButtonUtilState extends State { @override Widget build(BuildContext context) { double limitedInputTextSize = LimitedFontSizeUtil.getInputFontSize(context); - bool _isLoading = false; + bool isLoading = false; return Builder( builder: (context) { @@ -72,7 +72,7 @@ class _MediaUploadButtonUtilState extends State { child: GestureDetector( onTap: () async { setState(() { - _isLoading = true; + isLoading = true; }); final selectedMedia = await selectMediaWithSourceBottomSheet( @@ -120,7 +120,7 @@ class _MediaUploadButtonUtilState extends State { showUploadMessage(context, message); } else { setState(() { - _isLoading = false; + isLoading = false; }); final message = FFLocalizations.of(context) .getVariableText( @@ -131,7 +131,7 @@ class _MediaUploadButtonUtilState extends State { } } else { setState(() { - _isLoading = false; + isLoading = false; }); } }, @@ -150,7 +150,7 @@ class _MediaUploadButtonUtilState extends State { mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.center, children: [ - _isLoading + isLoading ? SizedBox( width: 30.0, height: 30.0, diff --git a/lib/components/atomic_components/shared_components_atoms/toast.dart b/lib/components/atomic_components/shared_components_atoms/toast.dart index 1be2a15e..30cc5332 100644 --- a/lib/components/atomic_components/shared_components_atoms/toast.dart +++ b/lib/components/atomic_components/shared_components_atoms/toast.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; -import 'package:hub/shared/utils/limited_text_size.dart'; class ToastUtil { static void showToast({ diff --git a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart index 141400e6..1993ba8e 100644 --- a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart +++ b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart @@ -195,6 +195,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State(local['CLI_NOME']), imagePath: _imagePath(local), + icon: null, labelsHashMap: _labelsHashMap(local), statusHashMap: [_statusHashMap(local)], onTapCardItemAction: () async { 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 9c96f384..049f78e4 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 @@ -12,18 +12,73 @@ import 'card_item_template_component_model.dart'; export 'card_item_template_component_model.dart'; +class FreCardIcon extends StatelessWidget { + final double height; + final double width; + final Icon icon; + + const FreCardIcon({ + super.key, + required this.height, + required this.width, + required this.icon, + }); + + @override + Widget build(BuildContext context) { + return SizedBox( + height: height, + width: width, + child: icon, + ); + } +} + +class FreCardPin extends StatelessWidget { + final double height; + final double width; + final Color color; + + const FreCardPin({ + super.key, + required this.height, + required this.width, + required this.color, + }); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.all(8.0), + child: Container( + height: height, + width: width, + decoration: BoxDecoration( + color: color, + shape: BoxShape.circle, + ), + ), + ); + } +} + + class CardItemTemplateComponentWidget extends StatefulWidget { const CardItemTemplateComponentWidget({ super.key, required this.labelsHashMap, required this.statusHashMap, - required this.imagePath, + this.imagePath, + this.icon, + this.pin, required this.onTapCardItemAction, }); final Map? labelsHashMap; final List?> statusHashMap; final String? imagePath; + final FreCardIcon? icon; + final FreCardPin? pin; final Future Function()? onTapCardItemAction; @override @@ -124,8 +179,25 @@ class _CardItemTemplateComponentWidgetState ); } + Widget _generateIcon() { + return Column( + children: [ + widget.icon!, + ], + ); + + } + + Widget _generatePin() { + return widget.pin!; + + } + List _generateStatus() { double limitedBodyTextSize = LimitedFontSizeUtil.getBodyFontSize(context); + int statusCount = statusLinkedHashMap.length; + double itemWidthFactor = statusCount == 1 ? 0.5 : 0.25; + return statusLinkedHashMap.expand((statusLinked) { return statusLinked.entries.map((entry) { final text = entry.key; @@ -135,7 +207,7 @@ class _CardItemTemplateComponentWidgetState message: text, child: Container( padding: const EdgeInsets.all(5), - width: MediaQuery.of(context).size.width * 0.25, + width: MediaQuery.of(context).size.width * itemWidthFactor, decoration: BoxDecoration( color: color, borderRadius: BorderRadius.circular(5), @@ -161,38 +233,54 @@ class _CardItemTemplateComponentWidgetState return LayoutBuilder( builder: (context, constraints) { if (constraints.maxWidth > 360) { - return Row( + return Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - ..._generateLabels(), - SizedBox(height: 3), - Wrap( - spacing: 8, - runSpacing: 4, - children: _generateStatus(), + Row( + mainAxisAlignment: MainAxisAlignment.end, + mainAxisSize: MainAxisSize.max, + children: [if(widget.pin != null) _generatePin()]), + Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + ..._generateLabels(), + + Wrap( + spacing: 8, + runSpacing: 4, + children: _generateStatus(), + ), + ] + .addToEnd(const SizedBox(height: 5)) + .divide(const SizedBox(height: 3)) + .addToStart(const SizedBox(height: 5)), ), - ] - .addToEnd(const SizedBox(height: 5)) - .divide(const SizedBox(height: 1)) - .addToStart(const SizedBox(height: 5)), - ), + ), + if(widget.icon != null) _generateIcon(), + if (widget.imagePath != null) _generateImage() + + ] + .addToEnd(const SizedBox(width: 10)) + .addToStart(const SizedBox(width: 10)), ), - if (widget.imagePath != null) _generateImage(), ] - .addToEnd(const SizedBox(width: 10)) - .addToStart(const SizedBox(width: 10)), + .addToStart(SizedBox(height: 5)) + .addToEnd(SizedBox(height: 5)), ); } else { return Column( mainAxisSize: MainAxisSize.min, children: [ if (widget.imagePath != null) _generateImage(), + if(widget.icon != null) _generateIcon(), Container( padding: const EdgeInsets.all(8), child: Column( diff --git a/lib/components/templates_components/details_component/details_component_widget.dart b/lib/components/templates_components/details_component/details_component_widget.dart index 6a4f5cec..b7c1c616 100644 --- a/lib/components/templates_components/details_component/details_component_widget.dart +++ b/lib/components/templates_components/details_component/details_component_widget.dart @@ -3,6 +3,7 @@ import 'dart:collection'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart'; import 'package:hub/components/templates_components/details_component/details_component_model.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; @@ -10,10 +11,11 @@ import 'package:hub/shared/utils/limited_text_size.dart'; class DetailsComponentWidget extends StatefulWidget { const DetailsComponentWidget({ - Key? key, + super.key, required this.labelsHashMap, required this.statusHashMap, this.imagePath, + this.icon, this.onTapCardItemAction, required this.buttons, }); @@ -23,6 +25,7 @@ class DetailsComponentWidget extends StatefulWidget { final String? imagePath; final Future Function()? onTapCardItemAction; final List? buttons; + final FreCardIcon? icon; @override State createState() => _DetailsComponentWidgetState(); @@ -95,6 +98,16 @@ class _DetailsComponentWidgetState extends State { useOldImageOnUrlChange: true, ), ), + if (widget.icon != null && widget.icon != '') + Container( + width: MediaQuery.of(context).size.width * 0.3, + height: MediaQuery.of(context).size.width * 0.3, + clipBehavior: Clip.antiAlias, + decoration: const BoxDecoration( + shape: BoxShape.circle, + ), + child: widget.icon!, + ), SizedBox(height: MediaQuery.of(context).size.height * 0.03), Row( children: statusLinkedHashMap.expand((linkedHashMap) { @@ -109,6 +122,7 @@ class _DetailsComponentWidgetState extends State { autofocus: false, canRequestFocus: false, readOnly: true, + initialValue: item.key, obscureText: false, decoration: InputDecoration( isDense: true, @@ -120,7 +134,7 @@ class _DetailsComponentWidgetState extends State { ), filled: true, fillColor: item.value, - labelText: item.key, + // labelText: item.key, labelStyle: FlutterFlowTheme.of(context) .labelMedium .override( @@ -156,16 +170,20 @@ class _DetailsComponentWidgetState extends State { color: FlutterFlowTheme.of(context).info, ), ), - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: - FlutterFlowTheme.of(context).bodyMediumFamily, - color: FlutterFlowTheme.of(context).info, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).bodyMediumFamily, + style: FlutterFlowTheme.of(context) + .labelMedium + .override( + fontFamily: FlutterFlowTheme.of(context) + .labelMediumFamily, + fontWeight: FontWeight.bold, + color: FlutterFlowTheme.of(context).info, + letterSpacing: 0.0, + useGoogleFonts: GoogleFonts.asMap().containsKey( + FlutterFlowTheme.of(context) + .labelMediumFamily, + ), + fontSize: limitedBodyFontSize, ), - fontSize: limitedBodyFontSize, - ), textAlign: TextAlign.center, maxLines: null, keyboardType: TextInputType.name, @@ -188,7 +206,7 @@ class _DetailsComponentWidgetState extends State { // return Text('key: $key, value: $value'); return TextFormField( readOnly: true, - initialValue: '$value', + initialValue: value, style: FlutterFlowTheme.of(context).bodyMedium.override( fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, diff --git a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart index 0fefa607..98d1c915 100644 --- a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart +++ b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart @@ -32,7 +32,6 @@ class LiberationHistoryItemDetailsTemplateComponentModel (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? ''; cliUUID = (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? ''; - ; } @override diff --git a/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart b/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart index c1e82767..7674b173 100644 --- a/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart +++ b/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart @@ -1,4 +1,3 @@ -import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:hub/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart'; diff --git a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart index acff7931..c3d0ee0b 100644 --- a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart +++ b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart @@ -140,7 +140,6 @@ class RegisiterVistorTemplateComponentModel (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? ''; cliUUID = (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? ''; - ; } @override diff --git a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart index 4a9c5ebe..b6c71aaf 100644 --- a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart +++ b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart @@ -35,7 +35,7 @@ class RegisiterVistorTemplateComponentWidget extends StatefulWidget { class _RegisiterVistorTemplateComponentWidgetState extends State { late RegisiterVistorTemplateComponentModel _model; - bool _isLoading = false; + final bool _isLoading = false; final scaffoldKey = GlobalKey(); bool _isVisitorRegistered = false; diff --git a/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart b/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart index d115ada3..b7628924 100644 --- a/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart +++ b/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart @@ -41,7 +41,6 @@ class ViewVisitDetailModel extends FlutterFlowModel { (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? ''; cliUUID = (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? ''; - ; } @override diff --git a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart index 17cc8baf..34b0bfc2 100644 --- a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart +++ b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart @@ -43,7 +43,6 @@ class VisitorSearchModalTemplateComponentModel (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? ''; cliUUID = (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? ''; - ; } @override diff --git a/lib/core/meta/anotations.dart b/lib/core/meta/anotations.dart index af721eaa..b75916be 100644 --- a/lib/core/meta/anotations.dart +++ b/lib/core/meta/anotations.dart @@ -1,4 +1,3 @@ -import 'package:meta/meta.dart'; class DeadCode { final String? desc; diff --git a/lib/features/backend/api_requests/api_calls.dart b/lib/features/backend/api_requests/api_calls.dart index 3219ac27..4b828e00 100644 --- a/lib/features/backend/api_requests/api_calls.dart +++ b/lib/features/backend/api_requests/api_calls.dart @@ -66,6 +66,7 @@ class PhpGroup extends Api { static GetResidentsByProperty getResidentsByProperty = GetResidentsByProperty(); static GetOpenedVisits getOpenedVisits = GetOpenedVisits(); + @override GetLicense getLicense = GetLicense(); static GetProvSchedules getProvSchedules = GetProvSchedules(); static RegisterVehicle registerVehicle = RegisterVehicle(); @@ -76,7 +77,7 @@ class PhpGroup extends Api { class CancelVehicle { Future call({ - required final String vehicleId, + required final int vehicleId, required final String licensePlate, required final String model, required final String color, @@ -118,7 +119,7 @@ class CancelVehicle { class DeleteVehicle { Future call({ - required final String vehicleId, + required final int vehicleId, required final String licensePlate, required final String model, required final String color, diff --git a/lib/features/backend/schema/structs/device_struct.dart b/lib/features/backend/schema/structs/device_struct.dart index db8a8896..3a765860 100644 --- a/lib/features/backend/schema/structs/device_struct.dart +++ b/lib/features/backend/schema/structs/device_struct.dart @@ -3,7 +3,6 @@ import 'package:hub/features/backend/index.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'index.dart'; class DeviceStruct extends BaseStruct { DeviceStruct({ diff --git a/lib/features/history/presentation/widgets/provisional_filter_modal.dart b/lib/features/history/presentation/widgets/provisional_filter_modal.dart index 44d0f538..bd46e621 100644 --- a/lib/features/history/presentation/widgets/provisional_filter_modal.dart +++ b/lib/features/history/presentation/widgets/provisional_filter_modal.dart @@ -1,4 +1,3 @@ -import 'dart:developer'; import 'package:flutter/material.dart'; diff --git a/lib/features/home/presentation/pages/about_system.dart b/lib/features/home/presentation/pages/about_system.dart index 78a409c2..4ba7d028 100644 --- a/lib/features/home/presentation/pages/about_system.dart +++ b/lib/features/home/presentation/pages/about_system.dart @@ -12,6 +12,8 @@ import 'package:package_info_plus/package_info_plus.dart'; import 'package:url_launcher/url_launcher.dart'; class AboutSystemPage extends StatefulWidget { + const AboutSystemPage({super.key}); + @override _AboutSystemPageState createState() => _AboutSystemPageState(); } diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 0d87ea9f..f2496866 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -4,7 +4,6 @@ import 'package:google_fonts/google_fonts.dart'; import 'package:hub/features/home/presentation/widgets/drawer_widget.dart'; import 'package:hub/features/local/index.dart'; import 'package:hub/features/menu/index.dart'; -import 'package:hub/features/storage/index.dart'; import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; diff --git a/lib/features/local/data/data_sources/locals_local_data_source.dart b/lib/features/local/data/data_sources/locals_local_data_source.dart index e259f2c3..c63aec38 100644 --- a/lib/features/local/data/data_sources/locals_local_data_source.dart +++ b/lib/features/local/data/data_sources/locals_local_data_source.dart @@ -58,7 +58,7 @@ class LocalsLocalDataSourceImpl implements LocalsLocalDataSource { }, conflictAlgorithm: ConflictAlgorithm.replace, ); - } catch (e, s) {} + } catch (e) {} } @override diff --git a/lib/features/local/presentation/widgets/local_profile/local_profile_widget.dart b/lib/features/local/presentation/widgets/local_profile/local_profile_widget.dart index 3cabc3e7..4215d501 100644 --- a/lib/features/local/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/features/local/presentation/widgets/local_profile/local_profile_widget.dart @@ -255,7 +255,7 @@ class _LocalProfileComponentWidgetState ), Tooltip( message: - valueOrDefault(' ' + state.ownerName, ''), + valueOrDefault(' ${state.ownerName}', ''), child: Text( valueOrDefault( state.ownerName.length > 30 diff --git a/lib/features/local/utils/local_util.dart b/lib/features/local/utils/local_util.dart index 88214b27..2a0b6d6b 100644 --- a/lib/features/local/utils/local_util.dart +++ b/lib/features/local/utils/local_util.dart @@ -95,6 +95,8 @@ class LocalUtil { try { await StorageHelper().set(LocalsStorageKey.whatsapp.key, jsonBody['whatsapp'] ?? false); await StorageHelper().set(LocalsStorageKey.provisional.key, jsonBody['provisional'] ?? false); + await StorageHelper().set(LocalsStorageKey.vehicleAutoApproval.key, jsonBody['vehicleAutoApproval'] ?? false); + await StorageHelper().set( LocalsStorageKey.pets.key, jsonBody['pet'] ?? false, @@ -118,6 +120,11 @@ class LocalUtil { await StorageHelper().set(LocalsStorageKey.petAmount.key, jsonBody['petAmountRegister']?.toString().isEmpty ?? true ? '0' : jsonBody['petAmountRegister'].toString()); + + await StorageHelper().set(LocalsStorageKey.vehicleAmountRegister.key, + jsonBody['vehicleAmountRegister']?.toString().isEmpty ?? true ? '0' : jsonBody['vehicleAmountRegister'].toString()); + + await StorageHelper().set(ProfileStorageKey.userName.key, jsonBody['visitado']['VDO_NOME'] ?? ''); await StorageHelper().set(ProfileStorageKey.userEmail.key, jsonBody['visitado']['VDO_EMAIL'] ?? ''); await StorageHelper().set(LocalsStorageKey.provisional.key, jsonBody['provisional'] ?? false); diff --git a/lib/features/menu/presentation/mappers/menu_entry.dart b/lib/features/menu/presentation/mappers/menu_entry.dart index 79c5e770..3398b0ae 100644 --- a/lib/features/menu/presentation/mappers/menu_entry.dart +++ b/lib/features/menu/presentation/mappers/menu_entry.dart @@ -7,9 +7,13 @@ import 'package:material_symbols_icons/symbols.dart'; enum MenuEntryType { Home, Drawer, Property } class MenuEntry implements BaseModule { + @override final String key; + @override final IconData icon; + @override final String name; + @override final String route; final List types; diff --git a/lib/features/menu/presentation/widgets/menu_item/menu_item_button.dart b/lib/features/menu/presentation/widgets/menu_item/menu_item_button.dart index c8f81e31..d5142c21 100644 --- a/lib/features/menu/presentation/widgets/menu_item/menu_item_button.dart +++ b/lib/features/menu/presentation/widgets/menu_item/menu_item_button.dart @@ -76,16 +76,15 @@ class _MenuButtonWidgetState extends State { mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (widget.icon != null) - Container( - alignment: Alignment.topLeft, - padding: const EdgeInsets.only(left: 8.0), - child: Icon( - widget.icon, - size: 24.0, - color: FlutterFlowTheme.of(context).primaryText, - ), + Container( + alignment: Alignment.topLeft, + padding: const EdgeInsets.only(left: 8.0), + child: Icon( + widget.icon, + size: 24.0, + color: FlutterFlowTheme.of(context).primaryText, ), + ), Flexible( child: Padding( padding: const EdgeInsets.only(left: 10.0), diff --git a/lib/features/module/data/data_sources/license_local_data_source.dart b/lib/features/module/data/data_sources/license_local_data_source.dart index cc377225..4cbe143f 100644 --- a/lib/features/module/data/data_sources/license_local_data_source.dart +++ b/lib/features/module/data/data_sources/license_local_data_source.dart @@ -94,7 +94,7 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { Future isNewVersion() async { final String? reponse = await StorageHelper().get(LocalsStorageKey.isNewVersion.key); - final bool isNewVersion = reponse.toBoolean(); + final bool isNewVersion = reponse.toBoolean; return isNewVersion; } diff --git a/lib/features/module/data/models/license_model.dart b/lib/features/module/data/models/license_model.dart index 48e215cc..df9e8f87 100644 --- a/lib/features/module/data/models/license_model.dart +++ b/lib/features/module/data/models/license_model.dart @@ -1,4 +1,3 @@ -import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'module_model.dart'; diff --git a/lib/features/module/data/models/module_model.dart b/lib/features/module/data/models/module_model.dart index e373edc3..17a2f23b 100644 --- a/lib/features/module/data/models/module_model.dart +++ b/lib/features/module/data/models/module_model.dart @@ -1,4 +1,3 @@ -import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'module_model.freezed.dart'; diff --git a/lib/features/module/domain/entities/base_module.dart b/lib/features/module/domain/entities/base_module.dart index 1cfbeef0..9e8759aa 100644 --- a/lib/features/module/domain/entities/base_module.dart +++ b/lib/features/module/domain/entities/base_module.dart @@ -1,6 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:hub/flutter_flow/internationalization.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; abstract class BaseModule { String get key; diff --git a/lib/features/module/domain/entities/license.dart b/lib/features/module/domain/entities/license.dart index 275776b9..130c7462 100644 --- a/lib/features/module/domain/entities/license.dart +++ b/lib/features/module/domain/entities/license.dart @@ -61,7 +61,7 @@ class License { } static Future _precessWpp() async { - final bool whatsapp = await StorageHelper().get(LocalsStorageKey.whatsapp.key).then((v) => v.toBoolean()); + final bool whatsapp = await StorageHelper().get(LocalsStorageKey.whatsapp.key).then((v) => v.toBoolean); if (whatsapp) return ModuleStatus.active.key; else @@ -69,7 +69,7 @@ class License { } static Future _processProvisional() async { - final bool provisional = await StorageHelper().get(LocalsStorageKey.provisional.key).then((v) => v.toBoolean()); + final bool provisional = await StorageHelper().get(LocalsStorageKey.provisional.key).then((v) => v.toBoolean); if (provisional) return ModuleStatus.active.key; else @@ -77,7 +77,7 @@ class License { } static Future _processPets() async { - final bool pets = await StorageHelper().get(LocalsStorageKey.pets.key).then((v) => v.toBoolean()); + final bool pets = await StorageHelper().get(LocalsStorageKey.pets.key).then((v) => v.toBoolean); if (pets) return ModuleStatus.active.key; else diff --git a/lib/features/notification/deep_link_service.dart b/lib/features/notification/deep_link_service.dart index cf7e13f2..374a8cd5 100644 --- a/lib/features/notification/deep_link_service.dart +++ b/lib/features/notification/deep_link_service.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:developer'; import 'package:app_links/app_links.dart'; import 'package:flutter/material.dart'; import 'package:hub/features/storage/index.dart'; diff --git a/lib/features/profile/data/data_sources/profile_local_data_source.dart b/lib/features/profile/data/data_sources/profile_local_data_source.dart index 8b0f9d1e..b1ee1258 100644 --- a/lib/features/profile/data/data_sources/profile_local_data_source.dart +++ b/lib/features/profile/data/data_sources/profile_local_data_source.dart @@ -1,8 +1,6 @@ import 'dart:developer'; -import 'package:hub/features/storage/constants/profile_constants.dart'; import 'package:hub/features/storage/index.dart'; -import 'package:hub/shared/constants/index.dart'; import 'package:sqflite/sqflite.dart'; diff --git a/lib/features/storage/enums/database_storage_key.dart b/lib/features/storage/enums/database_storage_key.dart index f4028646..92442313 100644 --- a/lib/features/storage/enums/database_storage_key.dart +++ b/lib/features/storage/enums/database_storage_key.dart @@ -34,7 +34,9 @@ enum LocalsStorageKey implements DatabaseStorageKey { panic('fre_panic'), person('fre_person'), requestOSNotification('fre_requestOSnotification'), - isNewVersion('fre_isNewVersion'); + isNewVersion('fre_isNewVersion'), + vehicleAutoApproval('fre_vehicleAutoApproval'), + vehicleAmountRegister('fre_vehicleAmountRegister'); final String key; diff --git a/lib/features/storage/repositories/storage_repository_impl.dart b/lib/features/storage/repositories/storage_repository_impl.dart index 30f3fd0d..1649b05e 100644 --- a/lib/features/storage/repositories/storage_repository_impl.dart +++ b/lib/features/storage/repositories/storage_repository_impl.dart @@ -1,7 +1,6 @@ import 'dart:developer'; import 'package:flutter/cupertino.dart'; -import 'package:hub/features/profile/data/data_sources/profile_local_data_source.dart'; import 'package:hub/features/storage/index.dart'; class StorageHelper implements StorageRepository { diff --git a/lib/flutter_flow/flutter_flow_widgets.dart b/lib/flutter_flow/flutter_flow_widgets.dart index 6845d783..122432eb 100644 --- a/lib/flutter_flow/flutter_flow_widgets.dart +++ b/lib/flutter_flow/flutter_flow_widgets.dart @@ -1,6 +1,5 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:flutter/material.dart'; -import 'package:auto_size_text/auto_size_text.dart'; class FFButtonOptions { const FFButtonOptions({ diff --git a/lib/initialization.dart b/lib/initialization.dart index 32198a5d..217044ec 100644 --- a/lib/initialization.dart +++ b/lib/initialization.dart @@ -1,4 +1,3 @@ -import 'dart:developer'; import 'package:app_tracking_transparency/app_tracking_transparency.dart'; import 'package:firebase_core/firebase_core.dart'; diff --git a/lib/main.dart b/lib/main.dart index 8db0f7c8..144a9fb5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -14,7 +14,6 @@ import 'package:hub/features/storage/index.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/utils/test_util.dart'; import 'package:responsive_framework/responsive_framework.dart'; import 'initialization.dart'; diff --git a/lib/pages/reception_page/reception_page_widget.dart b/lib/pages/reception_page/reception_page_widget.dart index e7d5718e..b56f8bfe 100644 --- a/lib/pages/reception_page/reception_page_widget.dart +++ b/lib/pages/reception_page/reception_page_widget.dart @@ -1,4 +1,3 @@ -import 'dart:developer'; import 'package:awesome_notifications/awesome_notifications.dart'; import 'package:flutter/material.dart'; diff --git a/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart b/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart index 8f63d8a2..64b61acf 100644 --- a/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart +++ b/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart @@ -29,7 +29,7 @@ class _ResidentsOnThePropertyState extends State late final ResidentsOnThePropertyModel model; late Future _future; - List _wrap = []; + final List _wrap = []; @override void initState() { 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 0e496a76..8a618838 100644 --- a/lib/pages/vehicles_on_the_property/vehicle_history_screen.dart +++ b/lib/pages/vehicles_on_the_property/vehicle_history_screen.dart @@ -18,6 +18,7 @@ class _VehicleHistoryScreenState extends State { int _pageNumber = 1; bool _hasData = false; bool _loading = false; + int count = 0; @override @@ -28,7 +29,8 @@ class _VehicleHistoryScreenState extends State { _future = _fetchVisits(); _scrollController = ScrollController() ..addListener(() { - if (_scrollController.position.atEdge && _scrollController.position.pixels != 0) { + if (_scrollController.position.atEdge && + _scrollController.position.pixels != 0) { _loadMore(); } }); @@ -53,59 +55,101 @@ class _VehicleHistoryScreenState extends State { ); } - String getRandomStatus() { - var statuses = ['ATI', 'INA', 'APR_CREATE', 'APR_DELETE', 'APR_UPDATE', 'AGU_CHANGE']; + String mockRandomMapStatusColor() { + var statuses = [ + 'ATI', + 'INA', + 'APR_CREATE', + 'APR_DELETE', + 'APR_UPDATE', + 'AGU_CHANGE' + ]; statuses.shuffle(); return statuses.first; } - Widget _item(BuildContext context, Map uItem) { - uItem['status'] = getRandomStatus(); - return CardItemTemplateComponentWidget( - imagePath: null, - labelsHashMap: { - '${FFLocalizations.of(context).getVariableText(ptText: "Placa", enText: "License Plate")}:': - uItem['licensePlate'] ?? '', - '${FFLocalizations.of(context).getVariableText(ptText: "Modelo", enText: "Model")}:': uItem['model'] ?? '', - '${FFLocalizations.of(context).getVariableText(ptText: "Tag", enText: "Tag")}:': uItem['tag'] ?? '', - }, - statusHashMap: [widget.model.generateStatusColorMap(uItem)], - onTapCardItemAction: () async { - await showDialog( - useSafeArea: true, - context: context, - builder: (context) { - return Dialog( - alignment: Alignment.center, - child: widget.model.buildVehicleDetails( + Future _item(BuildContext context, Map uItem) async { + // uItem['status'] = mockRandomMapStatusColor(); + final bool? isOwner = uItem['isOwnerVehicle']; + 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)); + } + final String? tag = uItem['tag']; + final bool containTag = tag.isNotNullAndEmpty; + final Map labelsHashMap = { + '${FFLocalizations.of(context).getVariableText(ptText: "Placa", enText: "License Plate")}:': + uItem['licensePlate'] ?? '', + '${FFLocalizations.of(context).getVariableText(ptText: "Modelo", enText: "Model")}:': + uItem['model'] ?? '', + '${FFLocalizations.of(context).getVariableText(ptText: "Proprietário", enText: "Owner")}:': + uItem['personName'] ?? '', + if (containTag) + '${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, - )); - }, - ).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; - }); + ), + 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; + } + + return CardItemTemplateComponentWidget( + icon: cardIcon, + labelsHashMap: labelsHashMap, + statusHashMap: statusHashMap, + onTapCardItemAction: onTapCardItemAction); } Future _fetchVisits() async { try { setState(() => _loading = true); - var response = await PhpGroup.getVehiclesByProperty.call(_pageNumber.toString()); + var response = + await PhpGroup.getVehiclesByProperty.call(_pageNumber.toString()); final List vehicles = response.jsonBody['vehicles'] ?? []; safeSetState(() => count = response.jsonBody['total_rows'] ?? 0); @@ -130,7 +174,8 @@ class _VehicleHistoryScreenState extends State { return null; } catch (e, s) { DialogUtil.errorDefault(context); - LogUtil.requestAPIFailed("proccessRequest.php", "", "Consulta de Veículo", e, s); + LogUtil.requestAPIFailed( + "proccessRequest.php", "", "Consulta de Veículo", e, s); setState(() { _hasData = false; _loading = false; @@ -149,7 +194,10 @@ class _VehicleHistoryScreenState extends State { @override Widget build(BuildContext context) { - late final limitedHeaderTextSize = LimitedFontSizeUtil.getHeaderFontSize(context); + late final limitedHeaderTextSize = + LimitedFontSizeUtil.getHeaderFontSize(context); + late final double limitedBodyTextSize = + LimitedFontSizeUtil.getBodyFontSize(context); return Column( mainAxisSize: MainAxisSize.max, @@ -192,13 +240,30 @@ class _VehicleHistoryScreenState extends State { return Padding( padding: const EdgeInsets.only(right: 30, top: 10), child: Text( - '', + (widget.model.amountRegister == '0' || + widget.model.amountRegister == null) + ? '' + : "${FFLocalizations.of(context).getVariableText(ptText: "Quantidade de Pets: ", enText: "Amount of Vehicles: ")}${widget.model.amountRegister}/$count", textAlign: TextAlign.right, + style: TextStyle( + fontFamily: 'Nunito', + fontSize: limitedBodyTextSize, + ), ), ); } else { Map item = _wrap[index - 1]; - return _item(context, item); + return FutureBuilder( + future: _item(context, item), + builder: (context, snapshot) { + if (snapshot.connectionState == + ConnectionState.done) { + return snapshot.data ?? Container(); + } else { + return Center(child: CircularProgressIndicator()); + } + }, + ); } }); }, diff --git a/lib/pages/vehicles_on_the_property/vehicle_model.dart b/lib/pages/vehicles_on_the_property/vehicle_model.dart index a279e972..2a643014 100644 --- a/lib/pages/vehicles_on_the_property/vehicle_model.dart +++ b/lib/pages/vehicles_on_the_property/vehicle_model.dart @@ -1,10 +1,13 @@ import 'dart:developer'; import 'package:flutter/material.dart'; +import 'package:hub/components/templates_components/card_item_template_component/card_item_template_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/storage/index.dart'; import 'package:hub/flutter_flow/index.dart'; import 'package:hub/pages/vehicles_on_the_property/vehicles_on_the_property.dart'; +import 'package:hub/shared/extensions/index.dart'; import 'package:hub/shared/utils/index.dart'; /// [VehicleModel] is a class that contains the business logic of the vehicle page. @@ -39,7 +42,7 @@ class VehicleModel extends FlutterFlowModel textFieldControllerModel = TextEditingController(); WidgetsBinding.instance.addPostFrameCallback((_) async { - vehicleAmountRegister = 0; + amountRegister = '0'; }); } @@ -57,7 +60,10 @@ class VehicleModel extends FlutterFlowModel final GlobalKey registerFormKey = GlobalKey(); final GlobalKey updateFormKey = GlobalKey(); - Future initAsync() async {} + Future initAsync() async { + + amountRegister = await StorageHelper().get(LocalsStorageKey.vehicleAmountRegister.key); + } bool isFormValid(BuildContext context) { if (registerFormKey.currentState == null) return false; @@ -75,7 +81,7 @@ mixin class _BaseVehiclePage { bool isEditing = false; String? vehicleId; ApiCallResponse? vehicleResponse; - late final vehicleAmountRegister; + String? amountRegister = '0'; VoidCallback? onUpdateVehicle; VoidCallback? onRegisterVehicle; @@ -93,9 +99,9 @@ mixin class _BaseVehiclePage { } // (ABC-1234) - final brazilianPlateRegex = RegExp(r'^[A-Z]{3}-\d{4}$'); + final brazilianPlateRegex = RegExp(r'^[A-Z]{3}\d{4}$'); // (ABC1D23) - final mercosurPlateRegex = RegExp(r'^[A-Z]{3}\d[A-Z]\d{2}$'); + final mercosurPlateRegex = RegExp(r'^[A-Z]{3}\d[A-Z0-9]\d{2}$'); if (!brazilianPlateRegex.hasMatch(value) && !mercosurPlateRegex.hasMatch(value)) { @@ -165,316 +171,6 @@ mixin class _BaseVehiclePage { } } -/// [_VehicleHistoryScreenModel] is a mixin that contains the business logic of the vehicle history page. -mixin _VehicleHistoryScreenModel on _BaseVehiclePage { - Map? generateStatusColorMap(dynamic uItem) { - final autoApproval = uItem['autoApproval']; - if (autoApproval == true) return null; - - final statusMap = { - "ATI": { - "text": FFLocalizations.of(context).getVariableText( - ptText: 'Ativo', - enText: 'Active', - ), - "color": FlutterFlowTheme.of(context).success, - }, - "INA": { - "text": FFLocalizations.of(context).getVariableText( - ptText: 'Inativo', - enText: 'Inactive', - ), - "color": FlutterFlowTheme.of(context).accent2, - }, - "APR_CREATE": { - "text": FFLocalizations.of(context).getVariableText( - ptText: 'Criando', - enText: 'Creating', - ), - "color": FlutterFlowTheme.of(context).success, - }, - "APR_DELETE": { - "text": FFLocalizations.of(context).getVariableText( - ptText: 'Deletando', - enText: 'Deleting', - ), - "color": FlutterFlowTheme.of(context).error, - }, - "APR_UPDATE": { - "text": FFLocalizations.of(context).getVariableText( - ptText: 'Atualizando', - enText: 'Updating', - ), - "color": FlutterFlowTheme.of(context).warning, - }, - "AGU_CHANGE": { - "text": FFLocalizations.of(context).getVariableText( - ptText: 'Aguardando', - enText: 'Waiting', - ), - "color": FlutterFlowTheme.of(context).accent2, - }, - }; - - final status = uItem['status']; - if (statusMap.containsKey(status)) { - return { - statusMap[status]!['text'] as String: - statusMap[status]!['color'] as Color, - }; - } - return {}; - } - - List? generateActionButtons(dynamic item) { - final Color iconButtonColor = FlutterFlowTheme.of(context).primaryText; - final FFButtonOptions buttonOptions = FFButtonOptions( - height: 40, - color: FlutterFlowTheme.of(context).primaryBackground, - elevation: 0, - textStyle: TextStyle( - color: FlutterFlowTheme.of(context).primaryText, - fontSize: LimitedFontSizeUtil.getNoResizeFont(context, 15), - ), - splashColor: FlutterFlowTheme.of(context).success, - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).primaryBackground, - width: 1, - ), - ); - - final updateText = FFLocalizations.of(context) - .getVariableText(ptText: 'Editar', enText: 'Edit'); - final updateIcon = Icon(Icons.edit, color: iconButtonColor); - Future updateOnPressed() async { - context.pop(); - isEditing = true; - - switchTab(1); - setEditForm(item); - } - - final cancelText = FFLocalizations.of(context) - .getVariableText(ptText: 'Cancelar', enText: 'Cancel'); - 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), - ); - } - - final deleteText = FFLocalizations.of(context) - .getVariableText(ptText: 'Excluir', enText: 'Delete'); - final deleteIcon = Icon(Icons.delete, color: iconButtonColor); - Future deleteOnPressed() async { - showAlertDialog( - context, - FFLocalizations.of(context).getVariableText( - ptText: 'Excluir Veículo', - enText: 'Delete Vehicle', - ), - FFLocalizations.of(context).getVariableText( - ptText: 'Você tem certeza que deseja excluir esse veículo?', - enText: 'Are you sure you want to delete this vehicle?', - ), - () async => await processDeleteRequest(item), - ); - } - - return [ - if (item['status'].contains('AGU')) - FFButtonWidget( - text: updateText, - icon: updateIcon, - onPressed: updateOnPressed, - options: buttonOptions, - ), - if (item['status'].contains('APR') || item['status'].contains('AGU')) - FFButtonWidget( - text: cancelText, - icon: cancelIcon, - onPressed: cancelOnPressed, - options: buttonOptions, - ), - if (item['status'].contains('ATI')) - FFButtonWidget( - text: deleteText, - icon: deleteIcon, - onPressed: deleteOnPressed, - options: buttonOptions, - ), - ]; - } - - Future processDeleteRequest(dynamic item) async { - int id = item['vehicleId']; - await PhpGroup.deleteVehicle.call( - vehicleId: item['vehicleId'], - licensePlate: item['licensePlate'], - model: item['model'], - color: item['color'], - ).then((value) { - context.pop(value); - context.pop(value); - - // ignore: unrelated_type_equality_checks - if (value == false) { - showSnackbar( - context, - FFLocalizations.of(context).getVariableText( - ptText: 'Erro ao excluir veículo', - enText: 'Error deleting vehicle', - ), - true, - ); - // ignore: unrelated_type_equality_checks - } else if (value == true) { - showSnackbar( - context, - FFLocalizations.of(context).getVariableText( - enText: 'Success deleting vehicle', - ptText: 'Succeso ao excluir veículo', - ), - false, - ); - } - }).catchError((err, stack) { - context.pop(); - showSnackbar( - context, - FFLocalizations.of(context).getVariableText( - enText: 'Error deleting vehicle', - ptText: 'Erro ao excluir veículo', - ), - true, - ); - }); - } - - Future processCancelRequest(String status, dynamic item) async { - late final ApiCallResponse value; - try { - switch (status) { - case 'APR_CREATE': - value = await processCancelDeleteRequest(item); - break; - case 'AGU_CHANGE': - value = await processCancelUpdateRequest(item); - break; - case 'APR_DELETE': - value = await processCancelCreateRequest(item); - break; - default: - break; - } - - context.pop(value); - context.pop(value); - - if (value.jsonBody['error'] == false) { - showSnackbar( - context, - FFLocalizations.of(context).getVariableText( - ptText: 'Erro ao cancelar solicitação', - enText: 'Error canceling request', - ), - true, - ); - } else if (value.jsonBody['error'] == true) { - showSnackbar( - context, - FFLocalizations.of(context).getVariableText( - enText: 'Success canceling request', - ptText: 'Succeso ao cancelar solicitação', - ), - false, - ); - } - } catch (err) { - context.pop(); - showSnackbar( - context, - FFLocalizations.of(context).getVariableText( - enText: 'Error canceling request', - ptText: 'Erro ao cancelar solicitação', - ), - true, - ); - } - } - - Future processCancelDeleteRequest(dynamic item) async { - return await PhpGroup.cancelVehicle.call( - vehicleId: item['vehicleId'], - licensePlate: item['licensePlate'], - model: item['model'], - color: item['color'], - ); - } - - Future processCancelUpdateRequest(dynamic item) async { - return await PhpGroup.deleteVehicle.call( - vehicleId: item['vehicleId'], - licensePlate: item['licensePlate'], - model: item['model'], - color: item['color'], - - ); - } - - Future processCancelCreateRequest(dynamic item) async { - return await PhpGroup.deleteVehicle.call( - vehicleId: item['vehicleId'], - licensePlate: item['licensePlate'], - model: item['model'], - color: item['color'], - ); - } - - Map generateLabelsHashMap(dynamic item) { - return { - if (item['model'] != null && item['model'] != '') - '${FFLocalizations.of(context).getVariableText(ptText: "Modelo", enText: "Model")}:': - item['model'].toString().toUpperCase(), - if (item['licensePlate'] != null && item['licensePlate'] != '') - '${FFLocalizations.of(context).getVariableText(ptText: "Placa", enText: "License Plate")}:': - item['licensePlate'].toString().toUpperCase(), - if (item['color'] != null && item['color'] != '') - '${FFLocalizations.of(context).getVariableText(ptText: "Cor", enText: "Color")}:': - item['color'].toString().toUpperCase(), - if (item['personName'] != null && item['personName'] != '') - '${FFLocalizations.of(context).getVariableText(ptText: "Proprietário", enText: "Owner")}:': - item['personName'].toString().toUpperCase(), - if (item['tag'] != null && item['tag'] != '') - '${FFLocalizations.of(context).getVariableText(ptText: "Tag", enText: "Tag")}:': - item['tag'].toString().toUpperCase(), - }; - } - - Widget buildVehicleDetails({ - required dynamic item, - required BuildContext context, - required VehicleModel model, - }) { - final status = generateStatusColorMap(item); - final buttons = generateActionButtons(item); - final labels = generateLabelsHashMap(item); - return DetailsComponentWidget( - buttons: buttons, - labelsHashMap: labels, - statusHashMap: [status], - ); - } -} /// [_VehicleRegisterScreenModel] is a mixin that contains the business logic of the vehicle register page. mixin _VehicleRegisterScreenModel on _BaseVehiclePage { @@ -540,3 +236,372 @@ mixin _VehicleUpdateScreenModel on _BaseVehiclePage { } } } + +/// [_VehicleHistoryScreenModel] is a mixin that contains the business logic of the vehicle history page. +mixin _VehicleHistoryScreenModel on _BaseVehiclePage { + + Future?> 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 = { + "ATI": { + "text": '', + "color": theme.success, + }, + "INA": { + "text": '', + "color": theme.accent2, + }, + + "APR_CREATE": { + "text": byLanguage('Awaiting', 'Aguardando'), + "color": theme.success, + }, + "APR_DELETE": { + "text": byLanguage('Awaiting', 'Aguardando'), + "color": theme.error, + }, + "APR_UPDATE": { + "text": byLanguage('Awaiting', 'Aguardando'), + "color": theme.warning, + }, + "AGU_CHANGE": { + "text": byLanguage('Awaiting', 'Aguardando'), + "color": theme.accent2, + }, + }; + final vehicleStatusMap = { + "ATI": { + "text": byLanguage('Active', 'Ativo'), + "color": theme.success, + }, + "INA": { + "text": byLanguage('Inactive', 'Inativo'), + "color": theme.accent2, + }, + + "APR_CREATE": { + "text": byLanguage('Creation', 'Criação'), + "color": theme.success, + }, + "APR_DELETE": { + "text": byLanguage('Deletion', 'Exclusão'), + "color": theme.error, + }, + "APR_UPDATE": { + "text": byLanguage('Update', 'Atualização'), + "color": theme.warning, + }, + "AGU_CHANGE": { + "text": byLanguage('Correction', 'Correção'), + "color": theme.accent2, + }, + }; + final ownerStatusMap = { + true: { + "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 { + preFixStatusMap[status]!['text'] as String: preFixStatusMap[status]!['color'] as Color, + vehicleStatusMap[status]!['text'] as String: vehicleStatusMap[status]!['color'] as Color, + // if (ownerStatusMap.containsKey(isOwner)) + // ownerStatusMap[isOwner]!['text'] as String: ownerStatusMap[isOwner]!['color'] as Color + }; + else return { + "${preFixStatusMap[status]!['text']} ${vehicleStatusMap[status]!['text']}": vehicleStatusMap[status]!['color'] as Color + }; + } + return {}; + } + + Future?> generateActionButtons(dynamic item) async { + final Color iconButtonColor = FlutterFlowTheme.of(context).primaryText; + final FFButtonOptions buttonOptions = FFButtonOptions( + height: 40, + color: FlutterFlowTheme.of(context).primaryBackground, + elevation: 0, + textStyle: TextStyle( + color: FlutterFlowTheme.of(context).primaryText, + fontSize: LimitedFontSizeUtil.getNoResizeFont(context, 15), + ), + splashColor: FlutterFlowTheme.of(context).success, + borderSide: BorderSide( + color: FlutterFlowTheme.of(context).primaryBackground, + width: 1, + ), + ); + + final updateText = FFLocalizations.of(context) + .getVariableText(ptText: 'Editar', enText: 'Edit'); + final updateIcon = Icon(Icons.edit, color: iconButtonColor); + Future updateOnPressed() async { + context.pop(); + isEditing = true; + + switchTab(1); + setEditForm(item); + } + + final cancelText = FFLocalizations.of(context) + .getVariableText(ptText: 'Cancelar', enText: 'Cancel'); + 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) + ); + } + + final deleteText = FFLocalizations.of(context) + .getVariableText(ptText: 'Excluir', enText: 'Delete'); + final deleteIcon = Icon(Icons.delete, color: iconButtonColor); + Future deleteOnPressed() async { + showAlertDialog( + context, + FFLocalizations.of(context).getVariableText( + ptText: 'Excluir Veículo', + enText: 'Delete Vehicle', + ), + FFLocalizations.of(context).getVariableText( + ptText: 'Você tem certeza que deseja excluir esse veículo?', + enText: 'Are you sure you want to delete this vehicle?', + ), + () async => await processDeleteRequest(item), + ); + } + + final bool containStatus = item['status'] == null; + final bool isOwnerVehicle = item['isOwnerVehicle']; + final bool isAGU = item['status'].contains('AGU'); + final bool isAPR = item['status'].contains('APR'); + final bool isATI = item['status'].contains('ATI'); + + if(containStatus) return [ + FFButtonWidget( + text: deleteText, + icon: deleteIcon, + onPressed: deleteOnPressed, + options: buttonOptions, + ), + ]; + + return [ + if (isAGU && isOwnerVehicle) + FFButtonWidget( + text: updateText, + icon: updateIcon, + onPressed: updateOnPressed, + options: buttonOptions, + ), + if ((isAPR || isAGU) && (isOwnerVehicle)) + FFButtonWidget( + text: cancelText, + icon: cancelIcon, + onPressed: cancelOnPressed, + options: buttonOptions, + ), + if (isATI && isOwnerVehicle) + FFButtonWidget( + text: deleteText, + icon: deleteIcon, + onPressed: deleteOnPressed, + options: buttonOptions, + ), + ]; + } + + Future 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) { + + + context.pop(value); + context.pop(value); + + // ignore: unrelated_type_equality_checks + if (value.jsonBody['error'] == true) { + final String errorMsg = value.jsonBody['error_msg']; + return showSnackbar( + context, + FFLocalizations.of(context).getVariableText( + ptText: errorMsg, + enText: 'Error deleting vehicle', + ), + true, + ); + // ignore: unrelated_type_equality_checks + } + return showSnackbar( + context, + FFLocalizations.of(context).getVariableText( + enText: 'Success deleting vehicle', + ptText: 'Succeso ao excluir veículo', + ), + false, + ); + + }).catchError((err, stack) { + context.pop(); + return showSnackbar( + context, + FFLocalizations.of(context).getVariableText( + enText: 'Error deleting vehicle', + ptText: 'Erro ao excluir veículo', + ), + true, + ); + }); + } + + Future processCancelRequest(String status, dynamic item) async { + late final ApiCallResponse value; + try { + switch (status) { + case 'APR_CREATE': + value = await processCancelDeleteRequest(item); + break; + case 'AGU_CHANGE': + value = await processCancelUpdateRequest(item); + break; + case 'APR_DELETE': + value = await processCancelCreateRequest(item); + break; + default: + break; + } + + context.pop(value); + context.pop(value); + + if (value.jsonBody['error'] == true) { + final String errorMsg = value.jsonBody['error_msg'] ; + return showSnackbar( + context, + FFLocalizations.of(context).getVariableText( + ptText: errorMsg, + enText: 'Error canceling request', + ), + true, + ); + } + return showSnackbar( + context, + FFLocalizations.of(context).getVariableText( + enText: 'Success canceling request', + ptText: 'Succeso ao cancelar solicitação', + ), + false, + ); + + } catch (err) { + context.pop(); + return showSnackbar( + context, + FFLocalizations.of(context).getVariableText( + enText: 'Error canceling request', + ptText: 'Erro ao cancelar solicitação', + ), + true, + ); + } + } + + Future processCancelDeleteRequest(dynamic item) async { + return await PhpGroup.deleteVehicle.call( + vehicleId: item['vehicleId'], + licensePlate: item['licensePlate'], + model: item['model'], + color: item['color'], + ); + } + + Future processCancelUpdateRequest(dynamic item) async { + return await PhpGroup.deleteVehicle.call( + vehicleId: item['vehicleId'], + licensePlate: item['licensePlate'], + model: item['model'], + color: item['color'], + + ); + } + + Future processCancelCreateRequest(dynamic item) async { + return await PhpGroup.deleteVehicle.call( + vehicleId: item['vehicleId'], + licensePlate: item['licensePlate'], + model: item['model'], + color: item['color'], + ); + } + + Future> generateLabelsHashMap(dynamic item) async { + return { + if (item['model'] != null && item['model'] != '') + '${FFLocalizations.of(context).getVariableText(ptText: "Modelo", enText: "Model")}:': + item['model'].toString().toUpperCase(), + if (item['licensePlate'] != null && item['licensePlate'] != '') + '${FFLocalizations.of(context).getVariableText(ptText: "Placa", enText: "License Plate")}:': + item['licensePlate'].toString().toUpperCase(), + if (item['color'] != null && item['color'] != '') + '${FFLocalizations.of(context).getVariableText(ptText: "Cor", enText: "Color")}:': + item['color'].toString().toUpperCase(), + if (item['personName'] != null && item['personName'] != '') + '${FFLocalizations.of(context).getVariableText(ptText: "Proprietário", enText: "Owner")}:': + item['personName'].toString().toUpperCase(), + if (item['tag'] != null && item['tag'] != '') + '${FFLocalizations.of(context).getVariableText(ptText: "Tag", enText: "Tag")}:': + item['tag'].toString().toUpperCase(), + }; + } + + Future buildVehicleDetails({ + required dynamic item, + required BuildContext context, + required VehicleModel model, + required FreCardIcon? icon, + }) async { + + final status = await generateStatusColorMap(item, 1); + final buttons = await generateActionButtons(item); + final labels = await generateLabelsHashMap(item); + return DetailsComponentWidget( + icon: icon, + buttons: buttons, + labelsHashMap: labels, + statusHashMap: [status], + ); + } +} diff --git a/lib/pages/vehicles_on_the_property/vehicles_on_the_property.dart b/lib/pages/vehicles_on_the_property/vehicles_on_the_property.dart index c96108fb..0d989e1c 100644 --- a/lib/pages/vehicles_on_the_property/vehicles_on_the_property.dart +++ b/lib/pages/vehicles_on_the_property/vehicles_on_the_property.dart @@ -1,4 +1,3 @@ -import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -8,11 +7,9 @@ import 'package:hub/components/atomic_components/shared_components_atoms/tabview import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart'; import 'package:hub/features/backend/index.dart'; import 'package:hub/features/module/index.dart'; -import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; -import 'package:hub/flutter_flow/flutter_flow_theme.dart'; -import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/index.dart'; import 'package:hub/pages/vehicles_on_the_property/vehicle_model.dart'; +import 'package:hub/shared/extensions/index.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/license_util.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; diff --git a/lib/pages/visits_on_the_property/model.dart b/lib/pages/visits_on_the_property/model.dart index ef521047..4e15ebef 100644 --- a/lib/pages/visits_on_the_property/model.dart +++ b/lib/pages/visits_on_the_property/model.dart @@ -80,7 +80,7 @@ class VisitsModel extends FlutterFlowModel { ), }), imagePath: - 'https://freaccess.com.br/freaccess/getImage.php?devUUID=${devUUID}&cliID=${cliUUID}&atividade=getFoto&Documento=${item['VDO_DOCUMENTO']}&tipo=E', + 'https://freaccess.com.br/freaccess/getImage.php?devUUID=$devUUID&cliID=$cliUUID&atividade=getFoto&Documento=${item['VDO_DOCUMENTO']}&tipo=E', statusHashMap: [ Map.from({ if (item['VTA_FIXA'] != null) diff --git a/lib/shared/extensions/string_extensions.dart b/lib/shared/extensions/string_extensions.dart index 32290e61..67cf03db 100644 --- a/lib/shared/extensions/string_extensions.dart +++ b/lib/shared/extensions/string_extensions.dart @@ -1,16 +1,16 @@ extension StringNullableExtensions on String? { - bool toBoolean() { + bool get toBoolean { if (this == null) return false; return this!.toLowerCase() == 'true'; } - bool isNullOrEmpty() { + bool get isNullOrEmpty { if (this == null) return true; if (this == '') return true; return false; } - bool isNotNullAndEmpty() { + bool get isNotNullAndEmpty { if (this == null) return false; if (this == '') return false; return true; @@ -18,8 +18,9 @@ extension StringNullableExtensions on String? { } extension StringExtensions on String { - bool toBoolean() { - return this.toLowerCase() == 'true'; + bool get toBoolean { + + return toLowerCase() == 'true'; } } diff --git a/lib/shared/utils/text_util.dart b/lib/shared/utils/text_util.dart index d2876a0b..00d40ef9 100644 --- a/lib/shared/utils/text_util.dart +++ b/lib/shared/utils/text_util.dart @@ -6,11 +6,11 @@ class TextUtil extends StatelessWidget { final TextAlign? textAlign; const TextUtil({ - Key? key, + super.key, required this.text, this.style, this.textAlign, - }) : super(key: key); + }); @override Widget build(BuildContext context) {