map: fixed address update on layer or orientation change

This commit is contained in:
Thibault Deckers 2021-09-27 17:59:30 +09:00
parent b720f65754
commit c5942ba344
2 changed files with 18 additions and 7 deletions

View file

@ -153,6 +153,8 @@ class _EntryLeafletMapState extends State<EntryLeafletMap> with TickerProviderSt
zoom: bounds.zoom,
minZoom: widget.minZoom,
maxZoom: widget.maxZoom,
// TODO TLAD [map] as of flutter_map v0.14.0, `doubleTapZoom` does not move when zoom is already maximal
// this could be worked around with https://github.com/fleaflet/flutter_map/pull/960
interactiveFlags: interactive ? InteractiveFlag.all : InteractiveFlag.none,
onTap: (tapPosition, point) => widget.onMapTap?.call(),
controller: _leafletMapController,

View file

@ -83,16 +83,17 @@ class _AddressRow extends StatefulWidget {
class _AddressRowState extends State<_AddressRow> {
final ValueNotifier<String?> _addressLineNotifier = ValueNotifier(null);
@override
void initState() {
super.initState();
_updateAddress();
}
@override
void didUpdateWidget(covariant _AddressRow oldWidget) {
super.didUpdateWidget(oldWidget);
final entry = widget.entry;
if (oldWidget.entry != entry) {
_getAddressLine(entry).then((addressLine) {
if (mounted && entry == widget.entry) {
_addressLineNotifier.value = addressLine;
}
});
if (oldWidget.entry != widget.entry) {
_updateAddress();
}
}
@ -136,6 +137,14 @@ class _AddressRowState extends State<_AddressRow> {
);
}
Future<void> _updateAddress() async {
final entry = widget.entry;
final addressLine = await _getAddressLine(entry);
if (mounted && entry == widget.entry) {
_addressLineNotifier.value = addressLine;
}
}
Future<String?> _getAddressLine(AvesEntry? entry) async {
if (entry != null && await availability.canLocatePlaces) {
final addresses = await GeocodingService.getAddress(entry.latLng!, entry.geocoderLocale);