我可以在不等待 toast 结束的情况下立即更改 Toast 文本吗?
Can I make Toast text change immediately without waiting the toast end?
在我的应用程序中,我为 activity 构建了一个 pdf 查看器小部件,当我将它滚动到上一页或下一页时,我让它敬酒并显示当前页码。
问题是,吐司需要时间显示,当我滚动足够快时,例如我滚动到页面“5”和“06”并滚动到“07”没有停顿,我必须等待“05”、“06”、“07”的吐司慢慢一一展现。
我可以立即显示特定的 Toast 而无需等待吗?
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();
},
您可以清除之前的 toast 并显示当前的 toast
// 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,
);
}
更多关于fluttertoast
在我的应用程序中,我为 activity 构建了一个 pdf 查看器小部件,当我将它滚动到上一页或下一页时,我让它敬酒并显示当前页码。
问题是,吐司需要时间显示,当我滚动足够快时,例如我滚动到页面“5”和“06”并滚动到“07”没有停顿,我必须等待“05”、“06”、“07”的吐司慢慢一一展现。
我可以立即显示特定的 Toast 而无需等待吗?
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();
},
您可以清除之前的 toast 并显示当前的 toast
// 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,
);
}
更多关于fluttertoast