wrapSizedWidgetWithBackground function

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

Implementation

PreferredSizeWidget? wrapSizedWidgetWithBackground({
  Border? border,
  Color? backgroundColor,
  PreferredSizeWidget? 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 PreferredSize(
      preferredSize: child!.preferredSize,
      child: childWithBackground,
    );
  }

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