diff --git a/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart b/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart index 3c253b1..888a34d 100644 --- a/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart +++ b/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart @@ -29,6 +29,30 @@ class DialogPicker extends StatefulWidget { super.key, }); + double height(BuildContext context) { + double textHeight(BuildContext context, String text, TextStyle? style) { + final TextPainter titlePainter = TextPainter( + text: TextSpan( + text: text, + style: style, + ), + textDirection: TextDirection.ltr, + )..layout(maxWidth: MediaQuery.of(context).size.width - Dimens.dialogIconTitlePadding.horizontal); + return titlePainter.size.height + Dimens.dialogIconTitlePadding.vertical; + } + + final titleHeight = textHeight(context, title, Theme.of(context).textTheme.headlineSmall); + final subtitleHeight = + subtitle != null ? textHeight(context, subtitle!, Theme.of(context).textTheme.bodyMedium) : 0; + + return (IconTheme.of(context).size! + Dimens.dialogTitlePadding.vertical) + // icon + icon padding + titleHeight + // title + title padding + subtitleHeight + // subtitle + subtitle padding + Dimens.grid56 * values.length + // values summary height + 1 + // dividers + (48 + Dimens.dialogActionsPadding.vertical); // actions + actions padding + } + @override State> createState() => _DialogPickerState(); } @@ -66,12 +90,7 @@ class _DialogPickerState extends State> { ), if (widget.subtitle != null) Padding( - padding: const EdgeInsets.fromLTRB( - Dimens.paddingL, - 0, - Dimens.paddingL, - Dimens.paddingM, - ), + padding: Dimens.dialogIconTitlePadding, child: Text( widget.subtitle!, style: Theme.of(context).textTheme.bodyMedium, diff --git a/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/widget_picker_dialog_animated.dart b/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/widget_picker_dialog_animated.dart index ad382f6..efa07c7 100644 --- a/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/widget_picker_dialog_animated.dart +++ b/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/widget_picker_dialog_animated.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart'; -// Has to be stateful, so that [GlobalKey] is not recreated. +// 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; @@ -37,24 +37,26 @@ class _AnimatedDialogPickerState extends State> { @override Widget build(BuildContext context) { + final dialogPicker = DialogPicker( + 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((_) => widget.onChanged(value)); + }, + ); return AnimatedDialog( key: _key, closedChild: widget.closedChild, - openedChild: DialogPicker( - 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((_) => widget.onChanged(value)); - }, - ), + openedChild: dialogPicker, + openedSize: Size.fromHeight(dialogPicker.height(context)), ); } }