在按下2-3秒后,我正在尝试更改按钮的文本。因此,如果我按下“保存目标”按钮,我想将其文本更改为“保存”2秒,然后返回到“保存目标”。我知道如何改变为“拯救”,但我不知道如何改变回拯救目标。延迟,睡觉等等,什么都没有用。我在一个有状态的小部件中。
OutlinedButton(
onPressed: () {
setState(() {
saveGoalsButtonText = "SAVED!";
Future.delayed(Duration(seconds: 3));
saveGoalsButtonText = "SAVE GOALS";
});
goals = _goalsController.text;
_saveGoals();
//Navigator.pushReplacementNamed(context, '/masterclasses');
} ,
style: OutlinedButton.styleFrom(
primary: const Color(0xffE4BDB6),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
),
side: const BorderSide(width: 3, color: Color(0xffE4BDB6)),
),
child: Text(
saveGoalsButtonText,
style: const TextStyle(
color: Color(0xff221F1E),
fontSize: 14,
fontWeight: FontWeight.w700,
)
),
),
发布于 2022-02-15 13:04:39
你可以这样做:
onPressed: () {
setState(() {
saveGoalsButtonText = "SAVED!";
});
Future.delayed(const Duration(seconds: 3), () {
setState(() {
saveGoalsButtonText = "SAVE GOALS";
});
});
} ,
结果:
https://stackoverflow.com/questions/71126605
复制相似问题