Fixed state refresh issue for custom radius + refactor
This commit is contained in:
parent
2b0d851c81
commit
53c3713e28
1 changed files with 32 additions and 25 deletions
|
@ -59,31 +59,7 @@ class _RadiusPickerWidgetState extends State<RadiusPickerWidget> {
|
|||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
showTextInputDialog(
|
||||
context,
|
||||
title: "Custom radius",
|
||||
onSubmit: (customRadius) async {
|
||||
final radius = double.tryParse(customRadius);
|
||||
if (radius != null) {
|
||||
InheritedLocationTagData.of(context)
|
||||
.updateRadiusValues([radius]);
|
||||
} else {
|
||||
showErrorDialog(
|
||||
context,
|
||||
"Invalid radius",
|
||||
"Please enter a valid radius",
|
||||
);
|
||||
}
|
||||
},
|
||||
submitButtonLabel: "Done",
|
||||
textInputFormatter: [
|
||||
NumberWithDecimalInputFormatter(maxValue: 10000)
|
||||
],
|
||||
textInputType:
|
||||
const TextInputType.numberWithOptions(decimal: true),
|
||||
);
|
||||
},
|
||||
onTap: _customRadiusOnTap,
|
||||
child: Container(
|
||||
height: 52,
|
||||
width: 52,
|
||||
|
@ -197,6 +173,37 @@ class _RadiusPickerWidgetState extends State<RadiusPickerWidget> {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
void _customRadiusOnTap() {
|
||||
showTextInputDialog(
|
||||
context,
|
||||
title: "Custom radius",
|
||||
onSubmit: (customRadius) async {
|
||||
final radius = double.tryParse(customRadius);
|
||||
if (radius != null) {
|
||||
final locationTagState = InheritedLocationTagData.of(context);
|
||||
locationTagState.updateRadiusValues([radius]);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
widget.selectedRadiusIndexNotifier.value =
|
||||
InheritedLocationTagData.of(context)
|
||||
.radiusValues
|
||||
.indexOf(radius);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
showErrorDialog(
|
||||
context,
|
||||
"Invalid radius",
|
||||
"Please enter a valid radius",
|
||||
);
|
||||
}
|
||||
},
|
||||
submitButtonLabel: "Done",
|
||||
textInputFormatter: [NumberWithDecimalInputFormatter(maxValue: 10000)],
|
||||
textInputType: const TextInputType.numberWithOptions(decimal: true),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class NumberWithDecimalInputFormatter extends TextInputFormatter {
|
||||
|
|
Loading…
Add table
Reference in a new issue