From 9f12b233b93c8ff63f07a0be46ff3bba02ef710c Mon Sep 17 00:00:00 2001 From: GittHub-d Date: Fri, 31 Jan 2025 11:14:34 +0200 Subject: [PATCH] [MDS-1580] Drawer component --- lib/src/widgets/drawer/drawer.dart | 72 +++++++++++++----------------- 1 file changed, 32 insertions(+), 40 deletions(-) diff --git a/lib/src/widgets/drawer/drawer.dart b/lib/src/widgets/drawer/drawer.dart index 0ff76c5c..b2ed38f8 100644 --- a/lib/src/widgets/drawer/drawer.dart +++ b/lib/src/widgets/drawer/drawer.dart @@ -1,12 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:mix/mix.dart'; import 'package:moon_core/moon_core.dart'; -import 'package:moon_design/src/theme/theme.dart'; import 'package:moon_design/src/theme/tokens/shadows.dart'; import 'package:moon_design/src/theme/tokens/typography/typography.dart'; -import 'package:moon_design/src/utils/extensions.dart'; -import 'package:moon_design/src/utils/squircle/squircle_border.dart'; + import 'package:moon_tokens/moon_tokens.dart'; class MoonDrawer extends StatelessWidget { @@ -45,61 +44,54 @@ class MoonDrawer extends StatelessWidget { @override Widget build(BuildContext context) { - final BorderRadiusGeometry effectiveBorderRadius = borderRadius ?? - context.moonTheme?.drawerTheme.properties.borderRadius ?? - BorderRadius.zero; + final BorderRadiusGeometry effectiveBorderRadius = + borderRadius ?? BorderRadius.zero; - final Color effectiveBackgroundColor = backgroundColor ?? - context.moonTheme?.drawerTheme.colors.backgroundColor ?? - MoonColors.light.goku; + final Color effectiveBackgroundColor = + backgroundColor ?? MoonColors.light.goku; - final Color effectiveTextColor = - context.moonTheme?.drawerTheme.colors.textColor ?? - MoonColors.light.textPrimary; + final Color effectiveTextColor = MoonColors.light.textPrimary; - final Color effectiveIconColor = - context.moonTheme?.drawerTheme.colors.iconColor ?? - MoonColors.light.iconPrimary; + final Color effectiveIconColor = MoonColors.light.iconPrimary; - final double effectiveWidthFromTheme = - context.moonTheme?.drawerTheme.properties.width ?? 448; + const double effectiveWidthFromTheme = 448; final double effectiveWidth = width ?? (MediaQuery.of(context).size.width < effectiveWidthFromTheme ? MediaQuery.of(context).size.width : effectiveWidthFromTheme); - final List effectiveDrawerShadows = drawerShadows ?? - context.moonTheme?.drawerTheme.shadows.drawerShadows ?? - MoonShadows.light.lg; + final List effectiveDrawerShadows = + drawerShadows ?? MoonShadows.light.lg; final TextStyle effectiveTextStyle = - context.moonTheme?.drawerTheme.properties.textStyle ?? - MoonTypography.typography.body.textDefault; + MoonTypography.typography.body.textDefault; + + final TextStyle resolvedTextStyle = + effectiveTextStyle.copyWith(color: effectiveTextColor); + + final Style drawerStyle = Style( + $box.width(effectiveWidth), + decorationToAttribute( + decoration ?? + ShapeDecorationWithPremultipliedAlpha( + color: effectiveBackgroundColor, + shadows: effectiveDrawerShadows, + shape: MoonBorder(borderRadius: effectiveBorderRadius), + ), + ), + $with.defaultTextStyle.style.as(resolvedTextStyle), + $with.iconTheme.data.color(effectiveIconColor), + ); return Semantics( explicitChildNodes: true, namesRoute: true, scopesRoute: true, label: semanticLabel, - child: IconTheme( - data: IconThemeData(color: effectiveIconColor), - child: DefaultTextStyle( - style: effectiveTextStyle.copyWith(color: effectiveTextColor), - child: Container( - width: effectiveWidth, - decoration: decoration ?? - ShapeDecorationWithPremultipliedAlpha( - color: effectiveBackgroundColor, - shadows: effectiveDrawerShadows, - shape: MoonSquircleBorder( - borderRadius: - effectiveBorderRadius.squircleBorderRadius(context), - ), - ), - child: child, - ), - ), + child: Box( + style: drawerStyle, + child: child, ), ); }