fl_toast 1.0.0 fl_toast: ^1.0.0 copied to clipboard
Easy Toast library for flutter
flutter_toast
Flutter Toast Library for Flutter
Features #
✔️ Easy-to-use - Made for new and advanced developers ✔️ Animations ✔️ Made Fully in flutter - No need to use platform channels
Usage #
context
in all show toast methods are required and can't be null
, otherwise an AssertionError
is thrown.
Basic usage #
import 'package:flutter_toast/flutter_toast.dart';
/// Shows a plaftform-styled toast with a text.
await showTextToast(
text: 'My Awesome Toast',
context: context,
);
Show the platform-styled toast #
await showPlatformToast(
child: Text('My Platform Toast'),
context: context,
);
/// Android-Styled Toast
///
/// Shows an Android Toast
await showAndroidToast(
child: 'My awesome Android Toast'
context: context,
);
Multi-toasts #
/// Show toasts at the same time
await showMultiToast(
toasts: [
Toast(child: Text('Toast 1')),
Toast(child: Text('Toast 2')),
],
context: context,
);
/// Shows one toast after another
await showSequencialToasts(
toasts: [
Toast(child: Text('First toast'), duration: Duration(seconds: 2)),
Toast(child: Text('Second toast'), duration: Duration(seconds: 1)),
],
context: context,
);
Animations #
You can customize the animation by setting animationBuilder
. The default animation is a FadeTransition
. The following snippet animate the widget with a scale transition.
await showStyledToast(
child: Text('Styled toast with custom animation'),
context: context,
animationBuilder: (context, animation, child) {
return ScaleTransition(
scale: animation,
child: child,
);
}
);
Cookbook #
Learn how to create beautiful toasts.
Snackbar #
showToast(
interactive: true,
padding: EdgeInsets.zero,
alignment: Alignment(0, 1),
duration: Duration(seconds: 4),
animationDuration: Duration(milliseconds: 200),
animationBuilder: (context, animation, child) {
return SlideTransition(
child: child,
position: Tween<Offset>(
begin: Offset(0, 1),
end: Offset(0, 0),
).animate(animation),
);
},
child: Dismissible(
key: ValueKey<String>(text),
direction: DismissDirection.down,
child: Material(
elevation: 8,
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 14),
color: Theme.of(context).scaffoldBackgroundColor,
child: content,
),
),
),
context: context,
);
Contribution #
Feel free to open an issue if you find an error or make pull requests.
TODO: #
- Add screenshots to the readme
- Increment the cookbook