wrapWithBackground function

Widget? wrapWithBackground({
  1. Border? border,
  2. Color? backgroundColor,
  3. Widget? child,
  4. bool updateSystemUiOverlay = false,
})

Returns child wrapped with background and a bottom border if background color is opaque. Otherwise, also blur with BackdropFilter.

When updateSystemUiOverlay is true, the nav bar will update the OS status bar's color theme based on the background color of the nav bar.

Implementation

Widget? wrapWithBackground({
  Border? border,
  Color? backgroundColor,
  Widget? child,
  bool updateSystemUiOverlay = false,
}) {
  if (!infoX.isIOS) return child;
  Widget? result = child;
  if (updateSystemUiOverlay) {
    final bool darkBackground = backgroundColor!.computeLuminance() < 0.179;
    final SystemUiOverlayStyle overlayStyle =
        darkBackground ? SystemUiOverlayStyle.light : SystemUiOverlayStyle.dark;
    result = AnnotatedRegion<SystemUiOverlayStyle>(
      value: overlayStyle,
      sized: true,
      child: result!,
    );
  }
  final DecoratedBox childWithBackground = DecoratedBox(
    decoration: BoxDecoration(
      border: border,
      color: backgroundColor,
    ),
    child: result,
  );

  if (backgroundColor!.alpha == 0xFF) return childWithBackground;

  return ClipRect(
    child: BackdropFilter(
      filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
      child: childWithBackground,
    ),
  );
}