'onDoubleTap decreases performance in GestureDetector without generate event
Expected results:
I don't expect a difference in performance if I don't double tap.
Actual results:
I added the double tap event and noticed that by simply adding it, the performance of the application is greatly diminished. If, on the other hand, I comment the line, then the performance returns stable.
If I had created any performance problems I would expect them if I double tap. But just add the event line that the performances drop drastically.
Code
void _startOperation(BuildContext ctx) {
_timer = Timer(const Duration(milliseconds: 150), () {
isLongPressed = true;
if (!widget.cell.isShowed) {
Provider.of<GameModelProvider>(ctx, listen: false).setFlag(widget.cell);
HapticFeedback.mediumImpact();
}
});
}
Widget build(BuildContext context) {
return GestureDetector(
onDoubleTap: () => Provider.of<GameModelProvider>(context, listen: false)
.speedOpenCell(widget.cell),
onTapDown: (_) {
_startOperation(context);
},
onTapUp: (_) {
if (!isLongPressed) {
Provider.of<GameModelProvider>(context, listen: false)
.computeCell(widget.cell);
} else {
isLongPressed = false;
}
_timer.cancel();
},
child: Container(
width: widget.cellWidth,
height: widget.cellHeight,
decoration: BoxDecoration(
color: widget.cell.isShowed
? Colors.grey.shade300
: Colors.grey.shade400,
borderRadius: BorderRadius.circular(5.0),
),
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Center(
child: getContent(),
),
),
),
);
}
You get all code here : https://github.com/EliaTolin/infinity_sweeper
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
