背景:
之前没有详细的用到这一块,最近自己做了一个竞速类的工具,主打一个快速输入之后快速提交。
结果,老是提交之后,不能快速的拿到输入栏的结果,明明已经输入了,却显示null。
一开始以为是放在setState方法中,有延迟,于是拿了出来,不在setState方法中改变初始值。
后面发现还是不行,输入快,点击快的情况下,还是会把输入的内容漏掉。
这时的我不得不分析我是否用错了控件。
原来代码如下:
class CustomButton extends StatelessWidget {
final String label;
final VoidCallback onTap;
final VoidCallback? onLongPress; // 添加这个字段
static const TextStyle top_two_style = TextStyle(
fontSize: 18, color: Color(0xff353e4d), fontWeight: FontWeight.w500);
const CustomButton({Key? key, required this.label, required this.onTap,this.onLongPress}) : super(key: key);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(1),
child: Material(
color: AppColors.APPKeyLightColor,
shape: const RoundedRectangleBo