asGlass method Null safety

ClipRRect asGlass(
  1. {double blurX = 4.0,
  2. double blurY = 4.0,
  3. Color tintColor = Colors.white,
  4. bool frosted = true,
  5. BorderRadius? clipBorderRadius = BorderRadius.zero,
  6. Clip clipBehaviour = Clip.antiAlias,
  7. TileMode tileMode = TileMode.clamp,
  8. CustomClipper<RRect>? clipper}
)

.asGlass(): Converts the calling widget into a glass widget.

Parameters:

  • blurX: Amount of blur in the direction of the X axis.
  • blurY: Amount of blur in the direction of the Y axis.
  • tintColor: Tint color for the glass (defaults to Colors.white)
  • frosted: Whether this glass should be frosted or not (defaults to true)
  • clipBorderRadius: The border radius of the rounded corners. Values are clamped so that horizontal and vertical radii sums do not exceed width/height. This value is ignored if clipper is non-null.
  • clipBehaviour: Defaults to Clip.antiAlias.
  • tileMode: Defines what happens at the edge of a gradient or the sampling of a source image in an ImageFilter.
  • clipper: If non-null, determines which clip to use.

Implementation

ClipRRect asGlass({
  double blurX = 4.0,
  double blurY = 4.0,
  Color tintColor = Colors.white,
  bool frosted = true,
  BorderRadius? clipBorderRadius = BorderRadius.zero,
  Clip clipBehaviour = Clip.antiAlias,
  TileMode tileMode = TileMode.clamp,
  CustomClipper<RRect>? clipper,
}) {
  return ClipRRect(
    clipper: clipper,
    clipBehavior: clipBehaviour,
    borderRadius: clipBorderRadius,
    child: BackdropFilter(
      filter: new ImageFilter.blur(
        sigmaX: blurX,
        sigmaY: blurY,
        tileMode: tileMode,
      ),
      child: Container(
        decoration: BoxDecoration(
          gradient: (tintColor != Colors.transparent)
              ? LinearGradient(
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                  colors: [
                    tintColor.withOpacity(0.1),
                    tintColor.withOpacity(0.08),
                  ],
                )
              : null,
          image: frosted
              ? DecorationImage(
                  image: AssetImage('images/noise.png', package: 'glass'),
                  fit: BoxFit.cover,
                )
              : null,
        ),
        child: this,
      ),
    ),
  );
}