showToastNotification function

dynamic showToastNotification(
  1. BuildContext context, {
  2. ToastNotificationStyleType? style,
  3. String? title,
  4. IconData? icon,
  5. String description = "",
  6. Duration? duration,
})

Display a new Toast notification to the user. Provide a valid ToastNotificationStyleType i.e ToastNotificationStyleType.SUCCESS Set a title, description to personalise the message.

Implementation

showToastNotification(BuildContext context,
    {ToastNotificationStyleType? style,
    String? title,
    IconData? icon,
    String description = "",
    Duration? duration}) {
  _ToastMeta toastMeta = _ToastNotificationStyleMetaHelper.getValue(style);
  toastMeta.title = toastMeta.title;
  if (title != null) {
    toastMeta.title = title;
  }
  toastMeta.description = description;

  Widget _icon = toastMeta.icon;
  if (icon != null) {
    _icon = Icon(icon, color: Colors.white);
  }

  // show the toast notification
  showToastWidget(
    Stack(children: [
      Container(
        padding: EdgeInsets.symmetric(horizontal: 18.0),
        margin: EdgeInsets.symmetric(horizontal: 8.0),
        height: 100,
        decoration: ShapeDecoration(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(8.0),
          ),
          color: toastMeta.color,
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Pulse(
              child: Container(
                child: Center(
                  child: IconButton(
                    onPressed: () {},
                    icon: _icon,
                    padding: EdgeInsets.only(right: 16),
                  ),
                ),
              ),
              infinite: true,
              duration: Duration(milliseconds: 1500),
            ),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    toastMeta.title,
                    style: Theme.of(context)
                        .textTheme
                        .headlineSmall!
                        .copyWith(color: Colors.white),
                  ),
                  Text(
                    toastMeta.description,
                    style: Theme.of(context)
                        .textTheme
                        .bodyLarge!
                        .copyWith(color: Colors.white),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
      Positioned(
        top: 0,
        right: 0,
        child: IconButton(
            onPressed: () {
              ToastManager().dismissAll(showAnim: true);
            },
            icon: Icon(
              Icons.close,
              color: Colors.white,
            )),
      )
    ]),
    context: context,
    isIgnoring: false,
    position: StyledToastPosition.top,
    animation: StyledToastAnimation.slideFromTopFade,
    duration: duration ?? toastMeta.duration,
  );
}