In my app, I construct a pdf viewer widget for my activity, when I scroll it to previous or next page, I let it make a toast and show the current page number.
The question is, the toast need time to show, when I scroll it fast enough, for example, I scrolled to page "5" and "06" and scroll to "07" without pause, I have to wait the Toast of "05", "06","07" to show one by one slowly.
Can I show a specific Toast immediately without waiting?
class _PdfoneState extends State<Pdfone> {
int currentPage1 = 0;
SharedPreferences? preferences;
final toast = FToast();
@override
void initState() {
super.initState();
toast.init(context);
initializePreference().whenComplete(() {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Container(
child: PDF(
enableSwipe: true,
pageFling: b,
fitPolicy: FitPolicy.BOTH,
nightMode: a,
onPageChanged: (page, total) {
setState(() {
currentPage1 = page!;
this.preferences?.setInt("page1", currentPage1);
});
Widget buildToast() => Container(
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 14),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
color: Colors.white70,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Text(
"${page! 1} / $total",
style: TextStyle(fontSize: 16),
)
],
),
);
void showToast() => toast.showToast(
child: buildToast(),
positionedToastBuilder: (context, child) => Positioned(
child: child,
top: 32,
left: 22,
),
fadeDuration: 300,
);
showToast();
},
CodePudding user response:
You can clear previous toast and show current one
// To remove present shwoing toast
fToast.removeCustomToast()
// To clear the queue
fToast.removeQueuedCustomToasts();
void showToast(){
toast.removeCustomToast(); // based on your need
toast.removeQueuedCustomToasts();
toast.showToast(
child: buildToast(),
positionedToastBuilder: (context, child) => Positioned(
child: child,
top: 32,
left: 22,
),
fadeDuration: 300,
);
}
More about fluttertoast
