【发布时间】:2022-01-08 18:09:21
【问题描述】:
在我的应用程序中,我为我的活动构建了一个 pdf 查看器小部件,当我将其滚动到上一页或下一页时,我让它敬酒并显示当前页码。
问题是,toast 需要时间显示,当我滚动它的速度足够快时,例如,我滚动到页面“5”和“06”并滚动到“07”而没有暂停,我必须等待 Toast “05”、“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();
},
【问题讨论】:
-
在你的情况下
FToast是什么? -
我正在使用flutterToast包并构建一个自定义吐司你需要使用FToast类
标签: flutter dart flutter-layout toast