在飞镖中做一个按钮异步
我必须将这两个“点击”功能仅在一个按钮中。问题是,我只能在navigator.push
savequestionmodel() and loadQuestions()已经执行。
onTap: () {
saveQuestionModel(_key, snapshot.data);
loadQuestions(_key);
},
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => QuizScreen(
code: _key,
index: _currentIndex,
),
),
);
我尝试过这样的尝试,但不起作用,
onTap: () async {
saveQuestionModel(_key, snapshot.data);
loadQuestions(_key);
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => QuizScreen(
code: _key,
index: _currentIndex,
),
),
);
},
如果不使用两个分开的按钮,有办法这样做吗?
I have to put this two "on tap" functions in only one button. The thing is that I only can execute the Navigator.push
after saveQuestionModel()
and loadQuestions()
have been already executed.
onTap: () {
saveQuestionModel(_key, snapshot.data);
loadQuestions(_key);
},
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => QuizScreen(
code: _key,
index: _currentIndex,
),
),
);
I tried like this but did not work
onTap: () async {
saveQuestionModel(_key, snapshot.data);
loadQuestions(_key);
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => QuizScreen(
code: _key,
index: _currentIndex,
),
),
);
},
Is there a way of doing that without using two separated buttons?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个单独的方法,该方法将保存您的所有方法并在将来的方法之前使用
等待
。并在widget ontap 上使用此
myfun
,您可以为
dart async-wait
Create a separate method that will hold all your methods and use
await
before future methods.And use this
myFun
on widgetonTap
For your case, you can do
More about dart async-await
在您的情况下,它
基本上应该在这里等待两个函数结束执行,然后再使用
navigator.push()
来推动下一页。In your case, it should be
Here basically it waits for both the functions to end executing before pushing the next page using
Navigator.push()