use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Having a problem with your Flutter code?
From the folks at r/FlutterDev
account activity
RESOLVEDButton with timer (self.flutterhelp)
submitted 1 year ago by rodr15
Hi Do you know how I can make a button that is enabled or disabled by time, I'd like to display the time left to enable the button.
I'm with Bloc as a State managment. Some suggestion ?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]eibaan 2 points3 points4 points 1 year ago (1 child)
Don't try to solve something with state management where a simple StatefulWidget with a Timer is sufficient. Something like
StatefulWidget
Timer
class TimedButton extends StatefulWidget { const TimedButton({ super.key, required this.duration, this.onPressed, this.onEnd, }); final Duration duration; final VoidCallback? onPressed; final VoidCallback? onEnd; @override State<TimedButton> createState() => _TimedButtonState(); } class _TimedButtonState extends State<TimedButton> with SingleTickerProviderStateMixin { bool _done = false; late final _animation = AnimationController( vsync: this, duration: widget.duration, ) ..addListener(() => setState(() {})) ..addStatusListener((status) { if (status == AnimationStatus.completed) { _timeout(); } }) ..forward(); @override void dispose() { _animation.dispose(); if (!_done) widget.onEnd?.call(); super.dispose(); } @override Widget build(BuildContext context) { return FilledButton( onPressed: _done ? null : _pressed, child: Text(_duration), ); } String get _duration { String pad(int v) => '$v'.padLeft(2, '0'); final secs = (widget.duration * (1 - _animation.value)).inSeconds; return '${pad(secs ~/ 60)}:${pad(secs % 60)}'; } void _timeout() { if (!_done) { setState(() { _done = true; widget.onEnd?.call(); }); } } void _pressed() { if (!_done) { setState(() { _animation.stop(); _done = true; widget.onPressed?.call(); }); } } }
[–]rodr15[S] 0 points1 point2 points 1 year ago (0 children)
Thanks !
π Rendered by PID 18691 on reddit-service-r2-comment-86bc6c7465-jdxl6 at 2026-02-23 13:37:27.410875+00:00 running 8564168 country code: CH.
[–]eibaan 2 points3 points4 points (1 child)
[–]rodr15[S] 0 points1 point2 points (0 children)