use closed child background color in AnimatedDialog

This commit is contained in:
Vadim 2024-01-11 13:58:34 +01:00
parent 2d143c48de
commit ffcd20c509
3 changed files with 20 additions and 9 deletions

View file

@ -1,9 +1,15 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:lightmeter/res/dimens.dart';
mixin AnimatedDialogClosedChild on Widget {
Color backgroundColor(BuildContext context);
}
class AnimatedDialog extends StatefulWidget {
final Size? openedSize;
final Widget? closedChild;
final AnimatedDialogClosedChild? closedChild;
final Widget? openedChild;
final Widget? child;
@ -95,7 +101,7 @@ class AnimatedDialogState extends State<AnimatedDialog> with SingleTickerProvide
void didChangeDependencies() {
super.didChangeDependencies();
_foregroundColorAnimation = ColorTween(
begin: Theme.of(context).colorScheme.primaryContainer,
begin: widget.closedChild?.backgroundColor(context) ?? Theme.of(context).colorScheme.primaryContainer,
end: Theme.of(context).colorScheme.surface,
).animate(_defaultCurvedAnimation);
@ -135,13 +141,14 @@ class AnimatedDialogState extends State<AnimatedDialog> with SingleTickerProvide
if (renderBox != null) {
final size = MediaQuery.sizeOf(context);
final padding = MediaQuery.paddingOf(context);
final maxWidth = size.width - padding.horizontal - Dimens.dialogMargin.horizontal;
final maxHeight = size.height - padding.vertical - Dimens.dialogMargin.vertical;
_closedSize = _key.currentContext!.size!;
_sizeTween = SizeTween(
begin: _closedSize,
end: widget.openedSize ??
Size(
size.width - padding.horizontal - Dimens.dialogMargin.horizontal,
size.height - padding.vertical - Dimens.dialogMargin.vertical,
end: Size(
min(widget.openedSize?.width ?? double.maxFinite, maxWidth),
min(widget.openedSize?.height ?? double.maxFinite, maxHeight),
),
);
_sizeAnimation = _sizeTween.animate(_defaultCurvedAnimation);

View file

@ -13,7 +13,7 @@ class AnimatedDialogPicker<T> extends StatefulWidget {
final DialogPickerItemTitleBuilder<T> itemTitleBuilder;
final DialogPickerItemTrailingBuilder<T>? itemTrailingBuilder;
final ValueChanged<T> onChanged;
final Widget closedChild;
final AnimatedDialogClosedChild closedChild;
const AnimatedDialogPicker({
required this.icon,

View file

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart';
class ReadingValue {
final String label;
@ -11,7 +12,7 @@ class ReadingValue {
});
}
class ReadingValueContainer extends StatelessWidget {
class ReadingValueContainer extends StatelessWidget implements AnimatedDialogClosedChild {
late final List<Widget> _items;
final Color? color;
@ -35,12 +36,15 @@ class ReadingValueContainer extends StatelessWidget {
super.key,
}) : _items = [_ReadingValueBuilder(value)];
@override
Color backgroundColor(BuildContext context) => color ?? Theme.of(context).colorScheme.primaryContainer;
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(Dimens.borderRadiusM),
child: ColoredBox(
color: color ?? Theme.of(context).colorScheme.primaryContainer,
color: backgroundColor(context),
child: Padding(
padding: const EdgeInsets.all(Dimens.paddingM),
child: Column(