Skip to content

Commit

Permalink
fix: [MDS-499] Refactor EdgeInsets and Alignment to use Geometry vari…
Browse files Browse the repository at this point in the history
…ants (#138)
  • Loading branch information
GittHub-d authored Apr 17, 2023
1 parent 755bbb9 commit 7b88df7
Show file tree
Hide file tree
Showing 22 changed files with 113 additions and 85 deletions.
13 changes: 7 additions & 6 deletions example/lib/src/storybook/stories/authcode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import 'package:flutter/material.dart';
import 'package:moon_design/moon_design.dart';
import 'package:storybook_flutter/storybook_flutter.dart';

final StreamController<ErrorAnimationType> errorController = StreamController<ErrorAnimationType>();
// Broadcast is used as a hack to overcome Storybook stale state
final StreamController<ErrorAnimationType> errorStreamController = StreamController<ErrorAnimationType>.broadcast();

class AuthCodeStory extends Story {
AuthCodeStory()
Expand Down Expand Up @@ -156,7 +157,7 @@ class AuthCodeStory extends Story {
gap: gapKnob.toDouble(),
authFieldShape: shapeKnob,
obscureText: obscuringKnob,
obscuringCharacter: '*',
obscuringCharacter: '',
peekWhenObscuring: peekWhenObscuringKnob,
validator: (String? value) => null,
errorBuilder: (BuildContext context, String? errorText) => const SizedBox(),
Expand All @@ -178,7 +179,7 @@ class AuthCodeStory extends Story {
gap: gapKnob.toDouble(),
authFieldShape: shapeKnob,
obscureText: obscuringKnob,
obscuringCharacter: '*',
obscuringCharacter: '',
peekWhenObscuring: peekWhenObscuringKnob,
validator: (String? value) => null,
errorBuilder: (BuildContext context, String? errorText) => const SizedBox(),
Expand All @@ -193,7 +194,7 @@ class AuthCodeStory extends Story {
authInputFieldCount: 4,
mainAxisAlignment: mainAxisAlignmentKnob,
borderRadius: BorderRadius.circular(borderRadiusKnob.toDouble()),
errorStreamController: errorController,
errorStreamController: errorStreamController,
selectedFillColor: selectedFillColor,
activeFillColor: activeFillColor,
inactiveFillColor: inactiveFillColor,
Expand All @@ -203,11 +204,11 @@ class AuthCodeStory extends Story {
gap: gapKnob.toDouble(),
authFieldShape: shapeKnob,
obscureText: obscuringKnob,
obscuringCharacter: '*',
obscuringCharacter: '',
peekWhenObscuring: peekWhenObscuringKnob,
onCompleted: (pin) {
if (pin != '9921') {
errorController.add(
errorStreamController.add(
errorAnimationKnob ? ErrorAnimationType.shake : ErrorAnimationType.noAnimation,
);
}
Expand Down
6 changes: 6 additions & 0 deletions example/lib/src/storybook/storybook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ class StorybookPage extends StatelessWidget {
TooltipStory(),
],
),

// hack for preloading the unicode character
const SizedBox(
height: 0,
child: Text('﹡'),
),
const Align(
alignment: Alignment.bottomCenter,
child: MoonVersionWidget(),
Expand Down
8 changes: 4 additions & 4 deletions lib/src/theme/accordion/accordion_item_size_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MoonAccordionItemSizeProperties extends ThemeExtension<MoonAccordionItemSi
final double iconSizeValue;

/// Padding around accordion title and icon.
final EdgeInsets headerPadding;
final EdgeInsetsGeometry headerPadding;

/// Accordion text style.
final TextStyle textStyle;
Expand All @@ -60,7 +60,7 @@ class MoonAccordionItemSizeProperties extends ThemeExtension<MoonAccordionItemSi
MoonAccordionItemSizeProperties copyWith({
double? headerHeight,
double? iconSizeValue,
EdgeInsets? headerPadding,
EdgeInsetsGeometry? headerPadding,
TextStyle? textStyle,
}) {
return MoonAccordionItemSizeProperties(
Expand All @@ -78,7 +78,7 @@ class MoonAccordionItemSizeProperties extends ThemeExtension<MoonAccordionItemSi
return MoonAccordionItemSizeProperties(
headerHeight: lerpDouble(headerHeight, other.headerHeight, t)!,
iconSizeValue: lerpDouble(iconSizeValue, other.iconSizeValue, t)!,
headerPadding: EdgeInsets.lerp(headerPadding, other.headerPadding, t)!,
headerPadding: EdgeInsetsGeometry.lerp(headerPadding, other.headerPadding, t)!,
textStyle: TextStyle.lerp(textStyle, other.textStyle, t)!,
);
}
Expand All @@ -90,7 +90,7 @@ class MoonAccordionItemSizeProperties extends ThemeExtension<MoonAccordionItemSi
..add(DiagnosticsProperty("type", "MoonAccordionItemSizeProperties"))
..add(DoubleProperty("headerHeight", headerHeight))
..add(DoubleProperty("iconSizeValue", iconSizeValue))
..add(DiagnosticsProperty<EdgeInsets>("headerPadding", headerPadding))
..add(DiagnosticsProperty<EdgeInsetsGeometry>("headerPadding", headerPadding))
..add(DiagnosticsProperty<TextStyle>("textStyle", textStyle));
}
}
8 changes: 4 additions & 4 deletions lib/src/theme/alert/alert_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MoonAlertProperties extends ThemeExtension<MoonAlertProperties> with Diagn
final Curve transitionCurve;

/// Alert padding.
final EdgeInsets padding;
final EdgeInsetsGeometry padding;

/// Alert body text style.
final TextStyle bodyTextStyle;
Expand Down Expand Up @@ -67,7 +67,7 @@ class MoonAlertProperties extends ThemeExtension<MoonAlertProperties> with Diagn
double? verticalGap,
Duration? transitionDuration,
Curve? transitionCurve,
EdgeInsets? padding,
EdgeInsetsGeometry? padding,
TextStyle? bodyTextStyle,
TextStyle? titleTextStyle,
}) {
Expand Down Expand Up @@ -95,7 +95,7 @@ class MoonAlertProperties extends ThemeExtension<MoonAlertProperties> with Diagn
verticalGap: lerpDouble(verticalGap, other.verticalGap, t)!,
transitionDuration: lerpDuration(transitionDuration, other.transitionDuration, t),
transitionCurve: other.transitionCurve,
padding: EdgeInsets.lerp(padding, other.padding, t)!,
padding: EdgeInsetsGeometry.lerp(padding, other.padding, t)!,
bodyTextStyle: TextStyle.lerp(bodyTextStyle, other.bodyTextStyle, t)!,
titleTextStyle: TextStyle.lerp(titleTextStyle, other.titleTextStyle, t)!,
);
Expand All @@ -112,7 +112,7 @@ class MoonAlertProperties extends ThemeExtension<MoonAlertProperties> with Diagn
..add(DiagnosticsProperty<double>("verticalGap", verticalGap))
..add(DiagnosticsProperty<Duration>("transitionDuration", transitionDuration))
..add(DiagnosticsProperty<Curve>("transitionCurve", transitionCurve))
..add(DiagnosticsProperty<EdgeInsets>("padding", padding))
..add(DiagnosticsProperty<EdgeInsetsGeometry>("padding", padding))
..add(DiagnosticsProperty<TextStyle>("bodyTextStyle", bodyTextStyle))
..add(DiagnosticsProperty<TextStyle>("titleTextStyle", titleTextStyle));
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/theme/button/button_size_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class MoonButtonSizeProperties extends ThemeExtension<MoonButtonSizeProperties>
final double iconSizeValue;

/// Padding around button children.
final EdgeInsets padding;
final EdgeInsetsGeometry padding;

/// Button border radius.
final BorderRadius borderRadius;
Expand All @@ -86,7 +86,7 @@ class MoonButtonSizeProperties extends ThemeExtension<MoonButtonSizeProperties>
double? height,
double? gap,
double? iconSizeValue,
EdgeInsets? padding,
EdgeInsetsGeometry? padding,
BorderRadius? borderRadius,
TextStyle? textStyle,
}) {
Expand All @@ -108,7 +108,7 @@ class MoonButtonSizeProperties extends ThemeExtension<MoonButtonSizeProperties>
height: lerpDouble(height, other.height, t)!,
gap: lerpDouble(gap, other.gap, t)!,
iconSizeValue: lerpDouble(iconSizeValue, other.iconSizeValue, t)!,
padding: EdgeInsets.lerp(padding, other.padding, t)!,
padding: EdgeInsetsGeometry.lerp(padding, other.padding, t)!,
borderRadius: BorderRadius.lerp(borderRadius, other.borderRadius, t)!,
textStyle: TextStyle.lerp(textStyle, other.textStyle, t)!,
);
Expand All @@ -122,7 +122,7 @@ class MoonButtonSizeProperties extends ThemeExtension<MoonButtonSizeProperties>
..add(DoubleProperty("height", height))
..add(DoubleProperty("gap", gap))
..add(DoubleProperty("iconSizeValue", iconSizeValue))
..add(DiagnosticsProperty<EdgeInsets>("padding", padding))
..add(DiagnosticsProperty<EdgeInsetsGeometry>("padding", padding))
..add(DiagnosticsProperty<BorderRadius>("borderRadius", borderRadius))
..add(DiagnosticsProperty<TextStyle>("textStyle", textStyle));
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/theme/chip/chip_size_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MoonChipSizeProperties extends ThemeExtension<MoonChipSizeProperties> with
final double iconSizeValue;

/// Padding around chip children.
final EdgeInsets padding;
final EdgeInsetsGeometry padding;

/// Chip border radius.
final BorderRadius borderRadius;
Expand All @@ -59,7 +59,7 @@ class MoonChipSizeProperties extends ThemeExtension<MoonChipSizeProperties> with
double? height,
double? gap,
double? iconSizeValue,
EdgeInsets? padding,
EdgeInsetsGeometry? padding,
BorderRadius? borderRadius,
TextStyle? textStyle,
}) {
Expand All @@ -81,7 +81,7 @@ class MoonChipSizeProperties extends ThemeExtension<MoonChipSizeProperties> with
height: lerpDouble(height, other.height, t)!,
gap: lerpDouble(gap, other.gap, t)!,
iconSizeValue: lerpDouble(iconSizeValue, other.iconSizeValue, t)!,
padding: EdgeInsets.lerp(padding, other.padding, t)!,
padding: EdgeInsetsGeometry.lerp(padding, other.padding, t)!,
borderRadius: BorderRadius.lerp(borderRadius, other.borderRadius, t)!,
textStyle: TextStyle.lerp(textStyle, other.textStyle, t)!,
);
Expand All @@ -95,7 +95,7 @@ class MoonChipSizeProperties extends ThemeExtension<MoonChipSizeProperties> with
..add(DoubleProperty("height", height))
..add(DoubleProperty("gap", gap))
..add(DoubleProperty("iconSizeValue", iconSizeValue))
..add(DiagnosticsProperty<EdgeInsets>("padding", padding))
..add(DiagnosticsProperty<EdgeInsetsGeometry>("padding", padding))
..add(DiagnosticsProperty<BorderRadius>("borderRadius", borderRadius))
..add(DiagnosticsProperty<TextStyle>("textStyle", textStyle));
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/theme/popover/popover_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MoonPopoverProperties extends ThemeExtension<MoonPopoverProperties> with D
final double distanceToTarget;

/// Padding around popover content.
final EdgeInsets contentPadding;
final EdgeInsetsGeometry contentPadding;

/// Popover border radius.
final BorderRadius borderRadius;
Expand All @@ -42,7 +42,7 @@ class MoonPopoverProperties extends ThemeExtension<MoonPopoverProperties> with D
@override
MoonPopoverProperties copyWith({
double? distanceToTarget,
EdgeInsets? contentPadding,
EdgeInsetsGeometry? contentPadding,
BorderRadius? borderRadius,
Duration? transitionDuration,
Curve? transitionCurve,
Expand All @@ -62,7 +62,7 @@ class MoonPopoverProperties extends ThemeExtension<MoonPopoverProperties> with D

return MoonPopoverProperties(
distanceToTarget: lerpDouble(distanceToTarget, other.distanceToTarget, t)!,
contentPadding: EdgeInsets.lerp(contentPadding, other.contentPadding, t)!,
contentPadding: EdgeInsetsGeometry.lerp(contentPadding, other.contentPadding, t)!,
borderRadius: BorderRadius.lerp(borderRadius, other.borderRadius, t)!,
transitionDuration: lerpDuration(transitionDuration, other.transitionDuration, t),
transitionCurve: other.transitionCurve,
Expand All @@ -75,7 +75,7 @@ class MoonPopoverProperties extends ThemeExtension<MoonPopoverProperties> with D
properties
..add(DiagnosticsProperty("type", "MoonPopoverProperties"))
..add(DoubleProperty("distanceToTarget", distanceToTarget))
..add(DiagnosticsProperty<EdgeInsets>("contentPadding", contentPadding))
..add(DiagnosticsProperty<EdgeInsetsGeometry>("contentPadding", contentPadding))
..add(DiagnosticsProperty<BorderRadius>("borderRadius", borderRadius))
..add(DiagnosticsProperty<Duration>("transitionDuration", transitionDuration))
..add(DiagnosticsProperty<Curve>("transitionCurve", transitionCurve));
Expand Down
8 changes: 4 additions & 4 deletions lib/src/theme/switch/switch_size_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MoonSwitchSizeProperties extends ThemeExtension<MoonSwitchSizeProperties>
final double thumbSizeValue;

/// Switch track padding.
final EdgeInsets padding;
final EdgeInsetsGeometry padding;

const MoonSwitchSizeProperties({
required this.width,
Expand All @@ -52,7 +52,7 @@ class MoonSwitchSizeProperties extends ThemeExtension<MoonSwitchSizeProperties>
double? width,
double? height,
double? thumbSizeValue,
EdgeInsets? padding,
EdgeInsetsGeometry? padding,
}) {
return MoonSwitchSizeProperties(
width: width ?? this.width,
Expand All @@ -70,7 +70,7 @@ class MoonSwitchSizeProperties extends ThemeExtension<MoonSwitchSizeProperties>
width: lerpDouble(width, other.width, t)!,
height: lerpDouble(height, other.height, t)!,
thumbSizeValue: lerpDouble(thumbSizeValue, other.thumbSizeValue, t)!,
padding: EdgeInsets.lerp(padding, other.padding, t)!,
padding: EdgeInsetsGeometry.lerp(padding, other.padding, t)!,
);
}

Expand All @@ -82,6 +82,6 @@ class MoonSwitchSizeProperties extends ThemeExtension<MoonSwitchSizeProperties>
..add(DoubleProperty("width", width))
..add(DoubleProperty("height", height))
..add(DoubleProperty("thumbSizeValue", thumbSizeValue))
..add(DiagnosticsProperty<EdgeInsets>("padding", padding));
..add(DiagnosticsProperty<EdgeInsetsGeometry>("padding", padding));
}
}
8 changes: 4 additions & 4 deletions lib/src/theme/tag/tag_size_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MoonTagSizeProperties extends ThemeExtension<MoonTagSizeProperties> with D
final double iconSizeValue;

/// Padding around tag children.
final EdgeInsets padding;
final EdgeInsetsGeometry padding;

/// Tag border radius.
final BorderRadius borderRadius;
Expand All @@ -65,7 +65,7 @@ class MoonTagSizeProperties extends ThemeExtension<MoonTagSizeProperties> with D
double? height,
double? gap,
double? iconSizeValue,
EdgeInsets? padding,
EdgeInsetsGeometry? padding,
BorderRadius? borderRadius,
TextStyle? textStyle,
TextStyle? upperCaseTextStyle,
Expand All @@ -89,7 +89,7 @@ class MoonTagSizeProperties extends ThemeExtension<MoonTagSizeProperties> with D
height: lerpDouble(height, other.height, t)!,
gap: lerpDouble(gap, other.gap, t)!,
iconSizeValue: lerpDouble(iconSizeValue, other.iconSizeValue, t)!,
padding: EdgeInsets.lerp(padding, other.padding, t)!,
padding: EdgeInsetsGeometry.lerp(padding, other.padding, t)!,
borderRadius: BorderRadius.lerp(borderRadius, other.borderRadius, t)!,
textStyle: TextStyle.lerp(textStyle, other.textStyle, t)!,
upperCaseTextStyle: TextStyle.lerp(upperCaseTextStyle, other.upperCaseTextStyle, t)!,
Expand All @@ -104,7 +104,7 @@ class MoonTagSizeProperties extends ThemeExtension<MoonTagSizeProperties> with D
..add(DoubleProperty("height", height))
..add(DoubleProperty("gap", gap))
..add(DoubleProperty("iconSizeValue", iconSizeValue))
..add(DiagnosticsProperty<EdgeInsets>("padding", padding))
..add(DiagnosticsProperty<EdgeInsetsGeometry>("padding", padding))
..add(DiagnosticsProperty<BorderRadius>("borderRadius", borderRadius))
..add(DiagnosticsProperty<TextStyle>("textStyle", textStyle))
..add(DiagnosticsProperty<TextStyle>("upperCaseTextStyle", upperCaseTextStyle));
Expand Down
8 changes: 4 additions & 4 deletions lib/src/theme/toast/toast_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MoonToastProperties extends ThemeExtension<MoonToastProperties> with Diagn
final BorderRadius borderRadius;

/// Padding around toast content.
final EdgeInsets contentPadding;
final EdgeInsetsGeometry contentPadding;

/// Space between toast children.
final double gap;
Expand All @@ -48,7 +48,7 @@ class MoonToastProperties extends ThemeExtension<MoonToastProperties> with Diagn
@override
MoonToastProperties copyWith({
BorderRadius? borderRadius,
EdgeInsets? contentPadding,
EdgeInsetsGeometry? contentPadding,
double? gap,
Duration? displayDuration,
Duration? transitionDuration,
Expand All @@ -70,7 +70,7 @@ class MoonToastProperties extends ThemeExtension<MoonToastProperties> with Diagn

return MoonToastProperties(
borderRadius: BorderRadius.lerp(borderRadius, other.borderRadius, t)!,
contentPadding: EdgeInsets.lerp(contentPadding, other.contentPadding, t)!,
contentPadding: EdgeInsetsGeometry.lerp(contentPadding, other.contentPadding, t)!,
gap: lerpDouble(gap, other.gap, t)!,
displayDuration: lerpDuration(displayDuration, other.displayDuration, t),
transitionDuration: lerpDuration(transitionDuration, other.transitionDuration, t),
Expand All @@ -84,7 +84,7 @@ class MoonToastProperties extends ThemeExtension<MoonToastProperties> with Diagn
properties
..add(DiagnosticsProperty("type", "MoonToastProperties"))
..add(DiagnosticsProperty<BorderRadius>("borderRadius", borderRadius))
..add(DiagnosticsProperty<EdgeInsets>("contentPadding", contentPadding))
..add(DiagnosticsProperty<EdgeInsetsGeometry>("contentPadding", contentPadding))
..add(DoubleProperty("gap", gap))
..add(DiagnosticsProperty<Duration>("displayDuration", displayDuration))
..add(DiagnosticsProperty<Duration>("transitionDuration", transitionDuration))
Expand Down
8 changes: 4 additions & 4 deletions lib/src/theme/tooltip/tooltip_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MoonTooltipProperties extends ThemeExtension<MoonTooltipProperties> with D
final double arrowTipDistance;

/// Padding around tooltip content.
final EdgeInsets contentPadding;
final EdgeInsetsGeometry contentPadding;

/// Tooltip border radius.
final BorderRadius borderRadius;
Expand Down Expand Up @@ -60,7 +60,7 @@ class MoonTooltipProperties extends ThemeExtension<MoonTooltipProperties> with D
double? arrowBaseWidth,
double? arrowLength,
double? arrowTipDistance,
EdgeInsets? contentPadding,
EdgeInsetsGeometry? contentPadding,
BorderRadius? borderRadius,
Duration? transitionDuration,
Curve? transitionCurve,
Expand All @@ -86,7 +86,7 @@ class MoonTooltipProperties extends ThemeExtension<MoonTooltipProperties> with D
arrowBaseWidth: lerpDouble(arrowBaseWidth, other.arrowBaseWidth, t)!,
arrowLength: lerpDouble(arrowLength, other.arrowLength, t)!,
arrowTipDistance: lerpDouble(arrowTipDistance, other.arrowTipDistance, t)!,
contentPadding: EdgeInsets.lerp(contentPadding, other.contentPadding, t)!,
contentPadding: EdgeInsetsGeometry.lerp(contentPadding, other.contentPadding, t)!,
borderRadius: BorderRadius.lerp(borderRadius, other.borderRadius, t)!,
transitionDuration: lerpDuration(transitionDuration, other.transitionDuration, t),
transitionCurve: other.transitionCurve,
Expand All @@ -102,7 +102,7 @@ class MoonTooltipProperties extends ThemeExtension<MoonTooltipProperties> with D
..add(DoubleProperty("arrowBaseWidth", arrowBaseWidth))
..add(DoubleProperty("arrowLength", arrowLength))
..add(DoubleProperty("arrowTipDistance", arrowTipDistance))
..add(DiagnosticsProperty<EdgeInsets>("contentPadding", contentPadding))
..add(DiagnosticsProperty<EdgeInsetsGeometry>("contentPadding", contentPadding))
..add(DiagnosticsProperty<BorderRadius>("borderRadius", borderRadius))
..add(DiagnosticsProperty<Duration>("transitionDuration", transitionDuration))
..add(DiagnosticsProperty<Curve>("transitionCurve", transitionCurve))
Expand Down
Loading

0 comments on commit 7b88df7

Please sign in to comment.