From ffcd20c50904294433af41da832edf11c3970f9e Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Thu, 11 Jan 2024 13:58:34 +0100 Subject: [PATCH] use closed child background color in `AnimatedDialog` --- .../widget_dialog_animated.dart | 19 +++++++++++++------ .../widget_picker_dialog_animated.dart | 2 +- .../widget_container_reading_value.dart | 8 ++++++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart b/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart index 72e770b..4b03d78 100644 --- a/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart +++ b/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart @@ -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 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 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); 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 eeeec52..ad382f6 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 @@ -13,7 +13,7 @@ class AnimatedDialogPicker extends StatefulWidget { final DialogPickerItemTitleBuilder itemTitleBuilder; final DialogPickerItemTrailingBuilder? itemTrailingBuilder; final ValueChanged onChanged; - final Widget closedChild; + final AnimatedDialogClosedChild closedChild; const AnimatedDialogPicker({ required this.icon, diff --git a/lib/screens/metering/components/shared/readings_container/components/shared/reading_value_container/widget_container_reading_value.dart b/lib/screens/metering/components/shared/readings_container/components/shared/reading_value_container/widget_container_reading_value.dart index e524854..10e051e 100644 --- a/lib/screens/metering/components/shared/readings_container/components/shared/reading_value_container/widget_container_reading_value.dart +++ b/lib/screens/metering/components/shared/readings_container/components/shared/reading_value_container/widget_container_reading_value.dart @@ -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 _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(