I have a timer/stopwatch in my app, and the default color of the text is white. I’ve managed to change the color of the text if you long-press on the screen. In other words, if the text is white and you long-press, it will turn green, and vice versa.
What I want now is to make it so that once the user stops long-tapping the screen, that the text reverts back to white. For example, say the user has white text. Once he long-presses on the screen, the text turns green, but as soon as he lifts his finger, the text should revert back to white. I’ve tried multiple things, such as wrapping my TextButton()
in a GestureDetector
so as to get access to the multiple onTap
options, but I cannot seem to get my desired outcome. I’m not very experienced with Flutter, so any help and explanation as to what I am doing wrong is greatly appreciated.
Code for the timer text:
child: GestureDetector(
// onTapDown: (details) => timercolor = Colors.white,
child: TextButton(
onLongPress: (){
setState(() {
timercolor = timercolor == Colors.white
? Colors.green.shade600
: Colors.white;
startStopWatch();
});
},
style: ButtonStyle(
overlayColor: MaterialStateProperty.all(Colors.transparent),
),
onPressed: startStopWatch,
child: Padding(
padding: const EdgeInsets.only(top: 210.0, bottom: 360),
child: Text(
stopWatchText,
style: TextStyle(fontSize: 50, color: timercolor),
),
),
),
),
3
Answers
If you wanna change the color of the text once the user long-presses the widget (Text) and revert the normal color on-tap release, look at the following:
here is compiled solutions buddy have fun with creativity !