Giter VIP home page Giter VIP logo

custom_timer's People

Contributors

apgapg avatar federicodesia 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

Watchers

 avatar  avatar  avatar

custom_timer's Issues

Counter is going down instead of up

on version 0.0.3 this worked fine but since I upgraded to 0.0.5 the counter goes down to negative values

CustomTimer(
      controller: _controller,
      from: Duration(seconds: 0),
      to: Duration(hours: 10),
      interval: Duration(milliseconds: 500),
      onBuildAction: CustomTimerAction.auto_start,
      builder: (CustomTimerRemainingTime remaining) {
        return Text(
          '${remaining.minutes}:${remaining.seconds}',
          style: _tema.title2().copyWith(color: _tema.backgroundTertiary()),
        );
      },
    )

milliseconds not working

CustomTimer( from: Duration(milliseconds: 0), to: Duration(hours: 1), onBuildAction: CustomTimerAction.auto_start, builder: (CustomTimerRemainingTime remaining) { return Text( "${remaining.minutes}:${remaining.seconds}:${remaining.milliseconds} ", style: TextStyle(fontSize: 20.0), ); }, ),

2021-08-11.01.16.57.mov

Issue: Classic flutter issue of insane & needless rebuilds eating resources - Propose: Less rebuilds for situations where NOT using milliseconds value of CustomTimerRemainingTime

Love this package, nice and simple & thank you for producing it. Now, I think something important could be improved.

I'm no Flutter pro engineer, mega computer genius, crazy Stephen Hawking intellectual, but rebuilding a widget a million times per second has always since I started learning Flutter been a serious main issue, concern & my arch nemesis and looks like Flutter's also. However it is also necessary IF one is showing milliseconds as part of their timer. I can understand this aspect of the programming. This uses enormous system resources in debug mode.

So my proposal is to include some sort of boolean value updateForMilliseconds or something which uses state and does not rebuild so much when not necessary when not using milliseconds value from timer. If using milliseconds then use the good old stateful widget and rebuild it quickly so user can see milliseconds passing.

I suppose all timers would have this issue and this is why I think this could be very valuable when some don't need rapid updates.

Showing my performance issue

class OTPTimer extends StatelessWidget {
  final CustomTimerController timeController;

  const OTPTimer({
    required this.timeController,
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CustomTimer(
        controller: timeController,
        begin: const Duration(minutes: 10),
        end: const Duration(minutes: 0),
        builder: (timeRemaining) {
          return Text(
            "${timeRemaining.hours}:${timeRemaining.minutes}:${timeRemaining.seconds}",
            style: timerStyle(timeRemaining),
          );
        });
  }

  // // Timer time text
  TextStyle timerStyle(CustomTimerRemainingTime timeRemaining) {
    print(int.parse(timeRemaining.secondsWithoutFill));                          // Prints 40-60 times per second (useless in my case)
    // Green indicator text
    if (int.parse(timeRemaining.minutesWithoutFill) > 3) {
      return ThemeEndpoints.infoHeaderPositive();
    }
    // Yellow indicator warning text
    if (int.parse(timeRemaining.minutesWithoutFill) < 3 &&
        int.parse(timeRemaining.minutesWithoutFill) > 1) {
      return ThemeEndpoints.infoHeaderWarning();
    }
    // Red indicator warning text
    return ThemeEndpoints.infoHeaderNegative();
  }

If set interval: CustomTimerInterval.seconds when there will be a bug

If set the interval: CustomTimerInterval.seconds, can normal execution code for the first time. However, when you reset begin for the second countdown, it will end directly.
CustomTimerController( vsync: this, begin: Duration(seconds: state.duration.value), end: const Duration(), initialState: CustomTimerState.reset, interval: CustomTimerInterval.seconds)

interval: CustomTimerInterval.milliseconds is ok;
interval: CustomTimerInterval.seconds is failed;

CustomTimerController end default value

end default value can be Duration.zero
Currently it does not have a default value and needs to get specify

CustomTimerController(
        vsync: this,
        begin: Duration(hours: 24),
        end: Duration.zero,
    );

Controller is dispose after state is finished

I am trying to set up a countdown timer but it keeps throwing an error. Controller is already disposed here's my code

CustomTimer(
    controller: controller,
    begin: Duration(seconds: 30),
    end: Duration(seconds: 0),
    onChangeState: (s) {
      if(s == CustomTimerState.finished) {
        print("We completed finished");
        // Prevent calling setState during a widget build
        showTimer.value = false;
        controller.reset();
      }
    },
    builder: (remaining) {
      return Text("${remaining.minutes}:${remaining.seconds}", style: TextStyle(
        fontFamily: "Montserrat",
        fontWeight: FontWeight.w600,
        color: primaryColor,
        fontSize: 14,
      ));
    },
  ),

usage:

how to do something like in a soccer match where you go from 00:00 to 10:95 to 45.00 and so and so ! is this possible?

The timer goes bellow 0

I was expecting the behaviour of onFinish to be triggered when it gets to Duration(seconds: 0) yet it didn't and it continued to negative values, is this a bug? thanks!

 Widget _timer() {
    return CustomTimer(
      controller: _timerController,
      from: widget.durationLeft,
      to: Duration(seconds: 0),
      interval: Duration(seconds: 1),
      onFinish: () => widget.onFinish(),
      onBuildAction: CustomTimerAction.auto_start,
      builder: (CustomTimerRemainingTime remaining) {
        return Text('${remaining.hours}:${remaining.minutes}:${remaining.seconds}');
      },
    );
  }

When I use microseconds, onFinished isn't triggered

I need a custom duration: eventDate.difference(DateTime.now()) for the from
Yet the onFinished wasn't being triggered so I tried to add microseconds to the from property and indeed it doesn't trigger it and continue to countdown below 0

	from: Duration(seconds: 10, microseconds: 11111),
CustomTimer(
  from: Duration(seconds: 10, microseconds: 11111),
  to: Duration(hours: 0),
  onBuildAction: CustomTimerAction.auto_start,
  onFinish: () => _refreshData(),
  builder: (CustomTimerRemainingTime remaining) {
    return Text(
      '${remaining.hours}:${remaining.minutes}:${remaining.seconds}')
    );
  },
)

A workaround that works is convert to seconds and convert to Duration

from: Duration(seconds: Duration(seconds: 10, microseconds: 11111).inSeconds),

Timer between multiple screens

I want to use the same time accessed between multiple screens, The timer is resetting in every screen currently, even when I use the same controller.

And when I come back to the previous screen, two instances of the timer running.

I want one instance of the timer used across multiple screens, do we have an option for that?

Request: Being able to access current state of timer

It would be nice to be have the controller be able to keep track of the timer regardless of whether or not the timer is in view or not.

I envision the controller being the source of truth for the timer widget and the widget simply latches on to the current state of the controller it was initialized with whenever it comes into view. This way we can get and set the timer from just the controller in other parts of an app.

The initial discussions for this issue can be found here.

Timer doesn't auto start

Hi, previously I used "onBuildAction: CustomTimerAction.auto_start", but now it's gone, and the timer doesn't auto start. How to auto start on build without using the external controller?

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.