mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 07:20:39 +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,
|
||||
});
|
||||
|
||||
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<DialogPicker<T>> createState() => _DialogPickerState<T>();
|
||||
}
|
||||
|
@ -66,12 +90,7 @@ class _DialogPickerState<T> extends State<DialogPicker<T>> {
|
|||
),
|
||||
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,
|
||||
|
|
|
@ -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<T> extends StatefulWidget {
|
||||
final IconData icon;
|
||||
|
@ -37,24 +37,26 @@ class _AnimatedDialogPickerState<T> extends State<AnimatedDialogPicker<T>> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dialogPicker = DialogPicker<T>(
|
||||
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<T>(
|
||||
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)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue