location_selector.dart: triggerCallback

master
Rafael 2024-05-10 23:17:35 +02:00
parent e8702c713a
commit 3fa52d3e85
1 changed files with 16 additions and 11 deletions

View File

@ -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<LocationSelector> {
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<LocationSelector> {
}
}
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<LocationSelector> {
_latitude = position.latitude;
_longitude = position.longitude;
});
triggerCallback();
}
} catch (e) {
print('Error getting current location: $e');