lucky_toast 0.1.0 lucky_toast: ^0.1.0 copied to clipboard
A new flutter plugin project.
lucky_toast đ #
A customizable toast library using flutter. Advantage: easy to customize the animation
Language: English | ä¸æįŽäŊ #
Example #
Renderings #
Getting started #
1. add dependencies into you project pubspec.yaml file
dependencies:
lucky_toast: any
2. import lucky_toast lib
import 'package:lucky_toast/lucky_toast.dart';
3. initialization
Use LuckyToastCtxGet
to wrap this widget in the outermost layer (i.e. outside of the MaterialApp widget).
Note â ī¸: Animation effects can be defined in
LuckyToastCtxGet
, see Custom Animation.
runApp(LuckyToastCtxGet(child: MyApp()));
4. use
The popup will be called from anywhere.
Note â ī¸: The default popup duration is two seconds, which can be defined in
LuckyToastCtxGet
, the global popup duration. You can also pass this popup time when you callsimpleShow
. PrioritysimpleShow
Definition > Global.
LuckyToast.simpleShow('xxxx', duration: Duration(seconds: 5));
5. dismiss all
LuckyToast.dismiss;
CustomAnimation #
1. create animation
First inherit ToastAnimatedBase
, override the builder method and define the animation.
That is
super.builder(context)
, which is used to display what you need to pop up when you call it.
class CustomToastAnimation extends ToastAnimatedBase {
CustomToastAnimation({Duration duration}) : super(duration: duration);
@override
Widget builder(BuildContext context) => AnimatedBuilder(
animation: animation,
child: super.builder(context),
builder: (context, child) {
return Opacity(
opacity: animation.value,
child: Transform.scale(
scale: Tween<double>(begin: 1.5, end: 1.0)
.transform(animation.value),
child: child,
),
);
},
);
}
2. Import animation
There are two ways to import animations, you can define the global at the initialization or change it during the runtime.
- Initialize the import
Use the object you have defined to inherit the
ToastAnimatedBase
class, initialize it intoLuckyToastCtxGet
.
LuckyToastCtxGet(toastAnimated: CustomToastAnimation(), child: MyApp());
- Change at runtime
LuckyToast.setToastAnimated(CustomToastAnimation());