build method

  1. @override
Widget build (
  1. BuildContext context
)
override

👷‍♂️ Build Surface

Implementation

@override
Widget build(BuildContext context) {
  if (corners == SurfaceCorners.SQUARE) if (radius != null)
    print(
        '[$context] > [borderRadius] passed non-null value while [corners] also set to SurfaceCorners.SQUARE. \n[borderRadius] will be ignored.');
  if (corners != SurfaceCorners.BEVEL && (flipBevels ?? false))
    print(
        '[$context] > Parameter [flipBevels] will be ignored because [corners] not set to [SurfaceCorners.BEVEL].');
  if (gradient != null && color != _DEFAULT_COLOR)
    print(
        '[$context] > Both [gradient] and [color] have been passed, so [color] will be ignored.');
  if (borderGradient != null && borderColor != _DEFAULT_COLOR_BORDER)
    print(
        '[$context] > Both [borderGadient] and [borderColor] have been passed, so [borderColor] will be ignored.');

  /// 🔢 Establish the thickness of each border-side (padding property for [borderContainer])
  /// based on [borderThickness] and considering [borderAlignment] & [borderRatio]
  final double left = (borderAlignment == Alignment.topLeft ||
          borderAlignment == Alignment.centerLeft ||
          borderAlignment == Alignment.bottomLeft)
      ? borderThickness * borderRatio
      : borderThickness;
  final double top = (borderAlignment == Alignment.topLeft ||
          borderAlignment == Alignment.topCenter ||
          borderAlignment == Alignment.topRight)
      ? borderThickness * borderRatio
      : borderThickness;
  final double right = (borderAlignment == Alignment.topRight ||
          borderAlignment == Alignment.centerRight ||
          borderAlignment == Alignment.bottomRight)
      ? borderThickness * borderRatio
      : borderThickness;
  final double bottom = (borderAlignment == Alignment.bottomLeft ||
          borderAlignment == Alignment.bottomCenter ||
          borderAlignment == Alignment.bottomRight)
      ? borderThickness * borderRatio
      : borderThickness;

  /// 🧅 [innerMaterial] may contain [buildInkResponse] but always eventually
  /// holds [child], as the InkResponse will soon [buildChild] as well.
  ///
  /// Supply [width], [height], and [margin] in the case where
  /// [borderContainer] is not built ([disableBorder] `== true`).
  Widget innerMaterial = AnimatedContainer(
    /// [width] and [height] may be `null` anyway
    width: (disableBorder) ? width : null,
    height: (disableBorder) ? height : null,
    margin: (disableBorder) ? margin : const EdgeInsets.all(0),
    duration: duration,
    curve: curve,

    /// Build shape and color for [innerMaterial]
    decoration: _buildDecoration(
      layer: SurfaceLayer.MATERIAL,
      isGradient: (gradient != null),
    ),

    /// Material will be canvas for [child] and respond to touches
    child: Material(
      color: const Color(0x00FFFFFF),
      child: (tappable) ? _buildInkResponse() : _buildChild(),
    ),
  );

  /// 🐚 [borderContainer] contains [innerMaterial] & represents [Surface] border
  Widget borderContainer = AnimatedContainer(
    /// [width] and [height] may be `null` anyway
    width: width,
    height: height,
    margin: margin,
    duration: duration,
    curve: curve,

    /// 🔲 This padding is effectively the border of the [Surface]
    padding: (borderAlignment == null || borderAlignment == Alignment.center)
        ? EdgeInsets.all(borderThickness)

        /// Generated at start of build() using [borderThickness].
        : EdgeInsets.fromLTRB(left, top, right, bottom),

    /// Build shape and color for [borderContainer]
    decoration: _buildDecoration(
      layer: SurfaceLayer.BORDER,
      isGradient: (borderGradient != null),
    ),

    /// 🧅 [innerMaterial] as descendent of 🐚 [borderContainer]
    child: _filterOrChild(
      layer: SurfaceLayer.MATERIAL,
      child: innerMaterial,
    ),
  );

  /// ### 📤 Return [Surface]
  if (disableBorder)
    return _filterOrChild(layer: SurfaceLayer.MATERIAL, child: innerMaterial);
  else
    return _filterOrChild(layer: SurfaceLayer.BORDER, child: borderContainer);
}