mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 07:20:39 +00:00
use closed child background color in AnimatedDialog
This commit is contained in:
parent
2d143c48de
commit
ffcd20c509
3 changed files with 20 additions and 9 deletions
|
@ -1,9 +1,15 @@
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
|
|
||||||
|
mixin AnimatedDialogClosedChild on Widget {
|
||||||
|
Color backgroundColor(BuildContext context);
|
||||||
|
}
|
||||||
|
|
||||||
class AnimatedDialog extends StatefulWidget {
|
class AnimatedDialog extends StatefulWidget {
|
||||||
final Size? openedSize;
|
final Size? openedSize;
|
||||||
final Widget? closedChild;
|
final AnimatedDialogClosedChild? closedChild;
|
||||||
final Widget? openedChild;
|
final Widget? openedChild;
|
||||||
final Widget? child;
|
final Widget? child;
|
||||||
|
|
||||||
|
@ -95,7 +101,7 @@ class AnimatedDialogState extends State<AnimatedDialog> with SingleTickerProvide
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
_foregroundColorAnimation = ColorTween(
|
_foregroundColorAnimation = ColorTween(
|
||||||
begin: Theme.of(context).colorScheme.primaryContainer,
|
begin: widget.closedChild?.backgroundColor(context) ?? Theme.of(context).colorScheme.primaryContainer,
|
||||||
end: Theme.of(context).colorScheme.surface,
|
end: Theme.of(context).colorScheme.surface,
|
||||||
).animate(_defaultCurvedAnimation);
|
).animate(_defaultCurvedAnimation);
|
||||||
|
|
||||||
|
@ -135,13 +141,14 @@ class AnimatedDialogState extends State<AnimatedDialog> with SingleTickerProvide
|
||||||
if (renderBox != null) {
|
if (renderBox != null) {
|
||||||
final size = MediaQuery.sizeOf(context);
|
final size = MediaQuery.sizeOf(context);
|
||||||
final padding = MediaQuery.paddingOf(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!;
|
_closedSize = _key.currentContext!.size!;
|
||||||
_sizeTween = SizeTween(
|
_sizeTween = SizeTween(
|
||||||
begin: _closedSize,
|
begin: _closedSize,
|
||||||
end: widget.openedSize ??
|
end: Size(
|
||||||
Size(
|
min(widget.openedSize?.width ?? double.maxFinite, maxWidth),
|
||||||
size.width - padding.horizontal - Dimens.dialogMargin.horizontal,
|
min(widget.openedSize?.height ?? double.maxFinite, maxHeight),
|
||||||
size.height - padding.vertical - Dimens.dialogMargin.vertical,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
_sizeAnimation = _sizeTween.animate(_defaultCurvedAnimation);
|
_sizeAnimation = _sizeTween.animate(_defaultCurvedAnimation);
|
||||||
|
|
|
@ -13,7 +13,7 @@ class AnimatedDialogPicker<T> extends StatefulWidget {
|
||||||
final DialogPickerItemTitleBuilder<T> itemTitleBuilder;
|
final DialogPickerItemTitleBuilder<T> itemTitleBuilder;
|
||||||
final DialogPickerItemTrailingBuilder<T>? itemTrailingBuilder;
|
final DialogPickerItemTrailingBuilder<T>? itemTrailingBuilder;
|
||||||
final ValueChanged<T> onChanged;
|
final ValueChanged<T> onChanged;
|
||||||
final Widget closedChild;
|
final AnimatedDialogClosedChild closedChild;
|
||||||
|
|
||||||
const AnimatedDialogPicker({
|
const AnimatedDialogPicker({
|
||||||
required this.icon,
|
required this.icon,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/res/dimens.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 {
|
class ReadingValue {
|
||||||
final String label;
|
final String label;
|
||||||
|
@ -11,7 +12,7 @@ class ReadingValue {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class ReadingValueContainer extends StatelessWidget {
|
class ReadingValueContainer extends StatelessWidget implements AnimatedDialogClosedChild {
|
||||||
late final List<Widget> _items;
|
late final List<Widget> _items;
|
||||||
final Color? color;
|
final Color? color;
|
||||||
|
|
||||||
|
@ -35,12 +36,15 @@ class ReadingValueContainer extends StatelessWidget {
|
||||||
super.key,
|
super.key,
|
||||||
}) : _items = [_ReadingValueBuilder(value)];
|
}) : _items = [_ReadingValueBuilder(value)];
|
||||||
|
|
||||||
|
@override
|
||||||
|
Color backgroundColor(BuildContext context) => color ?? Theme.of(context).colorScheme.primaryContainer;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ClipRRect(
|
return ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(Dimens.borderRadiusM),
|
borderRadius: BorderRadius.circular(Dimens.borderRadiusM),
|
||||||
child: ColoredBox(
|
child: ColoredBox(
|
||||||
color: color ?? Theme.of(context).colorScheme.primaryContainer,
|
color: backgroundColor(context),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(Dimens.paddingM),
|
padding: const EdgeInsets.all(Dimens.paddingM),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|
Loading…
Reference in a new issue