import 'package:flutter/material.dart';

/// Created by @Haoyi on 4/14/21
///

class FlexibleContainer extends StatelessWidget {
  final double? width;
  final double? height;
  final EdgeInsetsGeometry? margin;
  final EdgeInsetsGeometry? padding;
  final Color? borderColor;
  final double? borderWidth;
  final BorderRadius radius;
  final Color? color;
  final DecorationImage? image;
  final List<BoxShadow>? shadows;
  final AlignmentGeometry? alignment;
  final bool needClip;
  final BoxShape shape;
  final Gradient? gradient;
  final BoxConstraints? constraints;
  final Border? border;
  final DecorationImage? foregroundImage;

  final Widget? child;

  const FlexibleContainer(
      {Key? key,
      this.width,
      this.height,
      this.constraints,
      this.margin,
      this.padding,
      this.borderColor,
      this.borderWidth = 1.0,
      this.shape = BoxShape.rectangle,
      this.color,
      this.radius = BorderRadius.zero,
      this.gradient,
      this.shadows,
      this.alignment,
      this.needClip = false,
      this.border,
      this.image,
      this.foregroundImage,
      this.child})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    final constBorderColor = borderColor;
    return Container(
        height: height,
        width: width,
        margin: margin,
        padding: padding,
        constraints: constraints,
        alignment: alignment,
        foregroundDecoration:
            foregroundImage != null ? BoxDecoration(image: foregroundImage) : null,
        decoration: BoxDecoration(
            gradient: gradient,
            border: border ??
                (constBorderColor == null
                    ? null
                    : Border.all(
                        color: constBorderColor,
                        width: borderWidth ?? 1.0,
                        style: BorderStyle.solid,
                      )),
            shape: shape,
            borderRadius: (shape == BoxShape.rectangle && border == null) ? radius : null,
            boxShadow: shadows,
            image: image,
            color: color),
        child: needClip
            ? (shape == BoxShape.circle
                ? ClipOval(
                    child: child,
                  )
                : ClipRRect(
                    borderRadius: radius,
                    child: child,
                  ))
            : child);
  }
}
