GlassContainer constructor

GlassContainer({
  1. Key? key,
  2. required double height,
  3. required double width,
  4. AlignmentGeometry? alignment,
  5. Matrix4? transform,
  6. AlignmentGeometry? transformAlignment,
  7. EdgeInsetsGeometry? padding,
  8. EdgeInsetsGeometry? margin,
  9. Color? color,
  10. Gradient? gradient,
  11. BorderRadius? borderRadius,
  12. double? borderWidth,
  13. Color? borderColor,
  14. Gradient? borderGradient,
  15. double? blur,
  16. bool? isFrostedGlass,
  17. double? frostedOpacity,
  18. double? elevation,
  19. Color? shadowColor,
  20. BoxShape shape = BoxShape.rectangle,
  21. Widget? child,
})

Creates a widget by combining common painting, sizing, and positioning widgets to implement Glass Morphism.

  • The arguments height and width must not be null.
  • Both color and gradient cannot be null. Same goes for borderColor and borderGradient. Preference is given to gradient during painting.
  • The borderRadius argument must be null if the shape is BoxShape.Circle
  • By default borderWidth is 1.0, isFrosted is set to false and blur value is set to 12.0.
  • If the shape is BoxShape.circle then height is used as the diameter.

The shape argument must not be null.

Implementation

GlassContainer({
  Key? key,
  required this.height,
  required this.width,
  this.alignment,
  this.transform,
  this.transformAlignment,
  this.padding,
  this.margin,
  this.color,
  this.gradient,
  BorderRadius? borderRadius,
  double? borderWidth,
  this.borderColor,
  this.borderGradient,
  double? blur,
  bool? isFrostedGlass,
  double? frostedOpacity,
  double? elevation,
  Color? shadowColor,
  BoxShape shape = BoxShape.rectangle,
  this.child,
})  : borderWidth = borderWidth ?? kBorderWidth,
      blur = blur ?? kBlur,
      isFrostedGlass = isFrostedGlass ?? kIsFrosted,
      frostedOpacity = frostedOpacity ?? kFrostedOpacity,
      elevation = elevation ?? kElevation,
      shadowColor = shadowColor ?? kShadowColor,
      shape = shape,
      borderRadius = shape == BoxShape.rectangle
          ? (borderRadius ?? kBorderRadius)
          : null,
      assert(color != null || gradient != null,
          'Both color and gradient cannot be null\n'),
      assert(borderColor != null || borderGradient != null,
          'Both borderColor and borderGradient cannot be null\n'),
      assert(shape != BoxShape.circle || borderRadius == null,
          'The [borderRadius] needs to be null if the shape is [BoxShape.circle]\n'),
      assert(kIsWeb != true || borderColor != null,
          'borderColor cannot be null when runing on the Web\n'),
      super(key: key);