mahasMessageBoxWidget function

Widget mahasMessageBoxWidget(
  1. List<MahasMessageModel> models, {
  2. bool withMargin = false,
  3. double? marginBottom,
  4. double? marginTop = 3.0,
  5. bool isJustInformation = false,
  6. Duration? showDuration,
  7. bool withScroll = true,
  8. double? percentHeight,
})

Implementation

Widget mahasMessageBoxWidget(
  List<MahasMessageModel> models, {
  bool withMargin = false,
  double? marginBottom,
  double? marginTop = 3.0,
  bool isJustInformation = false,
  Duration? showDuration,
  bool withScroll = true,
  double? percentHeight,
}) {
  if (models.isEmpty) return Container();

  widget() => SizedBox(
        height: percentHeight == null
            ? null
            : MahasDimensions.getHeightPercentSize(percentHeight),
        child: Column(
          children: [
            if (marginTop != null) getSpaceHeight(marginTop),
            Container(
              margin: withMargin
                  ? EdgeInsets.symmetric(
                      horizontal: MahasDimensions.getAppBarPadding(),
                    )
                  : null,
              width: double.infinity,
              decoration: BoxDecoration(
                color: isJustInformation
                    ? MahasColors.statusBaruColor.withOpacity(.2)
                    : MahasColors.dangerColor.withOpacity(.2),
                borderRadius: BorderRadius.circular(
                  MahasDimensions.getInputRadius(),
                ),
              ),
              child: Padding(
                padding: EdgeInsets.symmetric(
                  vertical: MahasDimensions.getHeightPercentSize(1),
                  horizontal: MahasDimensions.getWidthPercentSize(2.5),
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: models
                      .expand((element) => element.errorMessages)
                      .map(
                        (e) => getCustomTextWithoutMaxLine(e,
                            align: TextAlign.start),
                      )
                      .toList(),
                ),
              ),
            ),
            if (marginBottom != null) getSpaceHeight(marginBottom),
          ],
        ),
      );

  if (!withScroll) return widget();

  return SingleChildScrollView(
    physics: const AlwaysScrollableScrollPhysics(),
    child: widget(),
  );
}