Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a helper to work with Toasts #65

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions lib/presentation/utils/toast/toaster.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

abstract class Toaster {
const Toaster._();

static Future<bool?> show(
String message, {
bool dismissPreviousToast = false,
Toast length = Toast.LENGTH_SHORT,
Color? textColor,
Color? backgroundColor,
double? fontSize,
ToastGravity? gravity,
}) async {
if (dismissPreviousToast) {
await Fluttertoast.cancel();
}

return Fluttertoast.showToast(
msg: message,
toastLength: length,
textColor: textColor,
backgroundColor: backgroundColor,
fontSize: fontSize,
gravity: gravity,
);
}

static Future<bool?> showLong(
String message, {
bool dismissPreviousToast = false,
Color? textColor,
Color? backgroundColor,
double? fontSize,
ToastGravity? gravity,
}) {
return show(
message,
dismissPreviousToast: dismissPreviousToast,
length: Toast.LENGTH_LONG,
textColor: textColor,
backgroundColor: backgroundColor,
fontSize: fontSize,
gravity: gravity,
);
}

static Future<bool?> showShort(
String message, {
bool dismissPreviousToast = false,
Color? textColor,
Color? backgroundColor,
double? fontSize,
ToastGravity? gravity,
}) async {
return show(
message,
dismissPreviousToast: dismissPreviousToast,
length: Toast.LENGTH_SHORT,
textColor: textColor,
backgroundColor: backgroundColor,
fontSize: fontSize,
gravity: gravity,
);
}
}
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
fluttertoast:
dependency: "direct main"
description:
name: fluttertoast
url: "https://pub.dartlang.org"
source: hosted
version: "8.0.9"
freezed:
dependency: "direct dev"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
git:
url: https://github.com/nstack-io/flutter-sdk.git
ref: v0.5.1
fluttertoast: 8.0.9

# Net
dio: ^4.0.6
Expand Down