For full control over UI and queuing, use the FToast class. This works on all platforms but requires setup in your MaterialApp and initialization with a BuildContext.
1. Setup MaterialApp
Update your MaterialApp to include the FToastBuilder in the builder property:
MaterialApp(
builder: FToastBuilder(),
home: MyApp(),
navigatorKey: navigatorKey,
),
2. Initialize FToast
Initialize FToast in your widget's initState:
FToast fToast;
@override
void initState() {
super.initState();
fToast = FToast();
fToast.init(context);
}
3. Show a Custom Toast
Pass any widget to fToast.showToast() to display it as a toast.
_showToast() {
Widget toast = Container(
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25.0),
color: Colors.greenAccent,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.check),
SizedBox(
width: 12.0,
),
Text("This is a Custom Toast"),
],
),
);
fToast.showToast(
child: toast,
gravity: ToastGravity.BOTTOM,
toastDuration: Duration(seconds: 2),
);
}