diff --git a/lib/screens/metering/components/shared/readings_container/components/animated_dialog_picker/widget_picker_dialog_animated.dart b/lib/screens/metering/components/shared/readings_container/components/animated_dialog_picker/widget_picker_dialog_animated.dart index 55923c8..d123d99 100644 --- a/lib/screens/metering/components/shared/readings_container/components/animated_dialog_picker/widget_picker_dialog_animated.dart +++ b/lib/screens/metering/components/shared/readings_container/components/animated_dialog_picker/widget_picker_dialog_animated.dart @@ -3,8 +3,9 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart'; -class AnimatedDialogPicker extends StatelessWidget { - final _key = GlobalKey(); +// Has to be stateful, so that [GlobalKey] is not recreated. +// Otherwise use will no be able to close the dialog after EV value has changed. +class AnimatedDialogPicker extends StatefulWidget { final IconData icon; final String title; final String? subtitle; @@ -15,7 +16,7 @@ class AnimatedDialogPicker extends StatelessWidget { final ValueChanged onChanged; final Widget closedChild; - AnimatedDialogPicker({ + const AnimatedDialogPicker({ required this.icon, required this.title, this.subtitle, @@ -28,24 +29,31 @@ class AnimatedDialogPicker extends StatelessWidget { super.key, }); + @override + State> createState() => _AnimatedDialogPickerState(); +} + +class _AnimatedDialogPickerState extends State> { + final _key = GlobalKey(); + @override Widget build(BuildContext context) { return AnimatedDialog( key: _key, - closedChild: closedChild, + closedChild: widget.closedChild, openedChild: DialogPicker( - icon: icon, - title: title, - subtitle: subtitle, - initialValue: selectedValue, - values: values, - itemTitleBuilder: itemTitleBuilder, - itemTrailingBuilder: itemTrailingBuilder, + icon: widget.icon, + title: widget.title, + subtitle: widget.subtitle, + initialValue: widget.selectedValue, + values: widget.values, + itemTitleBuilder: widget.itemTitleBuilder, + itemTrailingBuilder: widget.itemTrailingBuilder, onCancel: () { _key.currentState?.close(); }, onSelect: (value) { - _key.currentState?.close().then((_) => onChanged(value)); + _key.currentState?.close().then((_) => widget.onChanged(value)); }, ), );