ML-137 Dialogs improvements (#138)

* Force dialogs to have the same width

* Fix `DialogPicker` bouncing when the first selected item is near the end
This commit is contained in:
Vadim 2023-11-14 12:26:34 +01:00 committed by GitHub
parent 6566108994
commit 19fc039723
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 139 additions and 128 deletions

View file

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/res/dimens.dart';
@ -34,18 +35,20 @@ class _DialogFilterState<T> extends State<DialogFilter<T>> {
bool get _hasAnySelected => checkboxValues.contains(true); bool get _hasAnySelected => checkboxValues.contains(true);
bool get _hasAnyUnselected => checkboxValues.contains(false); bool get _hasAnyUnselected => checkboxValues.contains(false);
late final ScrollController _scrollController; final ScrollController _scrollController = ScrollController();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
SchedulerBinding.instance.addPostFrameCallback((_) {
int i = 0; int i = 0;
for (; i < checkboxValues.length; i++) { for (; i < checkboxValues.length; i++) {
if (checkboxValues[i]) { if (checkboxValues[i]) {
break; break;
} }
} }
_scrollController = ScrollController(initialScrollOffset: Dimens.grid56 * i); _scrollController.jumpTo((Dimens.grid56 * i).clamp(0, _scrollController.position.maxScrollExtent));
});
} }
@override @override
@ -61,7 +64,9 @@ class _DialogFilterState<T> extends State<DialogFilter<T>> {
titlePadding: Dimens.dialogIconTitlePadding, titlePadding: Dimens.dialogIconTitlePadding,
title: Text(widget.title), title: Text(widget.title),
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
content: Column( content: SizedBox(
width: double.maxFinite,
child: Column(
children: [ children: [
Padding( Padding(
padding: Dimens.dialogIconTitlePadding, padding: Dimens.dialogIconTitlePadding,
@ -106,9 +111,7 @@ class _DialogFilterState<T> extends State<DialogFilter<T>> {
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
icon: Icon(_hasAnyUnselected ? Icons.select_all : Icons.deselect), icon: Icon(_hasAnyUnselected ? Icons.select_all : Icons.deselect),
onPressed: _toggleAll, onPressed: _toggleAll,
tooltip: _hasAnyUnselected tooltip: _hasAnyUnselected ? S.of(context).tooltipSelectAll : S.of(context).tooltipDesecelectAll,
? S.of(context).tooltipSelectAll
: S.of(context).tooltipDesecelectAll,
), ),
), ),
const Spacer(), const Spacer(),
@ -135,6 +138,7 @@ class _DialogFilterState<T> extends State<DialogFilter<T>> {
) )
], ],
), ),
),
); );
} }

View file

@ -32,7 +32,10 @@ class _DialogPickerState<T> extends State<DialogPicker<T>> {
titlePadding: Dimens.dialogIconTitlePadding, titlePadding: Dimens.dialogIconTitlePadding,
title: Text(widget.title), title: Text(widget.title),
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
content: Column( content: SizedBox(
width: double.maxFinite,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: widget.values children: widget.values
.map( .map(
@ -51,6 +54,7 @@ class _DialogPickerState<T> extends State<DialogPicker<T>> {
) )
.toList(), .toList(),
), ),
),
actionsPadding: Dimens.dialogActionsPadding, actionsPadding: Dimens.dialogActionsPadding,
actions: [ actions: [
TextButton( TextButton(

View file

@ -36,7 +36,9 @@ class _DialogRangePickerState<T extends PhotographyValue> extends State<DialogRa
titlePadding: Dimens.dialogIconTitlePadding, titlePadding: Dimens.dialogIconTitlePadding,
title: Text(widget.title), title: Text(widget.title),
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
content: Column( content: SizedBox(
width: double.maxFinite,
child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Padding( Padding(
@ -78,6 +80,7 @@ class _DialogRangePickerState<T extends PhotographyValue> extends State<DialogRa
), ),
], ],
), ),
),
actionsPadding: Dimens.dialogActionsPadding, actionsPadding: Dimens.dialogActionsPadding,
actions: [ actions: [
TextButton( TextButton(