Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 32 additions & 40 deletions lib/src/widgets/drawer/drawer.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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<BoxShadow> effectiveDrawerShadows = drawerShadows ??
context.moonTheme?.drawerTheme.shadows.drawerShadows ??
MoonShadows.light.lg;
final List<BoxShadow> 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,
),
);
}
Expand Down