wuweijian1997 / fluttercountdowntimer Goto Github PK
View Code? Open in Web Editor NEWA flutter countdown timer. [10 days 5:30:46] ⬇⬇⬇⬇ | flutter倒计时
License: BSD 3-Clause "New" or "Revised" License
A flutter countdown timer. [10 days 5:30:46] ⬇⬇⬇⬇ | flutter倒计时
License: BSD 3-Clause "New" or "Revised" License
onEnd()
callback is called twice when provided endTime
is already surpassed (i.e endTime < currentTime)
i.e
...
int endTime = (DateTime.now().millisecondsSinceEpoch / 1000).round() - 60;
void onEnd() {
print('onEnd');
}
...
CountdownTimer(
endTime: endTime,
onEnd: onEnd,
)
...
➤ For aforementioned snippet 'onEnd' will be printed 2 times.
SliverAppBar( expandedHeight: MediaQuery.of(context).size.height / 3.5, pinned: true, snap: false, floating: true, forceElevated: innerBoxIsScrolled, automaticallyImplyLeading: false, flexibleSpace: LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { return FlexibleSpaceBar( collapseMode: CollapseMode.parallax, background: Container( decoration: BoxDecoration(color: AppColors.blue[500]), child: Observer( builder: (BuildContext context) { return _matchStore.gameListLoading ? CustomProgressIndicatorWidget() : buildHeaderListView(); }, ), ), ); }, ), )
The Above buildHeaderview is re-rendered while the body is scrolled
getMatchDetail(int index) { UserMatches userMatch = _matchStore.matchesResponse.userMatches[index]; DateFormat dateFormat = DateFormat("yyyy-MM-dd H:m:s"); DateFormat gameDateFormat = new DateFormat.yMd().add_jm(); DateTime dateTime = dateFormat.parse(userMatch.matchTime); String gameDate = gameDateFormat.format(dateTime); int endTime = dateTime.millisecondsSinceEpoch; countdownTimerController = CountdownTimerController(endTime: endTime, onEnd: onEnd); TimeClass timeClass = TimeClass(); switch (userMatch.matchStatus) { case 0: { //UpComing return Stack( children: [ Container( alignment: Alignment.bottomLeft, margin: EdgeInsets.only(bottom: 20, left: 10), child: Text( "Upcoming", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15), ), ), Container( alignment: Alignment.bottomLeft, margin: EdgeInsets.only(left: 10), child: CountdownTimer( controller: countdownTimerController, widgetBuilder: (_, CurrentRemainingTime time) { if (time == null) { //todo notify timer stopped for reactions return Text("Contest is online"); } else { return Text( time.days != null ? timeClass.getTimeWithDays(time) : time.hours != null ? timeClass.getTimeWithHours(time) : time.min != null ? timeClass.getTimeWithMinutes(time) : time.sec != null ? timeClass.getTimeWithSeconds(time) : "Match Started", style: TextStyle(fontSize: 12), ); } }, ), ), ], ); });
**Current Remaining time always comes null after re rendering**
在列表上使用,滚动时item会被销毁,这种情况怎么弄,求指点
Undefined class 'CurrentRemainingTime'.
Try changing the name to the name of an existing class, or creating a class with the name 'CurrentRemainingTime'.
how to set the class?
sorry for dumb question 😂
Hello,
I'am using your Countdown class and would like to know how to restart it to a new value when it ends. In my app, i must chain 10 countdowns (each with it own duration).
I saw the otther post to restart the CountDownTimer (by redefining endTime) but i'm using the other class (because i need to be able to pause the countdown).
Is this scenario possible with your library ?
Thanks for your time
Compiler is throwing error:
The argument type 'Container Function(BuildContext, CurrentRemainingTime)' can't be assigned to the parameter type 'Widget Function(BuildContext, CurrentRemainingTime?)?'
I'm using this code (which is mostly from the ReadMe
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: CountdownTimer(
controller: controller,
endTime: endTime,
widgetBuilder: (BuildContext context, CurrentRemainingTime time) {
if (time == null) {
return Container(child: Text('Resend?'));
} else {
return Container(child: Text('[ ${time.min} ], [ ${time.sec} ]'));
}
},
),
),
);
}
FYI same thing happens if I remove the Container
and just leave the Text
Hi thanks for the plugin! is it possible to restart the time or countdown to original endTime?
Please add text alignment.. thanks
I have a countdown timer and when it ends I have it run some functions, updating data, etc... However I then need to reset timer, set the value and start the timer for the next round. However when I run reset it then runs the onend again and causes problems with data and order of actions for the future rounds. Is this by design or a bug or is there another way to get the time reset and start the timer again, I have tried several combinations and only when I reset will the time start over and countdown.
Any thoughts on if this is a bug or a way to handle it?
Thanks
I think it would be useful to include a method that returns the timer value. I want to check in my tests if my timer is reset and I am not sure how to do this with what the library is providing.
Great library by the way 😃
I am currently hiding the "0" with "Go" but I'd like to navigate away at 0 seconds. Is this currently possible?
Thanks
Container(
padding: EdgeInsets.only(top: 16.0),
margin: EdgeInsets.only(top: 20.0),
child: CountdownTimer(
endTime: endTime,
onEnd: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => GameContainer()),
);
},
textStyle: TextStyle(fontSize: 30, color: Colors.white),
// ignore: missing_return
widgetBuilder: (_, CurrentRemainingTime time) {
print(context);
return Text(
(time != null && time.sec != 0 ? time.sec : 'Go')
.toString(),
style: TextStyle(fontSize: 64, color: Colors.white),
);
},
),
),
I've to implement a custom builderCountdownTimer
just because I want to display a the countdown with a bigger text.
So please consider add some simple styling parameters as "fontSize".
Regards.
flutter_countdown_timer-1.6.0/lib/flutter_countdown_timer.dart:14:3: Context: Found this candidate, but the arguments don't match.
CountdownTimer({
Error occurs at the end of a countdown timer.
The following NoSuchMethodError was thrown building CountdownTimer(dirty, state: _CountDownState#e1b16):
The getter 'sec' was called on null.
Receiver: null
Tried calling: sec
final int endTime = DateTime.now().millisecondsSinceEpoch + 3000;
CountdownTimer(
endTime: endTime,
widgetBuilder: (_, CurrentRemainingTime time) {
if(time.sec != null) {
return Text('${time.sec}');
} else {
return Text('Complete!');
}
},
),
How to turn off logging to console?
I/flutter ( 2997): CurrentRemainingTime{days: null, hours: 1, min: 15, sec: 16}
I/flutter ( 2997): CurrentRemainingTime{days: null, hours: 1, min: 15, sec: 15}
I/flutter ( 2997): CurrentRemainingTime{days: null, hours: 1, min: 15, sec: 14}
I/flutter ( 2997): CurrentRemainingTime{days: null, hours: 1, min: 15, sec: 13}
I/flutter ( 2997): CurrentRemainingTime{days: null, hours: 1, min: 15, sec: 12}
I/flutter ( 2997): CurrentRemainingTime{days: null, hours: 1, min: 15, sec: 11}
I/flutter ( 2997): CurrentRemainingTime{days: null, hours: 1, min: 15, sec: 10}
I/flutter ( 2997): CurrentRemainingTime{days: null, hours: 1, min: 15, sec: 9}
when use , it show 00:05:00 , how can only 05:00 ?
Hello, how to localize "days" string in another languages.
Hello
thank for you widget ! very usefull
i have a question:
I add a countdown timer with an event at the endtime.
But sometimes, if the user do some actions, I want to stop before the end, my countdown timer.
How it is possible ?
For example, I would like stop the count before the end sometimes... actually, if I go to the page2 or other thing, onEnd method execute always at 0 the push..
CountdownTimer(
endTime: endTime,
onEnd: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => GoToPage2(),
));
}
)
thx
Because disposeTimer()
that sets _isRunning
to false
is called after setting _isRunning
to true
in start()
in CountdownTimerController:
start() {
_isRunning = true;
disposeTimer();
.
.
.
disposeTimer() {
_isRunning = false;
onEnd?.call(); is getting null and onEnd function is not getting call in ui.
放进去都没有东西显示出来了】
How to set timer according to UTC time.? As of now it only takes the timezone of the device.
I tried toUtc method but doesn't work
endTime: DateTime(year, month, day, 22, minute, second).toUtc().millisecondsSinceEpoch,
When you spam start and stop, the timer will be faster
Hello,
thank you for your helpful project. Is this package working for web projects?
I created the following dart file and try to see the countdown in the browser, however nothing shows up. Here is my code:
import 'package:flutter/material.dart';
import 'package:flutter_countdown_timer/countdown_timer.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Generated App',
theme: new ThemeData(
primarySwatch: Colors.blue,
primaryColor: const Color(0xFF2196f3),
accentColor: const Color(0xFF2196f3),
canvasColor: const Color(0xFFfafafa),
),
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('App Name'),
),
body: new CountdownTimer(
endTime: 1576682634231,
textStyle: TextStyle(fontSize: 30, color: Colors.orange),
),
);
}
}
I added Countdowntimer as dependency like this:
flutter_countdown_timer: ^1.1.0
Best,
wirthual
how can we restart the timer in between time counting? I mean is it possible to restart the timer.
This is just a suggestion to add the onchanged callback to do some action if the timer is changed by 1s
Nowhere in the documentation does it say the format of the time you must input for the endTime
parameter of the CountdownTimer
function. What exactly is it?
Can you add Reset for CountdownController. There is no normal way to reset value.
Hi thanks for the plugin, is it possible to pause and resume the time or countdown?
how to pause/resume counter?
Version 1.6.0 does not follow semantic versioning and breaks compatibility.
https://dart.dev/tools/pub/versioning#semantic-versions
This is because the signature of CountdownTimer changed from 1.5.0 to 1.6.0
According to semantic versioning 1.6.0 should have been 2.0.0
I was stuck for hours on my code eventually realising the problem was in the package it self.
When the countdown reaches to 0, this means 0 seconds but not nanoseconds.
It is little bug worth fixing.
This can be tested by using the Datetime.now() in the function on end.
While counting down the remaining time, the numbers '24' on hours and '60' on minutes which should be both '00' are provided null.
It would be awesome if this package could be migrated to null safety.
Hello I would like to propose a change to the library inside the file countdown_timer_controller.dart
int remainingTimeStamp =
(_endTime - DateTime.now().millisecondsSinceEpoch) ~/ 1000;
I am making a app that should countdown time before a key is available in specific timezone but the problem is that whatever I do DateTime.now() will always use the current timezone of the user.
This line should be changed with optional parameter of specific timezone to be passed so the time is timezone agnostic
it always gives me error saying set state was called from widget which was not visible in the widget tree..
How to fix this and dispose the timer properly on page change (route to another page)
without clicking any button
any plans to show milliseconds counting down? they move fast but would be nice to have it so it's like a super precise stopwatch.
thanks
HI, When i us the AnimationController the countdown dose not count down until the animation ends
New to flutter. As the title says. Trying to navigate to a new page when the timer completes.
"the current time has expired" occur when finished countdown timer . how to remove it?
When program is running in background. The timer not continue in correct way what should I do
Hi, before I ask something, I want to say thanks for your package. It helps me.
Currently, I want to show a countdown timer in format like [hours:minutes:seconds]. But unfortunately, when one of them remaining 1 digit, it shows 1 digit, like [1:1:10]. I wonder if I can change the countdown display to become like [01:01:10]. Or, is something I missing when I writing the codes?
Here is the sample code I write to achive my goal.
...
CountdownTimer(
endTime: DateTime.now().millisecondsSinceEpoch + 1000 * 30,
widgetBuilder: (_, timeRemain){
if (timeRemain == null) {
return Text("00:00:00");
} else {
return Text('${timeRemain.hours ?? 0}:${timeRemain.min ?? 00}:${timeRemain.sec}');
}
},
)
...
Thanks in advance
onEnd ({String `ownerId,String` postId,String photoUrl,String images,String name}) async {
await activityFeedRef
.doc(ownerId)
.collection("feedItems")
.doc(postId)
.set({
"type": "topBid",
"username": name,
"userId": ownerId,
"userProfileImg": photoUrl,
"postId": postId,
"mediaUrl": images,
"timestamp": timestamp,
"read": 'false',
});
bidsRef.doc(ownerId)
.collection("userBids")
.doc(postId)
.update({
"hasEnded":true,});
}
I have a 5 minute timer, if the person finishes before time is up they navigate to another page. I want the timer to be destroyed because when they fill it out again and go to the 5 minute timer the timer has the leftover time from the previous time they were on the page. Then it executes the OnEnd wrongly using the leftover time rather than the current time.
How to dispose of the current timer after navigating away from the screen. I want to have a new timer each time I come to the screen.
CountdownTimer(
endTime: endTime,
onEnd: () {
print("end");
if (widget.isSeer) {
seerFinish();
} else {
lockinAnswer();
// This is still executing even after navigating
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => RevealScreen(
colors[widget.color + selection - 1],
selection,
win,
widget.roomCode,
widget.myName),
fullscreenDialog: true),
);
}
},
Hello,
I've noticed that there are 2 controllers and from #14 you use CountdownController to pause. I can't see a method to pause using (what I'm speculating is the new one) CountdownTimerController.
I have spend a lot of hours trying to understand what your wrote there . please add a docs to this project so people can uderstand what you had written
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.