dizoftteam / simple_count_down Goto Github PK
View Code? Open in Web Editor NEWSimple countdown (timer) for Flutter
Home Page: https://pub.dev/packages/timer_count_down
License: MIT License
Simple countdown (timer) for Flutter
Home Page: https://pub.dev/packages/timer_count_down
License: MIT License
I'm missing a method to change the seconds value when called either as a function call or from setState(){}.
This would enable me to have an increment/decrement button to change the interval of the countdown timer.
Best regards
Ulrich Bjerre
Does the timer keep working even when the screen is locked or turned off?
Hi I start the timer fine but then I want to restart the count down when the timer is done at onFinished
with countdownController.restart()
but it is not working, here is the widget.
@override
Widget build(BuildContext context) {
return Countdown(
controller: countdownController,
seconds: seconds,
interval: const Duration(milliseconds: 500),
build: (BuildContext context, double time) {
countdownController.start();
print(time);
return child;
},
onFinished: () {
print('timer done');
countdownController.restart();
if (mqttState == MqttAppConnectionState.connected) {
print('TIMER::: Timer done retrying sending 1..');
}
},
);
}
It prints the countdown at print(time):
just fine the first time but the restart does not happen
I am doing something wrong? thanks!
InkWell(
onTap: state
? () {
onPressInkFunction(
type,
context,
listLabelByPincodeType['phoneNumber'] ?? '',
);
_countdownController.restart();
context.read().add(
const PincodeEvent.pressedResendOTP(
isTapable: false,
),
);
}
: null,
child: AutoSizeText.rich(
TextSpan(
text: listLabelByPincodeType['footerLabel'] ?? '',
style: Theme.of(context)
.textTheme
.titleMedium
?.copyWith(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.secondary,
),
),
maxLines: 1,
textAlign: TextAlign.left,
),
);
I have an inkwell with onTap() function but when I tapped the restart function was executed only once. The next time I tap nothing happends.
There should be a preview in the documentation to showcase the package.
when the counter reaches zero it keeps counting one more second before calling the "onFinished" method.
The Problem here is, When we update seconds (duration for which the timer will run) for timer, it doesn't reflect any change to Timer build method, because you assigned _currentMicroSeconds in init method.
To resolve this we can add the below code and this will work in a effecient way -
@override void didUpdateWidget(Countdown oldWidget) { super.didUpdateWidget(oldWidget); if (oldWidget.seconds != widget.seconds) _currentMicroSeconds = widget.seconds * _secondsFactor; }
Also Created a PR, if you find it correct merge it..
Happy Coding..
In this case, the counter is frozen because it does not resume its execution, even when the controler executes the resume method. As a result, the onFinished event is never executed.
Following the logic of the flow of actions. We can say that in this scenario, the user stopped the counter before it was finished. And if it is reactivated through the Resume method, we must only run the event onFinished method, and this must be done only once.
Any expectations to migrate to nullsafety?
It will be great if we can have way to choose which format we want for example I want timer to be always shown in 00:00 format example 10:00, 09:00, 00:09.
this starts automatically. instead of starting timer by on, there should be a start() method.
I actually have a second request.
It would be nice to have an onProgress or onUpdate callback too. This would enable me to refresh/update other UI elements at every update rate (e.g. once every 100ms)
Best regards
Ulrich Bjerre
Create multiple timers at the same time, display exception
The previous timer will reset the time, and the next one will inherit the remaining time of the previous one
Widget _timerCountDown() {
return Countdown(
// controller: timerController,
seconds: 120,
build: (BuildContext context, double time) {
if (time < 5.0) {
return Text("ღ( ´・ᴗ・` )",style: TextStyle(color: Colors.white),);
}else{
return Text(time.toString(),style: TextStyle(color: Colors.white),);
}
},
interval: Duration(milliseconds: 100),
onFinished: () {
print('Timer is done!');
},
);
}
Count Down is freezed on 2.1.0+1
if (_currentMicroSeconds != 0) {
_timer = Timer.periodic(
widget.interval,
(Timer timer) {
if (_currentMicroSeconds == 0) {
timer.cancel();
The ==
on the second last line (Line 127) needs to be changed to <=
, otherwise I see the _currentMicroSeconds
going negative making the countdown endless.
Hi,
Simple_count_down is a great tool. i would like to know how to cancel the timer in on pressed(and it should not execute on finished code)?
hi DizoftTeam,
Congratulations first! Simple widget, self explaining and works great!
Is it possible to access current times outside of widget?
The example only shows how to access the time inside the widget:
build: (BuildContext context, double time) => Text(time.toString()),
I would have expected this to be via _controller, unfortunately I don't see a property time!?
Thanks
pc-Justin
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.