You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
752 B
33 lines
752 B
import 'package:flutter/material.dart';
|
|
|
|
/**
|
|
* 防止快速点击
|
|
*/
|
|
class FastClickWidget extends StatelessWidget {
|
|
final int between_time = 500; //默认两次点击间隔500ms内则点击无效
|
|
|
|
Function onTap;
|
|
Widget child;
|
|
|
|
FastClickWidget({@required this.onTap, @required this.child});
|
|
|
|
int lastClickTime = 0;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: () {
|
|
if (lastClickTime == 0 ||
|
|
DateTime.now().millisecondsSinceEpoch - lastClickTime >
|
|
between_time) {
|
|
onTap();
|
|
lastClickTime = DateTime.now().millisecondsSinceEpoch;
|
|
} else {
|
|
//间隔500ms内点击无效
|
|
}
|
|
},
|
|
child: child,
|
|
);
|
|
}
|
|
}
|