From 3fa52d3e85a3ac2ef478d623d5e65df5d2b495f1 Mon Sep 17 00:00:00 2001 From: Rafael <1024481@stud.hs-mannheim.de> Date: Fri, 10 May 2024 23:17:35 +0200 Subject: [PATCH] location_selector.dart: triggerCallback --- lib/components/location_selector.dart | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/components/location_selector.dart b/lib/components/location_selector.dart index 02feda0..8cb1f6a 100644 --- a/lib/components/location_selector.dart +++ b/lib/components/location_selector.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:geocoding/geocoding.dart'; import 'package:geolocator/geolocator.dart'; -import 'package:cofounderella/models/location.dart'; +import '../models/location.dart'; class LocationSelector extends StatefulWidget { final Function(MyLocation) onLocationChanged; // Callback function @@ -92,16 +92,7 @@ class LocationSelectorState extends State { errorText = null; }); // location is found, trigger callback - widget.onLocationChanged(MyLocation( - street: _street, - country: _country, - administrativeArea: _administrativeArea, - locality: _city, - subLocality: _subLocality, - postalCode: _postalCode, - latitude: _latitude, - longitude: _longitude, - )); + triggerCallback(); } else { setState(() { // should placeMarks be empty return latitude and longitude anyway @@ -118,6 +109,19 @@ class LocationSelectorState extends State { } } + void triggerCallback(){ + widget.onLocationChanged(MyLocation( + street: _street, + country: _country, + administrativeArea: _administrativeArea, + locality: _city, + subLocality: _subLocality, + postalCode: _postalCode, + latitude: _latitude, + longitude: _longitude, + )); + } + /// Resets the location data and calls setState() void _resetLocationData(String errorMessage) { setState(() { @@ -187,6 +191,7 @@ class LocationSelectorState extends State { _latitude = position.latitude; _longitude = position.longitude; }); + triggerCallback(); } } catch (e) { print('Error getting current location: $e');