From 771ad2d5760ce6c6432194001d737b5c4e4caffd Mon Sep 17 00:00:00 2001 From: yaso Date: Wed, 23 Oct 2024 12:18:46 +0200 Subject: [PATCH] add gps loation field to add and update business details --- .../manage_business/business_details.dart | 44 +++++++++++++++++++ .../manage_business/profile_business_add.dart | 44 +++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/Frontend/patient_manager/lib/mih_packages/manage_business/business_details.dart b/Frontend/patient_manager/lib/mih_packages/manage_business/business_details.dart index 9b67e1fc..81131b09 100644 --- a/Frontend/patient_manager/lib/mih_packages/manage_business/business_details.dart +++ b/Frontend/patient_manager/lib/mih_packages/manage_business/business_details.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:patient_manager/mih_apis/mih_location_api.dart'; import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_loading_circle.dart'; import 'package:patient_manager/mih_components/mih_inputs_and_buttons/mih_dropdown_input.dart'; import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_error_message.dart'; @@ -45,6 +46,7 @@ class _BusinessDetailsState extends State { final accessController = TextEditingController(); final contactController = TextEditingController(); final emailController = TextEditingController(); + final locationController = TextEditingController(); late PlatformFile? selectedLogo = null; late PlatformFile? selectedSignature = null; @@ -179,6 +181,7 @@ class _BusinessDetailsState extends State { "${widget.arguments.signedInUser.app_id}/business_files/${logonameController.text}", "contact_no": contactController.text, "bus_email": emailController.text, + "gps_location": locationController.text, }), ); if (response.statusCode == 200) { @@ -284,6 +287,7 @@ class _BusinessDetailsState extends State { accessController.dispose(); contactController.dispose(); emailController.dispose(); + locationController.dispose(); _focusNode.dispose(); super.dispose(); } @@ -310,6 +314,7 @@ class _BusinessDetailsState extends State { oldLogoPath = widget.arguments.business!.logo_path; contactController.text = widget.arguments.business!.contact_no; emailController.text = widget.arguments.business!.bus_email; + locationController.text = widget.arguments.business!.gps_location; }); super.initState(); @@ -405,6 +410,45 @@ class _BusinessDetailsState extends State { }); }, ), + const SizedBox(height: 10.0), + Row( + children: [ + Flexible( + child: MIHTextField( + controller: locationController, + hintText: "Location", + editable: false, + required: false, + ), + ), + const SizedBox(width: 10.0), + SizedBox( + width: 80.0, + height: 50.0, + child: MIHButton( + buttonText: "Set", + buttonColor: MzanziInnovationHub.of(context)! + .theme + .secondaryColor(), + textColor: MzanziInnovationHub.of(context)! + .theme + .primaryColor(), + onTap: () { + MIHLocationAPI() + .getGPSPosition(context) + .then((position) { + if (position != null) { + setState(() { + locationController.text = + "${position.latitude}, ${position.longitude}"; + }); + } + }); + }, + ), + ), + ], + ), const SizedBox(height: 15.0), ], ), diff --git a/Frontend/patient_manager/lib/mih_packages/manage_business/profile_business_add.dart b/Frontend/patient_manager/lib/mih_packages/manage_business/profile_business_add.dart index b016fa3c..aece6a61 100644 --- a/Frontend/patient_manager/lib/mih_packages/manage_business/profile_business_add.dart +++ b/Frontend/patient_manager/lib/mih_packages/manage_business/profile_business_add.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:patient_manager/mih_apis/mih_location_api.dart'; import 'package:patient_manager/mih_components/mih_layout/mih_action.dart'; import 'package:patient_manager/mih_components/mih_layout/mih_body.dart'; import 'package:patient_manager/mih_components/mih_layout/mih_header.dart'; @@ -49,6 +50,7 @@ class _ProfileBusinessAddState extends State { final accessController = TextEditingController(); final contactController = TextEditingController(); final emailController = TextEditingController(); + final locationController = TextEditingController(); late PlatformFile selectedLogo; late PlatformFile selectedSignature; @@ -121,6 +123,7 @@ class _ProfileBusinessAddState extends State { "${widget.signedInUser.app_id}/business_files/${logonameController.text}", "contact_no": contactController.text, "bus_email": emailController.text, + "gps_location": locationController.text, }), ); if (response.statusCode == 201) { @@ -312,6 +315,46 @@ class _ProfileBusinessAddState extends State { }); }, ), + const SizedBox(height: 10.0), + Row( + children: [ + Flexible( + child: MIHTextField( + controller: locationController, + hintText: "Location", + editable: false, + required: false, + ), + ), + const SizedBox(width: 10.0), + SizedBox( + width: 80.0, + height: 50.0, + child: MIHButton( + buttonText: "Set", + buttonColor: MzanziInnovationHub.of(context)! + .theme + .secondaryColor(), + textColor: MzanziInnovationHub.of(context)! + .theme + .primaryColor(), + onTap: () { + MIHLocationAPI() + .getGPSPosition(context) + .then((position) { + if (position != null) { + setState(() { + locationController.text = + "${position.latitude}, ${position.longitude}"; + }); + } + }); + }, + ), + ), + ], + ), + const SizedBox(height: 15.0), Divider( color: @@ -417,6 +460,7 @@ class _ProfileBusinessAddState extends State { accessController.dispose(); contactController.dispose(); emailController.dispose(); + locationController.dispose(); _focusNode.dispose(); super.dispose(); }