map: fixed collection refresh when source initializes

This commit is contained in:
Thibault Deckers 2024-10-04 14:44:09 +02:00
parent 1864f77866
commit 7fabb059b7
3 changed files with 11 additions and 12 deletions

View file

@ -7,6 +7,7 @@ import 'package:aves/model/entry/extensions/location.dart';
import 'package:aves/model/entry/sort.dart'; import 'package:aves/model/entry/sort.dart';
import 'package:aves/model/settings/enums/map_style.dart'; import 'package:aves/model/settings/enums/map_style.dart';
import 'package:aves/model/settings/settings.dart'; import 'package:aves/model/settings/settings.dart';
import 'package:aves/model/source/collection_lens.dart';
import 'package:aves/ref/poi.dart'; import 'package:aves/ref/poi.dart';
import 'package:aves/services/common/services.dart'; import 'package:aves/services/common/services.dart';
import 'package:aves/theme/durations.dart'; import 'package:aves/theme/durations.dart';
@ -32,8 +33,8 @@ import 'package:provider/provider.dart';
class GeoMap extends StatefulWidget { class GeoMap extends StatefulWidget {
final AvesMapController? controller; final AvesMapController? controller;
final Listenable? collectionListenable; final CollectionLens? collection;
final List<AvesEntry> entries; final List<AvesEntry>? entries;
final Size availableSize; final Size availableSize;
final LatLng? initialCenter; final LatLng? initialCenter;
final double? initialZoom; final double? initialZoom;
@ -59,8 +60,8 @@ class GeoMap extends StatefulWidget {
const GeoMap({ const GeoMap({
super.key, super.key,
this.controller, this.controller,
this.collectionListenable, this.collection,
required this.entries, this.entries,
required this.availableSize, required this.availableSize,
this.initialCenter, this.initialCenter,
this.initialZoom, this.initialZoom,
@ -73,7 +74,7 @@ class GeoMap extends StatefulWidget {
this.onMarkerTap, this.onMarkerTap,
this.onMarkerLongPress, this.onMarkerLongPress,
this.openMapPage, this.openMapPage,
}); }) : assert(collection != null || entries != null);
@override @override
State<GeoMap> createState() => _GeoMapState(); State<GeoMap> createState() => _GeoMapState();
@ -92,7 +93,7 @@ class _GeoMapState extends State<GeoMap> {
Fluster<GeoEntry<AvesEntry>>? _slowMarkerCluster; Fluster<GeoEntry<AvesEntry>>? _slowMarkerCluster;
final AChangeNotifier _clusterChangeNotifier = AChangeNotifier(); final AChangeNotifier _clusterChangeNotifier = AChangeNotifier();
List<AvesEntry> get entries => widget.entries; List<AvesEntry> get entries => widget.collection?.sortedEntries ?? widget.entries ?? [];
// cap initial zoom to avoid a zoom change // cap initial zoom to avoid a zoom change
// when toggling overlay on Google map initial state // when toggling overlay on Google map initial state
@ -121,7 +122,7 @@ class _GeoMapState extends State<GeoMap> {
} }
void _registerWidget(GeoMap widget) { void _registerWidget(GeoMap widget) {
widget.collectionListenable?.addListener(_onCollectionChanged); widget.collection?.addListener(_onCollectionChanged);
final controller = widget.controller; final controller = widget.controller;
if (controller != null) { if (controller != null) {
_subscriptions.add(controller.markerLocationChanges.listen((event) => _onCollectionChanged())); _subscriptions.add(controller.markerLocationChanges.listen((event) => _onCollectionChanged()));
@ -129,7 +130,7 @@ class _GeoMapState extends State<GeoMap> {
} }
void _unregisterWidget(GeoMap widget) { void _unregisterWidget(GeoMap widget) {
widget.collectionListenable?.removeListener(_onCollectionChanged); widget.collection?.removeListener(_onCollectionChanged);
_subscriptions _subscriptions
..forEach((sub) => sub.cancel()) ..forEach((sub) => sub.cancel())
..clear(); ..clear();

View file

@ -135,8 +135,7 @@ class _ContentState extends State<_Content> with SingleTickerProviderStateMixin
navigationButton: MapNavigationButton.back, navigationButton: MapNavigationButton.back,
child: GeoMap( child: GeoMap(
controller: _mapController, controller: _mapController,
collectionListenable: openingCollection, collection: openingCollection,
entries: openingCollection?.sortedEntries ?? [],
availableSize: MediaQuery.sizeOf(context), availableSize: MediaQuery.sizeOf(context),
initialCenter: widget.initialLocation, initialCenter: widget.initialLocation,
isAnimatingNotifier: _isPageAnimatingNotifier, isAnimatingNotifier: _isPageAnimatingNotifier,

View file

@ -272,8 +272,7 @@ class _ContentState extends State<_Content> with SingleTickerProviderStateMixin
// key is expected by test driver // key is expected by test driver
key: const Key('map_view'), key: const Key('map_view'),
controller: _mapController, controller: _mapController,
collectionListenable: openingCollection, collection: openingCollection,
entries: openingCollection.sortedEntries,
availableSize: MediaQuery.sizeOf(context), availableSize: MediaQuery.sizeOf(context),
initialCenter: widget.initialLocation ?? widget.initialEntry?.latLng ?? widget.overlayEntry?.center, initialCenter: widget.initialLocation ?? widget.initialEntry?.latLng ?? widget.overlayEntry?.center,
initialZoom: widget.initialZoom, initialZoom: widget.initialZoom,