this is my code
GestureDetector(onLongPress: () async {
await _cameraController.startVideoRecording();
setState(() {
startTimer();
isRecoring = true;
});
},
onLongPressUp: () async {
final videoPath = await _cameraController.stopVideoRecording();
setState(() {
isRecoring = false;
});
print("Going to next screen");
Navigator.push(
context,
MaterialPageRoute(
builder: (builder) => VideoViewPage(
path: videoPath.path,
isWelcome: widget.isWelcome,
))
);
},
child: isRecoring
? Icon(
Icons.brightness_1_rounded,
color: Colors.red,
size: 120,
)
: Icon(
Icons.panorama_fish_eye,
color: Colors.white,
size: 70,
),
),
all I want is that If my timer function which is initialize after onLongPress() is == 60 then onLongPressUp() method call.Please help me to solve this problem. Thanks in advance.
CodePudding user response:
Perhaps with the following code in your GestureDetector:
onLongPressDown: () {timeLongPressStart = DateTime.fromMillisecondsSinceEpoch(DateTime.now())}
onLongPressUp: () {
timeLongPressEnd = DateTime.fromMillisecondsSinceEpoch(DateTime.now())
if (timeLongPressEnd - timeLongPressStart < 60000)
{
Do your logic
}
}
CodePudding user response:
Please check the following codes
import 'dart:async';
onLongPress(){ Timer(Duration(seconds: 30), () { // your logic here // });}
Another way is:
onPressed: (){Future.delayed(Duration(seconds: 5), () { // your code here //});},
