我是一个初学者,我正在努力学习Flutter。
ElevatedButton(
child: Text(
'Go to the new page'
),
onPressed: () {
Future<bool?> pushFuture = Navigator.of(context).push<bool>(
MaterialPageRoute(
builder: (context) {
return VideoScreen('Do you like the video?');
},
)
);
pushFuture.then((bool? answer) async {
print('answer is: ${answer}');
if(answer == true) {
print("He/She liked!!!");
return Future.value(true);
}else{
Navigator.of(context).push<bool>(
MaterialPageRoute(
builder: (context) {
return VideoScreen('I wish you would liked it... Do you like the video?');
},
)
);
}
}).then((value) {
if(value == true){
print('You liked it!!!');
}
});
我有一个视频屏幕和两个答案按钮,分别是“是”和“否”。我想在他们单击“否”时再次提问,如果他们第二次单击“是”,我想在控制台屏幕上打印“您喜欢它!!!”。但它不起作用。你能帮助我吗?
1条答案
按热度按时间3mpgtkmj1#
试试这个格式