location_selector.dart: triggerCallback
parent
e8702c713a
commit
3fa52d3e85
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:geocoding/geocoding.dart';
|
import 'package:geocoding/geocoding.dart';
|
||||||
import 'package:geolocator/geolocator.dart';
|
import 'package:geolocator/geolocator.dart';
|
||||||
import 'package:cofounderella/models/location.dart';
|
import '../models/location.dart';
|
||||||
|
|
||||||
class LocationSelector extends StatefulWidget {
|
class LocationSelector extends StatefulWidget {
|
||||||
final Function(MyLocation) onLocationChanged; // Callback function
|
final Function(MyLocation) onLocationChanged; // Callback function
|
||||||
|
@ -92,16 +92,7 @@ class LocationSelectorState extends State<LocationSelector> {
|
||||||
errorText = null;
|
errorText = null;
|
||||||
});
|
});
|
||||||
// location is found, trigger callback
|
// location is found, trigger callback
|
||||||
widget.onLocationChanged(MyLocation(
|
triggerCallback();
|
||||||
street: _street,
|
|
||||||
country: _country,
|
|
||||||
administrativeArea: _administrativeArea,
|
|
||||||
locality: _city,
|
|
||||||
subLocality: _subLocality,
|
|
||||||
postalCode: _postalCode,
|
|
||||||
latitude: _latitude,
|
|
||||||
longitude: _longitude,
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
setState(() {
|
setState(() {
|
||||||
// should placeMarks be empty return latitude and longitude anyway
|
// 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()
|
/// Resets the location data and calls setState()
|
||||||
void _resetLocationData(String errorMessage) {
|
void _resetLocationData(String errorMessage) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
@ -187,6 +191,7 @@ class LocationSelectorState extends State<LocationSelector> {
|
||||||
_latitude = position.latitude;
|
_latitude = position.latitude;
|
||||||
_longitude = position.longitude;
|
_longitude = position.longitude;
|
||||||
});
|
});
|
||||||
|
triggerCallback();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error getting current location: $e');
|
print('Error getting current location: $e');
|
||||||
|
|
Loading…
Reference in New Issue