location_selector.dart: triggerCallback
parent
e8702c713a
commit
3fa52d3e85
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue