showToastMessage method

void showToastMessage({
  1. required ToastEnum toastEnum,
  2. required String toastMessage,
  3. Color? fontColor,
  4. double? fontSize,
  5. FontWeight? fontWeight,
})

Implementation

void showToastMessage({
  required ToastEnum toastEnum,
  required String toastMessage,
  Color? fontColor,
  double? fontSize,
  FontWeight? fontWeight,
}) {
  // initialize flutter toast
  FToast fToast = FToast();
  fToast.init(this);
  // remove all flutter toast that has been kept on queue
  // before displaying new toast
  fToast.removeQueuedCustomToasts();

  Widget toast = Container(
    // padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
    padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
    decoration: BoxDecoration(
      borderRadius: BorderRadius.circular(16.r),
      color: _getColorBasedOnToastEnum(toastEnum),
    ),
    child: Row(
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        Expanded(
          child: Text(
            toastMessage,
            maxLines: 3,
            overflow: TextOverflow.ellipsis,
            style: Theme.of(this).textTheme.bodyMedium?.copyWith(
                  color: fontColor ?? Colors.white,
                  fontSize: fontSize,
                  fontWeight: fontWeight,
                ),
          ),
        ),
      ],
    ),
  );

  fToast.showToast(
    child: toast,
    gravity: ToastGravity.BOTTOM,
    toastDuration: const Duration(seconds: 3),
  );
}