|
@@ -1,5 +1,6 @@
|
|
|
import "dart:async";
|
|
|
|
|
|
+import "package:collection/collection.dart";
|
|
|
import "package:flutter/material.dart";
|
|
|
import "package:photos/core/constants.dart";
|
|
|
import "package:photos/core/event_bus.dart";
|
|
@@ -33,14 +34,22 @@ class _LocationTagStateProviderState extends State<LocationTagStateProvider> {
|
|
|
final Debouncer _selectedRadiusDebouncer =
|
|
|
Debouncer(const Duration(milliseconds: 300));
|
|
|
late final StreamSubscription _locTagEntityListener;
|
|
|
+ late final List<double> _radiusValues;
|
|
|
+
|
|
|
@override
|
|
|
void initState() {
|
|
|
_locationTagEntity = widget.locationTagEntity;
|
|
|
_centerPoint = widget.centerPoint;
|
|
|
assert(_centerPoint != null || _locationTagEntity != null);
|
|
|
_centerPoint = _locationTagEntity?.item.centerPoint ?? _centerPoint!;
|
|
|
+
|
|
|
+ ///If the location tag has a custom radius value, we add the custom radius
|
|
|
+ ///value to the list of default radius values only for this location tag and
|
|
|
+ ///keep it in the state of this widget.
|
|
|
+ _radiusValues = _getRadiusValuesOfLocTag(_locationTagEntity?.item.radius);
|
|
|
_selectedRaduisIndex =
|
|
|
- _locationTagEntity?.item.radiusIndex ?? defaultRadiusValueIndex;
|
|
|
+ _locationTagEntity?.item.radiusIndex(_radiusValues) ??
|
|
|
+ defaultRadiusValueIndex;
|
|
|
_locTagEntityListener =
|
|
|
Bus.instance.on<LocationTagUpdatedEvent>().listen((event) {
|
|
|
_locationTagUpdateListener(event);
|
|
@@ -60,7 +69,8 @@ class _LocationTagStateProviderState extends State<LocationTagStateProvider> {
|
|
|
//Update state when locationTag is updated.
|
|
|
setState(() {
|
|
|
final updatedLocTagEntity = event.updatedLocTagEntities!.first;
|
|
|
- _selectedRaduisIndex = updatedLocTagEntity.item.radiusIndex;
|
|
|
+ _selectedRaduisIndex =
|
|
|
+ updatedLocTagEntity.item.radiusIndex(_radiusValues);
|
|
|
_centerPoint = updatedLocTagEntity.item.centerPoint;
|
|
|
_locationTagEntity = updatedLocTagEntity;
|
|
|
});
|
|
@@ -87,6 +97,32 @@ class _LocationTagStateProviderState extends State<LocationTagStateProvider> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void _updateRadiusValues(List<double> radiusValues) {
|
|
|
+ if (mounted) {
|
|
|
+ setState(() {
|
|
|
+ for (double radiusValue in radiusValues) {
|
|
|
+ if (!_radiusValues.contains(radiusValue)) {
|
|
|
+ _radiusValues.add(radiusValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _radiusValues.sort();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ///Returns the list of radius values for the location tag entity. If radius of
|
|
|
+ ///the location tag is not present in the default list, it returns the list
|
|
|
+ ///with the custom radius value.
|
|
|
+ List<double> _getRadiusValuesOfLocTag(double? radiusOfLocTag) {
|
|
|
+ final radiusValues = <double>[...defaultRadiusValues];
|
|
|
+ if (radiusOfLocTag != null &&
|
|
|
+ !defaultRadiusValues.contains(radiusOfLocTag)) {
|
|
|
+ radiusValues.add(radiusOfLocTag);
|
|
|
+ radiusValues.sort();
|
|
|
+ }
|
|
|
+ return radiusValues;
|
|
|
+ }
|
|
|
+
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
return InheritedLocationTagData(
|
|
@@ -95,6 +131,8 @@ class _LocationTagStateProviderState extends State<LocationTagStateProvider> {
|
|
|
_updateSelectedIndex,
|
|
|
_locationTagEntity,
|
|
|
_updateCenterPoint,
|
|
|
+ _updateRadiusValues,
|
|
|
+ _radiusValues,
|
|
|
child: widget.child,
|
|
|
);
|
|
|
}
|
|
@@ -108,12 +146,16 @@ class InheritedLocationTagData extends InheritedWidget {
|
|
|
final LocalEntity<LocationTag>? locationTagEntity;
|
|
|
final VoidCallbackParamInt updateSelectedIndex;
|
|
|
final VoidCallbackParamLocation updateCenterPoint;
|
|
|
+ final VoidCallbackParamListDouble updateRadiusValues;
|
|
|
+ final List<double> radiusValues;
|
|
|
const InheritedLocationTagData(
|
|
|
this.selectedRadiusIndex,
|
|
|
this.centerPoint,
|
|
|
this.updateSelectedIndex,
|
|
|
this.locationTagEntity,
|
|
|
- this.updateCenterPoint, {
|
|
|
+ this.updateCenterPoint,
|
|
|
+ this.updateRadiusValues,
|
|
|
+ this.radiusValues, {
|
|
|
required super.child,
|
|
|
super.key,
|
|
|
});
|
|
@@ -126,6 +168,7 @@ class InheritedLocationTagData extends InheritedWidget {
|
|
|
@override
|
|
|
bool updateShouldNotify(InheritedLocationTagData oldWidget) {
|
|
|
return oldWidget.selectedRadiusIndex != selectedRadiusIndex ||
|
|
|
+ !oldWidget.radiusValues.equals(radiusValues) ||
|
|
|
oldWidget.centerPoint != centerPoint ||
|
|
|
oldWidget.locationTagEntity != locationTagEntity;
|
|
|
}
|