map: fixed collection refresh when source initializes
This commit is contained in:
parent
1864f77866
commit
7fabb059b7
3 changed files with 11 additions and 12 deletions
|
@ -7,6 +7,7 @@ import 'package:aves/model/entry/extensions/location.dart';
|
|||
import 'package:aves/model/entry/sort.dart';
|
||||
import 'package:aves/model/settings/enums/map_style.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/services/common/services.dart';
|
||||
import 'package:aves/theme/durations.dart';
|
||||
|
@ -32,8 +33,8 @@ import 'package:provider/provider.dart';
|
|||
|
||||
class GeoMap extends StatefulWidget {
|
||||
final AvesMapController? controller;
|
||||
final Listenable? collectionListenable;
|
||||
final List<AvesEntry> entries;
|
||||
final CollectionLens? collection;
|
||||
final List<AvesEntry>? entries;
|
||||
final Size availableSize;
|
||||
final LatLng? initialCenter;
|
||||
final double? initialZoom;
|
||||
|
@ -59,8 +60,8 @@ class GeoMap extends StatefulWidget {
|
|||
const GeoMap({
|
||||
super.key,
|
||||
this.controller,
|
||||
this.collectionListenable,
|
||||
required this.entries,
|
||||
this.collection,
|
||||
this.entries,
|
||||
required this.availableSize,
|
||||
this.initialCenter,
|
||||
this.initialZoom,
|
||||
|
@ -73,7 +74,7 @@ class GeoMap extends StatefulWidget {
|
|||
this.onMarkerTap,
|
||||
this.onMarkerLongPress,
|
||||
this.openMapPage,
|
||||
});
|
||||
}) : assert(collection != null || entries != null);
|
||||
|
||||
@override
|
||||
State<GeoMap> createState() => _GeoMapState();
|
||||
|
@ -92,7 +93,7 @@ class _GeoMapState extends State<GeoMap> {
|
|||
Fluster<GeoEntry<AvesEntry>>? _slowMarkerCluster;
|
||||
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
|
||||
// when toggling overlay on Google map initial state
|
||||
|
@ -121,7 +122,7 @@ class _GeoMapState extends State<GeoMap> {
|
|||
}
|
||||
|
||||
void _registerWidget(GeoMap widget) {
|
||||
widget.collectionListenable?.addListener(_onCollectionChanged);
|
||||
widget.collection?.addListener(_onCollectionChanged);
|
||||
final controller = widget.controller;
|
||||
if (controller != null) {
|
||||
_subscriptions.add(controller.markerLocationChanges.listen((event) => _onCollectionChanged()));
|
||||
|
@ -129,7 +130,7 @@ class _GeoMapState extends State<GeoMap> {
|
|||
}
|
||||
|
||||
void _unregisterWidget(GeoMap widget) {
|
||||
widget.collectionListenable?.removeListener(_onCollectionChanged);
|
||||
widget.collection?.removeListener(_onCollectionChanged);
|
||||
_subscriptions
|
||||
..forEach((sub) => sub.cancel())
|
||||
..clear();
|
||||
|
|
|
@ -135,8 +135,7 @@ class _ContentState extends State<_Content> with SingleTickerProviderStateMixin
|
|||
navigationButton: MapNavigationButton.back,
|
||||
child: GeoMap(
|
||||
controller: _mapController,
|
||||
collectionListenable: openingCollection,
|
||||
entries: openingCollection?.sortedEntries ?? [],
|
||||
collection: openingCollection,
|
||||
availableSize: MediaQuery.sizeOf(context),
|
||||
initialCenter: widget.initialLocation,
|
||||
isAnimatingNotifier: _isPageAnimatingNotifier,
|
||||
|
|
|
@ -272,8 +272,7 @@ class _ContentState extends State<_Content> with SingleTickerProviderStateMixin
|
|||
// key is expected by test driver
|
||||
key: const Key('map_view'),
|
||||
controller: _mapController,
|
||||
collectionListenable: openingCollection,
|
||||
entries: openingCollection.sortedEntries,
|
||||
collection: openingCollection,
|
||||
availableSize: MediaQuery.sizeOf(context),
|
||||
initialCenter: widget.initialLocation ?? widget.initialEntry?.latLng ?? widget.overlayEntry?.center,
|
||||
initialZoom: widget.initialZoom,
|
||||
|
|
Loading…
Reference in a new issue