【发布时间】:2022-02-15 21:10:15
【问题描述】:
我试图在按下 2-3 秒后更改按钮的文本。所以,如果我按下“SAVE GOALS”按钮,我想将其文本更改为“SAVED”2 秒钟,然后返回“SAVE GOALS”。我知道如何更改为“已保存”,但我不知道如何更改回“已保存目标”。延迟,睡眠等,没有任何效果。我在一个有状态的小部件中。
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,
)
),
),
【问题讨论】: