Surface constructor

const Surface({
  1. double? width,
  2. double? height,
  3. EdgeInsets margin = const EdgeInsets.all(0),
  4. EdgeInsets padding = const EdgeInsets.all(0),
  5. Color? color,
  6. Color? baseColor,
  7. Gradient? gradient,
  8. Gradient? baseGradient,
  9. Shape shape = const Shape(),
  10. Peek peek = Peek.DEFAULT,
  11. TapSpec tapSpec = const TapSpec(),
  12. Filter filter = Filter.DEFAULT,
  13. Duration duration = const Duration(milliseconds: 500),
  14. Curve curve = Curves.easeIn,
  15. Widget? child,
  16. Clip clipBehavior = Clip.hardEdge,
  17. Key? key,
})

๐ŸŒŸ Surface

A shapeable, layered, intrinsincally animated container Widget offering convenient access to blurring ImageFilters, Material InkResponse, and HapticFeedback.

Property ๐Ÿ”ฒ Peek.peekAlignment has hard-coded recognition of all nine Alignment geometries and will determine which side(s) receive a special border treatment according to property ๐Ÿ”ฒ Peek.peekRatio.

  • defaults at peekRatio: 2 which makes the ๐Ÿ”ฒ Peek.peekAlignment sides twice as thick, but
  • these borders made be made thinner than the others by passing 0 > peekRatio > 1.

Considering:

  1. ๐Ÿ“ CornerSpec property corners and global ๐Ÿ”˜ radius;
  2. ๐Ÿ‘† TapSpec parameters tappable, onTap, providesFeedback & inkHighlightColor, inkSplashColor;
  3. ๐Ÿ”› padLayer initialized ๐Ÿ“š SurfaceLayer.MATERIAL for three effective container layers
  4. ๐Ÿ‘“ SurfaceFilter passed as ๐Ÿ‘“ filterStyle and Map<SurfaceLayer, double> ๐Ÿ“Š radiusMap
  5. duration & curve properties for intrinsic property-change animations;

A ๐ŸŒŸ Surface is robustly customizable and, watch out, could also be expensive.

If not initialized, then default as follows:

  • ๐ŸŽจ color - Theme.of(context).colorScheme.surface.withOpacity(0.3)
  • ๐ŸŽจ baseColor - Theme.of(context).colorScheme.primaryVariant.withOpacity(0.3)

โ— CAUTION

With default ๐Ÿคนโ€โ™‚๏ธ SurfaceFX ๐Ÿ’ง Fx.blurry, only provide ๐Ÿ‘“ Filter.filteredLayers value for which you intend on passing each relevant ๐Ÿ’ง Filter.radiusMap map parameter.

  • Not only are the blurry BackdropFilters expensive, but the inheritance/ancestry behavior is strange.
  • If all three filters are active via ๐Ÿ‘“ Filter.filteredLayers, passing ๐Ÿ“Š baseRadius: 0 eliminates the remaining children filters, regardless of their passed ๐Ÿ“Š radius.
    • This behavior can be worked-around by setting any parent ๐Ÿ“š Layer's radius to just above 0, specifically radius > (_MINIMUM_BLUR == 0.0003)
    • ๐Ÿ“š BASE > ๐Ÿ“š MATERIAL > ๐Ÿ“š CHILD
    • But in this case a different ๐Ÿ‘“ FilterSpec.filteredLayers Set should be passed anyway that only activates the correct ๐Ÿ“š Layer(s).


Simple Example

// Surface with a border that's thicker on bottom & right, with rounded corners
final surface = Surface(
  radius: 10,
  peek: const Peek(
    peekAlignment: Alignment.bottomRight,
    peekRatio: 20,
  ),
);

Implementation

const Surface({
  this.width,
  this.height,
  this.margin = const EdgeInsets.all(0),
  this.padding = const EdgeInsets.all(0),
  this.color,
  this.baseColor,
  this.gradient,
  this.baseGradient,
  this.shape = const Shape(),
  this.peek = Peek.DEFAULT,
  this.tapSpec = const TapSpec(),
  this.filter = Filter.DEFAULT,
  this.duration = const Duration(milliseconds: 500),
  this.curve = Curves.easeIn,
  this.child,
  this.clipBehavior = Clip.hardEdge,
  Key? key,
}) : super(key: key);