mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2025-04-21 17:00:40 +00:00
adjust AnimatedDialogPicker
to items count
This commit is contained in:
parent
ffcd20c509
commit
2a4d79e35a
2 changed files with 43 additions and 22 deletions
|
@ -29,6 +29,30 @@ class DialogPicker<T> extends StatefulWidget {
|
||||||
super.key,
|
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
|
@override
|
||||||
State<DialogPicker<T>> createState() => _DialogPickerState<T>();
|
State<DialogPicker<T>> createState() => _DialogPickerState<T>();
|
||||||
}
|
}
|
||||||
|
@ -66,12 +90,7 @@ class _DialogPickerState<T> extends State<DialogPicker<T>> {
|
||||||
),
|
),
|
||||||
if (widget.subtitle != null)
|
if (widget.subtitle != null)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(
|
padding: Dimens.dialogIconTitlePadding,
|
||||||
Dimens.paddingL,
|
|
||||||
0,
|
|
||||||
Dimens.paddingL,
|
|
||||||
Dimens.paddingM,
|
|
||||||
),
|
|
||||||
child: Text(
|
child: Text(
|
||||||
widget.subtitle!,
|
widget.subtitle!,
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
|
|
|
@ -37,10 +37,7 @@ class _AnimatedDialogPickerState<T> extends State<AnimatedDialogPicker<T>> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return AnimatedDialog(
|
final dialogPicker = DialogPicker<T>(
|
||||||
key: _key,
|
|
||||||
closedChild: widget.closedChild,
|
|
||||||
openedChild: DialogPicker<T>(
|
|
||||||
icon: widget.icon,
|
icon: widget.icon,
|
||||||
title: widget.title,
|
title: widget.title,
|
||||||
subtitle: widget.subtitle,
|
subtitle: widget.subtitle,
|
||||||
|
@ -54,7 +51,12 @@ class _AnimatedDialogPickerState<T> extends State<AnimatedDialogPicker<T>> {
|
||||||
onSelect: (value) {
|
onSelect: (value) {
|
||||||
_key.currentState?.close().then((_) => widget.onChanged(value));
|
_key.currentState?.close().then((_) => widget.onChanged(value));
|
||||||
},
|
},
|
||||||
),
|
);
|
||||||
|
return AnimatedDialog(
|
||||||
|
key: _key,
|
||||||
|
closedChild: widget.closedChild,
|
||||||
|
openedChild: dialogPicker,
|
||||||
|
openedSize: Size.fromHeight(dialogPicker.height(context)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue