Store state of selected radius instead of selected radius index for a bug fix
This commit is contained in:
parent
6404f86059
commit
7b5b39997f
7 changed files with 63 additions and 64 deletions
|
@ -62,6 +62,6 @@ const kilometersPerDegree = 111.16;
|
|||
|
||||
const defaultRadiusValues = <double>[1, 2, 10, 20, 40, 80, 200, 400, 1200];
|
||||
|
||||
const defaultRadiusValueIndex = 4;
|
||||
const defaultRadiusValue = 40.0;
|
||||
|
||||
const galleryGridSpacing = 2.0;
|
||||
|
|
|
@ -2,11 +2,14 @@ import 'dart:async';
|
|||
|
||||
import "package:photos/models/location/location.dart";
|
||||
|
||||
typedef FutureVoidCallback = Future<void> Function();
|
||||
typedef BoolCallBack = bool Function();
|
||||
typedef FutureVoidCallbackParamStr = Future<void> Function(String);
|
||||
|
||||
typedef VoidCallbackParamStr = void Function(String);
|
||||
typedef FutureOrVoidCallback = FutureOr<void> Function();
|
||||
typedef VoidCallbackParamInt = void Function(int);
|
||||
typedef VoidCallbackParamLocation = void Function(Location);
|
||||
typedef VoidCallbackParamDouble = Function(double);
|
||||
typedef VoidCallbackParamListDouble = void Function(List<double>);
|
||||
typedef VoidCallbackParamLocation = void Function(Location);
|
||||
|
||||
typedef FutureVoidCallback = Future<void> Function();
|
||||
typedef FutureOrVoidCallback = FutureOr<void> Function();
|
||||
typedef FutureVoidCallbackParamStr = Future<void> Function(String);
|
||||
|
|
|
@ -28,7 +28,8 @@ class LocationTagStateProvider extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _LocationTagStateProviderState extends State<LocationTagStateProvider> {
|
||||
int _selectedRaduisIndex = defaultRadiusValueIndex;
|
||||
late double _selectedRadius;
|
||||
|
||||
late Location? _centerPoint;
|
||||
late LocalEntity<LocationTag>? _locationTagEntity;
|
||||
final Debouncer _selectedRadiusDebouncer =
|
||||
|
@ -47,9 +48,9 @@ class _LocationTagStateProviderState extends State<LocationTagStateProvider> {
|
|||
///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(_radiusValues) ??
|
||||
defaultRadiusValueIndex;
|
||||
|
||||
_selectedRadius = _locationTagEntity?.item.radius ?? defaultRadiusValue;
|
||||
|
||||
_locTagEntityListener =
|
||||
Bus.instance.on<LocationTagUpdatedEvent>().listen((event) {
|
||||
_locationTagUpdateListener(event);
|
||||
|
@ -66,11 +67,11 @@ class _LocationTagStateProviderState extends State<LocationTagStateProvider> {
|
|||
void _locationTagUpdateListener(LocationTagUpdatedEvent event) {
|
||||
if (event.type == LocTagEventType.update) {
|
||||
if (event.updatedLocTagEntities!.first.id == _locationTagEntity!.id) {
|
||||
//Update state when locationTag is updated.
|
||||
setState(() {
|
||||
final updatedLocTagEntity = event.updatedLocTagEntities!.first;
|
||||
_selectedRaduisIndex =
|
||||
updatedLocTagEntity.item.radiusIndex(_radiusValues);
|
||||
|
||||
_selectedRadius = updatedLocTagEntity.item.radius;
|
||||
|
||||
_centerPoint = updatedLocTagEntity.item.centerPoint;
|
||||
_locationTagEntity = updatedLocTagEntity;
|
||||
});
|
||||
|
@ -78,12 +79,12 @@ class _LocationTagStateProviderState extends State<LocationTagStateProvider> {
|
|||
}
|
||||
}
|
||||
|
||||
void _updateSelectedIndex(int index) {
|
||||
void _updateSelectedRadius(double radius) {
|
||||
_selectedRadiusDebouncer.cancelDebounce();
|
||||
_selectedRadiusDebouncer.run(() async {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_selectedRaduisIndex = index;
|
||||
_selectedRadius = radius;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -126,9 +127,9 @@ class _LocationTagStateProviderState extends State<LocationTagStateProvider> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InheritedLocationTagData(
|
||||
_selectedRaduisIndex,
|
||||
_selectedRadius,
|
||||
_centerPoint!,
|
||||
_updateSelectedIndex,
|
||||
_updateSelectedRadius,
|
||||
_locationTagEntity,
|
||||
_updateCenterPoint,
|
||||
_updateRadiusValues,
|
||||
|
@ -140,18 +141,18 @@ class _LocationTagStateProviderState extends State<LocationTagStateProvider> {
|
|||
|
||||
///This InheritedWidget's state is used in add & edit location sheets
|
||||
class InheritedLocationTagData extends InheritedWidget {
|
||||
final int selectedRadiusIndex;
|
||||
final double selectedRadius;
|
||||
final Location centerPoint;
|
||||
//locationTag is null when we are creating a new location tag in add location sheet
|
||||
final LocalEntity<LocationTag>? locationTagEntity;
|
||||
final VoidCallbackParamInt updateSelectedIndex;
|
||||
final VoidCallbackParamDouble updateSelectedRadius;
|
||||
final VoidCallbackParamLocation updateCenterPoint;
|
||||
final VoidCallbackParamListDouble updateRadiusValues;
|
||||
final List<double> radiusValues;
|
||||
const InheritedLocationTagData(
|
||||
this.selectedRadiusIndex,
|
||||
this.selectedRadius,
|
||||
this.centerPoint,
|
||||
this.updateSelectedIndex,
|
||||
this.updateSelectedRadius,
|
||||
this.locationTagEntity,
|
||||
this.updateCenterPoint,
|
||||
this.updateRadiusValues,
|
||||
|
@ -167,7 +168,9 @@ class InheritedLocationTagData extends InheritedWidget {
|
|||
|
||||
@override
|
||||
bool updateShouldNotify(InheritedLocationTagData oldWidget) {
|
||||
return oldWidget.selectedRadiusIndex != selectedRadiusIndex ||
|
||||
print(selectedRadius);
|
||||
print(oldWidget.selectedRadius != selectedRadius);
|
||||
return oldWidget.selectedRadius != selectedRadius ||
|
||||
!oldWidget.radiusValues.equals(radiusValues) ||
|
||||
oldWidget.centerPoint != centerPoint ||
|
||||
oldWidget.locationTagEntity != locationTagEntity;
|
||||
|
|
|
@ -51,14 +51,17 @@ class AddLocationSheet extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _AddLocationSheetState extends State<AddLocationSheet> {
|
||||
//The value of these notifiers has no significance.
|
||||
//The value of this notifier has no significance.
|
||||
//When memoriesCountNotifier is null, we show the loading widget in the
|
||||
//memories count section which also means the gallery is loading.
|
||||
final ValueNotifier<int?> _memoriesCountNotifier = ValueNotifier(null);
|
||||
|
||||
//The value of this notifier has no significance.
|
||||
final ValueNotifier<bool> _submitNotifer = ValueNotifier(false);
|
||||
|
||||
final ValueNotifier<bool> _cancelNotifier = ValueNotifier(false);
|
||||
final ValueNotifier<int> _selectedRadiusIndexNotifier =
|
||||
ValueNotifier(defaultRadiusValueIndex);
|
||||
final ValueNotifier<double> _selectedRadiusNotifier =
|
||||
ValueNotifier(defaultRadiusValue);
|
||||
final _focusNode = FocusNode();
|
||||
final _textEditingController = TextEditingController();
|
||||
final _isEmptyNotifier = ValueNotifier(true);
|
||||
|
@ -67,7 +70,7 @@ class _AddLocationSheetState extends State<AddLocationSheet> {
|
|||
@override
|
||||
void initState() {
|
||||
_focusNode.addListener(_focusNodeListener);
|
||||
_selectedRadiusIndexNotifier.addListener(_selectedRadiusIndexListener);
|
||||
_selectedRadiusNotifier.addListener(_selectedRadiusListener);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
@ -76,7 +79,7 @@ class _AddLocationSheetState extends State<AddLocationSheet> {
|
|||
_focusNode.removeListener(_focusNodeListener);
|
||||
_submitNotifer.dispose();
|
||||
_cancelNotifier.dispose();
|
||||
_selectedRadiusIndexNotifier.dispose();
|
||||
_selectedRadiusNotifier.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
@ -149,7 +152,7 @@ class _AddLocationSheetState extends State<AddLocationSheet> {
|
|||
),
|
||||
const SizedBox(height: 24),
|
||||
RadiusPickerWidget(
|
||||
_selectedRadiusIndexNotifier,
|
||||
_selectedRadiusNotifier,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
|
@ -230,8 +233,8 @@ class _AddLocationSheetState extends State<AddLocationSheet> {
|
|||
Future<void> _addLocationTag() async {
|
||||
final locationData = InheritedLocationTagData.of(context);
|
||||
final coordinates = locationData.centerPoint;
|
||||
final radiusValues = locationData.radiusValues;
|
||||
final radius = radiusValues[locationData.selectedRadiusIndex];
|
||||
final radius = locationData.selectedRadius;
|
||||
|
||||
await LocationService.instance.addLocation(
|
||||
_textEditingController.text.trim(),
|
||||
coordinates,
|
||||
|
@ -257,11 +260,11 @@ class _AddLocationSheetState extends State<AddLocationSheet> {
|
|||
}
|
||||
}
|
||||
|
||||
void _selectedRadiusIndexListener() {
|
||||
void _selectedRadiusListener() {
|
||||
InheritedLocationTagData.of(
|
||||
context,
|
||||
).updateSelectedIndex(
|
||||
_selectedRadiusIndexNotifier.value,
|
||||
).updateSelectedRadius(
|
||||
_selectedRadiusNotifier.value,
|
||||
);
|
||||
_memoriesCountNotifier.value = null;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ class _DynamicLocationGalleryWidgetState
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const galleryFilesLimit = 1000;
|
||||
final selectedRadius = _selectedRadius();
|
||||
final selectedRadius = InheritedLocationTagData.of(context).selectedRadius;
|
||||
Future<FileLoadResult> filterFiles() async {
|
||||
final FileLoadResult result = await fileLoadResult;
|
||||
//wait for ignored files to be removed after init
|
||||
|
@ -121,11 +121,6 @@ class _DynamicLocationGalleryWidgetState
|
|||
);
|
||||
}
|
||||
|
||||
double _selectedRadius() {
|
||||
final locationTagState = InheritedLocationTagData.of(context);
|
||||
return locationTagState.radiusValues[locationTagState.selectedRadiusIndex];
|
||||
}
|
||||
|
||||
double _galleryHeight(int fileCount) {
|
||||
final photoGridSize = LocalSettings.instance.getPhotoGridSize();
|
||||
final totalWhiteSpaceBetweenPhotos =
|
||||
|
|
|
@ -61,8 +61,8 @@ class _EditLocationSheetState extends State<EditLocationSheet> {
|
|||
final ValueNotifier<int?> _memoriesCountNotifier = ValueNotifier(null);
|
||||
final ValueNotifier<bool> _submitNotifer = ValueNotifier(false);
|
||||
final ValueNotifier<bool> _cancelNotifier = ValueNotifier(false);
|
||||
final ValueNotifier<int> _selectedRadiusIndexNotifier =
|
||||
ValueNotifier(defaultRadiusValueIndex);
|
||||
final ValueNotifier<double> _selectedRadiusNotifier =
|
||||
ValueNotifier(defaultRadiusValue);
|
||||
final _focusNode = FocusNode();
|
||||
final _textEditingController = TextEditingController();
|
||||
final _isEmptyNotifier = ValueNotifier(false);
|
||||
|
@ -71,7 +71,7 @@ class _EditLocationSheetState extends State<EditLocationSheet> {
|
|||
@override
|
||||
void initState() {
|
||||
_focusNode.addListener(_focusNodeListener);
|
||||
_selectedRadiusIndexNotifier.addListener(_selectedRadiusIndexListener);
|
||||
_selectedRadiusNotifier.addListener(_selectedRadiusListener);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ class _EditLocationSheetState extends State<EditLocationSheet> {
|
|||
_focusNode.removeListener(_focusNodeListener);
|
||||
_submitNotifer.dispose();
|
||||
_cancelNotifier.dispose();
|
||||
_selectedRadiusIndexNotifier.dispose();
|
||||
_selectedRadiusNotifier.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,7 @@ class _EditLocationSheetState extends State<EditLocationSheet> {
|
|||
const EditCenterPointTileWidget(),
|
||||
const SizedBox(height: 20),
|
||||
RadiusPickerWidget(
|
||||
_selectedRadiusIndexNotifier,
|
||||
_selectedRadiusNotifier,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
@ -240,8 +240,7 @@ class _EditLocationSheetState extends State<EditLocationSheet> {
|
|||
final locationTagState = InheritedLocationTagData.of(context);
|
||||
await LocationService.instance.updateLocationTag(
|
||||
locationTagEntity: locationTagState.locationTagEntity!,
|
||||
newRadius:
|
||||
locationTagState.radiusValues[locationTagState.selectedRadiusIndex],
|
||||
newRadius: locationTagState.selectedRadius,
|
||||
newName: _textEditingController.text.trim(),
|
||||
newCenterPoint: InheritedLocationTagData.of(context).centerPoint,
|
||||
);
|
||||
|
@ -265,11 +264,11 @@ class _EditLocationSheetState extends State<EditLocationSheet> {
|
|||
}
|
||||
}
|
||||
|
||||
void _selectedRadiusIndexListener() {
|
||||
void _selectedRadiusListener() {
|
||||
InheritedLocationTagData.of(
|
||||
context,
|
||||
).updateSelectedIndex(
|
||||
_selectedRadiusIndexNotifier.value,
|
||||
).updateSelectedRadius(
|
||||
_selectedRadiusNotifier.value,
|
||||
);
|
||||
_memoriesCountNotifier.value = null;
|
||||
}
|
||||
|
|
|
@ -23,11 +23,11 @@ class CustomTrackShape extends RoundedRectSliderTrackShape {
|
|||
}
|
||||
|
||||
class RadiusPickerWidget extends StatefulWidget {
|
||||
///This notifier can be listened to get the selected radius index from
|
||||
///a parent widget.
|
||||
final ValueNotifier<int> selectedRadiusIndexNotifier;
|
||||
///This notifier can be listened from a parent widget to get the selected radius
|
||||
final ValueNotifier<double> selectedRadiusNotifier;
|
||||
|
||||
const RadiusPickerWidget(
|
||||
this.selectedRadiusIndexNotifier, {
|
||||
this.selectedRadiusNotifier, {
|
||||
super.key,
|
||||
});
|
||||
|
||||
|
@ -44,19 +44,18 @@ class _RadiusPickerWidgetState extends State<RadiusPickerWidget> {
|
|||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
widget.selectedRadiusIndexNotifier.value =
|
||||
InheritedLocationTagData.of(context).selectedRadiusIndex;
|
||||
widget.selectedRadiusNotifier.value =
|
||||
InheritedLocationTagData.of(context).selectedRadius;
|
||||
super.didChangeDependencies();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final radiusValues = InheritedLocationTagData.of(context).radiusValues;
|
||||
final selectedRadiusIndex = widget.selectedRadiusIndexNotifier.value;
|
||||
final radiusValue = radiusValues[selectedRadiusIndex];
|
||||
final selectedRadius = widget.selectedRadiusNotifier.value;
|
||||
final textTheme = getEnteTextTheme(context);
|
||||
final colorScheme = getEnteColorScheme(context);
|
||||
final roundedRadius = roundRadius(radiusValue);
|
||||
final roundedRadius = roundRadius(selectedRadius);
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
|
@ -136,11 +135,11 @@ class _RadiusPickerWidgetState extends State<RadiusPickerWidget> {
|
|||
),
|
||||
child: RepaintBoundary(
|
||||
child: Slider(
|
||||
value: selectedRadiusIndex.toDouble(),
|
||||
value: radiusValues.indexOf(selectedRadius).toDouble(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
widget.selectedRadiusIndexNotifier.value =
|
||||
value.toInt();
|
||||
widget.selectedRadiusNotifier.value =
|
||||
radiusValues[value.toInt()];
|
||||
});
|
||||
},
|
||||
min: 0,
|
||||
|
@ -187,10 +186,7 @@ class _RadiusPickerWidgetState extends State<RadiusPickerWidget> {
|
|||
locationTagState.updateRadiusValues([radius]);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
widget.selectedRadiusIndexNotifier.value =
|
||||
InheritedLocationTagData.of(context)
|
||||
.radiusValues
|
||||
.indexOf(radius);
|
||||
widget.selectedRadiusNotifier.value = radius;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue