getWrappedWidget method

Widget getWrappedWidget(
  1. Widget content,
  2. double? width,
  3. double? height,
  4. double? aspectRatio,
)

Implementation

Widget getWrappedWidget(
    Widget content, double? width, double? height, double? aspectRatio) {
  Widget wrappedWidget;

  if (width != null && aspectRatio == null && height == null) {
    // 1. only width is given, nothing else
    wrappedWidget = SizedBox(
      width: width,
      height: double.infinity,
      child: content,
    );
  } else if (height != null && aspectRatio == null && width == null) {
    // 2. only height is given, nothing else
    wrappedWidget = SizedBox(
      width: double.infinity,
      height: height,
      child: content,
    );
  } else if (width != null && height != null && aspectRatio == null) {
    // 3. only width and height is given, no aspectRatio
    wrappedWidget = SizedBox(
      width: width,
      height: height,
      child: content,
    );
  } else if (aspectRatio != null && width == null && height == null) {
    // 4. only aspectRatio is given, no width and no height
    wrappedWidget = AspectRatio(
      aspectRatio: aspectRatio,
      child: content,
    );
  } else if (aspectRatio != null && width != null && height == null) {
    // 5. no height is given, but width and aspectRatio
    wrappedWidget = SizedBox(
      width: width,
      height: width / aspectRatio,
      child: content,
    );
  } else if (aspectRatio != null && height != null && width == null) {
    // 6. no width is given, but height and aspectRatio
    wrappedWidget = SizedBox(
      width: height * aspectRatio,
      height: height,
      child: content,
    );
  } else {
    // none of the above applies which means either no size input at all
    // or we got an aspectRatio AND width/height constraint.
    // -> Fallback to 16/9 video.
    wrappedWidget = AspectRatio(
      aspectRatio: 16.0 / 9.0,
      child: content,
    );
  }

  return wrappedWidget;
}