showToast static method

void showToast(
  1. String message, {
  2. String? title,
})

Implementation

static void showToast(String message, {String? title}) {
  final now = DateTime.now();

  // Prevent showing toasts if another was just shown recently
  if (_lastShownTime != null &&
      now.difference(_lastShownTime!) < _cooldown) {
    return;
  }

  _lastShownTime = now;

  // Cancel existing toast before showing a new one
  Fluttertoast.cancel();

  // Show the toast
  Fluttertoast.showToast(
    msg: title != null ? "$title\n$message" : message,
    toastLength: Toast.LENGTH_SHORT,
    gravity: ToastGravity.TOP,
    backgroundColor: Colors.black87,
    textColor: Colors.white,
    fontSize: 16.0,
  );
}