Coder Social home page Coder Social logo

wuweijian1997 / fluttercountdowntimer Goto Github PK

View Code? Open in Web Editor NEW
94.0 94.0 46.0 1.26 MB

A flutter countdown timer. [10 days 5:30:46] ⬇⬇⬇⬇ | flutter倒计时

License: BSD 3-Clause "New" or "Revised" License

Dart 96.99% Kotlin 0.66% Swift 2.15% Objective-C 0.20%

fluttercountdowntimer's Introduction

fluttercountdowntimer's People

Contributors

ahsinmehmood avatar jakobkordez avatar kjawaddeveloper avatar nvshah avatar wuweijian1997 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fluttercountdowntimer's Issues

onEnd() callback is called twice

Bug Description

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.

When SliverAppbar re-renders after a scroll, Current remaining time returns null

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**         

Undefined class 'CurrentRemainingTime'.

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 😂

Restart Countdown

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

Custom styling widgetBuilder error on types

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

Restart Timer

Hi thanks for the plugin! is it possible to restart the time or countdown to original endTime?

OnEnd called when you reset timer

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

Testing

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.

Navigate away after 0 seconds remaining ( don't want to see the 0 secs remaining)

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),
      );
    },
  ),
),

[Request] Consider some basic styling parameters

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.

null problem

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?

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}

Stop before the end

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

isRunning is always false

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;

没用了

放进去都没有东西显示出来了】

utc time?

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,

Countdown in web project does not work

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

Time format?

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?

Pause Timer

Hi thanks for the plugin, is it possible to pause and resume the time or countdown?

Counter doesn't keep in mind nano seconds

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.

Counting Issue

While counting down the remaining time, the numbers '24' on hours and '60' on minutes which should be both '00' are provided null.

Time in specific timezone

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

how to cancel timer on page change?

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

animating milliseconds

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

Display format when show 1 digit

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 called before timer ends.

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,});
 }

Stopping timer after Navigate

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),
                            );
                          }
                        },

How to pause with CountdownTimerController?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.