This is Stop Watch Timer for flutter plugin.🏃‍♂️

Overview

stop_watch_timer

Simple CountUp timer / CountDown timer. It easily create app of stopwatch.

https://pub.dev/packages/stop_watch_timer

countup_timer_demo countdown_timer_demo

Example code

See the example directory for a complete sample app using stop_watch_timer.

example

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  stop_watch_timer:

Features

This is StopWatchMode.

  • CountUp
  • CountDown

CountUp

This is default mode. If you' d like to set it explicitly, set StopWatchMode.countUp to mode.

final stopWatchTimer = StopWatchTimer(
  mode: StopWatchMode.countUp,
  onChange: (value) => print('onChange $value'),
  onChangeRawSecond: (value) => print('onChangeRawSecond $value'),
  onChangeRawMinute: (value) => print('onChangeRawMinute $value'),
);

example code

CountDown

Can be set StopWatchMode.countDown mode and preset millisecond.

final stopWatchTimer = StopWatchTimer(
  mode: StopWatchMode.countDown,
  presetMillisecond: StopWatchTimer.getMilliSecFromMinute(1), // millisecond => minute.
  onChange: (value) => print('onChange $value'),
  onChangeRawSecond: (value) => print('onChangeRawSecond $value'),
  onChangeRawMinute: (value) => print('onChangeRawMinute $value'),
);

example code

This is helper functions for presetTime.

/// Get millisecond from hour
final value = StopWatchTimer.getMilliSecFromHour(1); 

/// Get millisecond from minute
final value = StopWatchTimer.getMilliSecFromMinute(60);

/// Get millisecond from second
final value = StopWatchTimer.getMilliSecFromSecond(60 * 60);

Usage

import 'package:stop_watch_timer/stop_watch_timer.dart';  // Import stop_watch_timer

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  final StopWatchTimer _stopWatchTimer = StopWatchTimer(); // Create instance.

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() async {
    super.dispose();
    await _stopWatchTimer.dispose();  // Need to call dispose function.
  }

  @override
  Widget build(BuildContext context) {
    ...
  }
}

To operation stop watch.

// Start
_stopWatchTimer.onExecute.add(StopWatchExecute.start);


// Stop
_stopWatchTimer.onExecute.add(StopWatchExecute.stop);


// Reset
_stopWatchTimer.onExecute.add(StopWatchExecute.reset);


// Lap time
_stopWatchTimer.onExecute.add(StopWatchExecute.lap);

Can be set preset time. This case is "00:01.23".

// Set Millisecond.
_stopWatchTimer.setPresetTime(mSec: 1234);

When timer is idle state, can be set this.

// Set Hours. (ex. 1 hours)
_stopWatchTimer.setPresetHoursTime(1);

// Set Minute. (ex. 30 minute)
_stopWatchTimer.setPresetMinuteTime(30);

// Set Second. (ex. 120 second)
_stopWatchTimer.setPresetSecondTime(120);

Using callback

final _stopWatchTimer = StopWatchTimer(
  onChange: (value) {
    final displayTime = StopWatchTimer.getDisplayTime(value);
    print('displayTime $displayTime');
  },
  onChangeRawSecond: (value) => print('onChangeRawSecond $value'),
  onChangeRawMinute: (value) => print('onChangeRawMinute $value'),
);

Using stream

Display time formatted stop watch. Using function of "rawTime" and "getDisplayTime".

_stopWatchTimer.rawTime.listen((value) => print('rawTime $value ${StopWatchTimer.getDisplayTime(value)}'));

Example code using stream builder.

StreamBuilder<int>(
  stream: _stopWatchTimer.rawTime,
  initialData: 0,
  builder: (context, snap) {
    final value = snap.data;
    final displayTime = StopWatchTimer.getDisplayTime(value);
    return Column(
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.all(8),
          child: Text(
            displayTime,
            style: TextStyle(
              fontSize: 40,
              fontFamily: 'Helvetica',
              fontWeight: FontWeight.bold
            ),
          ),
        ),
        Padding(
          padding: const EdgeInsets.all(8),
          child: Text(
            value.toString(),
            style: TextStyle(
                fontSize: 16,
                fontFamily: 'Helvetica',
                fontWeight: FontWeight.w400
            ),
          ),
        ),
      ],
    );
  },
),
),

Notify from "secondTime" every second.

_stopWatchTimer.secondTime.listen((value) => print('secondTime $value'));

Example code using stream builder.

StreamBuilder<int>(
  stream: _stopWatchTimer.secondTime,
  initialData: 0,
  builder: (context, snap) {
    final value = snap.data;
    print('Listen every second. $value');
    return Column(
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.all(8),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              const Padding(
                padding: EdgeInsets.symmetric(horizontal: 4),
                child: Text(
                  'second',
                  style: TextStyle(
                      fontSize: 17,
                      fontFamily: 'Helvetica',
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 4),
                child: Text(
                  value.toString(),
                  style: TextStyle(
                      fontSize: 30,
                      fontFamily: 'Helvetica',
                      fontWeight: FontWeight.bold
                  ),
                ),
              ),
            ],
          )
        ),
      ],
    );
  },
),

Notify from "minuteTime" every minute.

_stopWatchTimer.minuteTime.listen((value) => print('minuteTime $value'));

Example code using stream builder.

StreamBuilder<int>(
  stream: _stopWatchTimer.minuteTime,
  initialData: 0,
  builder: (context, snap) {
    final value = snap.data;
    print('Listen every minute. $value');
    return Column(
      children: <Widget>[
        Padding(
            padding: const EdgeInsets.all(8),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                const Padding(
                  padding: EdgeInsets.symmetric(horizontal: 4),
                  child: Text(
                    'minute',
                    style: TextStyle(
                      fontSize: 17,
                      fontFamily: 'Helvetica',
                    ),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 4),
                  child: Text(
                    value.toString(),
                    style: TextStyle(
                        fontSize: 30,
                        fontFamily: 'Helvetica',
                        fontWeight: FontWeight.bold
                    ),
                  ),
                ),
              ],
            )
        ),
      ],
    );
  },
),

Notify lap time.

_stopWatchTimer.records.listen((value) => print('records $value'));

Example code using stream builder.

StreamBuilder<List<StopWatchRecord>>(
  stream: _stopWatchTimer.records,
  initialData: const [],
  builder: (context, snap) {
    final value = snap.data;
    return ListView.builder(
      scrollDirection: Axis.vertical,
      itemBuilder: (BuildContext context, int index) {
        final data = value[index];
        return Column(
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(8),
              child: Text(
                '${index + 1} ${data.displayTime}',
                style: TextStyle(
                  fontSize: 17,
                  fontFamily: 'Helvetica',
                  fontWeight: FontWeight.bold
                ),
              ),
            ),
            const Divider(height: 1,)
          ],
        );
      },
      itemCount: value.length,
    );
  },
),

Parsing Time

Can be used getDisplayTime func. It display time like a real stopwatch timer.

  • Hours
  • Minute
  • Second
  • Millisecond

For example, 1 hours and 30 minute and 50 second and 20 millisecond => "01:30:50.20"

And can be set enable/disable display time and change split character.

Comments
  • Start timer from preset time

    Start timer from preset time

    Hi! Is there a way to start the timer from a given time. Instead of starting from 0 minutes 0 hrs, the timer should start from a given hour, minutes, and sec. For example, start from 2 hrs, 36 mins and 46 secs like this.

    opened by haaris94 5
  • How to preserve state properly?

    How to preserve state properly?

    Hi!

    I have been using your package for an app, and so far it works like a charm. I am unable though to maintain the state of the stopwatch when moving away from the page.

    Looking up strategies for maintaining state in Flutter I saw that there are multiple different strategies. I was wondering what the proper way would be to keep the last rawTime in the stopwatch and store it.

    Apart from that, I was wondering if it would be feasible to let the timer run in the background after dismissing it?

    Thanks in advance!

    question 
    opened by hld0 4
  • Dispose method needs to cancel timer

    Dispose method needs to cancel timer

    Hi,

    Thanks for the great plugin!

    Just noticed one small issue in the dispose method. If the timer is started and the widget is then disposed before the timer is stopped, Timer.periodic() will still try to add events to the now closed PublishSubjects. See the error below:

    I/flutter (21245): I/flutter (21245): #0 _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:249:24) I/flutter (21245): #1 Subject._add package:rxdart/…/subjects/subject.dart:141 I/flutter (21245): #2 Subject.add package:rxdart/…/subjects/subject.dart:135 I/flutter (21245): #3 StopWatchTimer._handle package:stop_watch_timer/stop_watch_timer.dart:185 I/flutter (21245): #4 _rootRunUnary (dart:async/zone.dart:1198:47) I/flutter (21245): #5 _CustomZone.runUnary (dart:async/zone.dart:1100:19) I/flutter (21245): #6 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7) I/flutter (21245): #7 _CustomZone.bindUnaryCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1042:26) I/flutter (21245): #8 _rootRunUnary (dart:async/zone.dart:1206:13) I/flutter (21245): #9 _CustomZone.runUnary (dart:async/zone.dart:1100:19) I/flutter (21245): #10 _CustomZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:1026:26) I/flutter (21245): #11 _Closure.call (dart:core-patch/function.dart) I/flutter (21245): #12 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19) I/flutter (21245): #13 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5) I/flutter (21245): #14 _Closure.call (dart:c I/flutter (21245): Error caught by Crashlytics plugin <recordError>: I/flutter (21245): Bad state: Cannot add new events after calling close

    I fixed it locally by calling _timer.close(); in the first line of the dispose() method.

    bug 
    opened by alfredjingle 4
  • Add support for parsing hours

    Add support for parsing hours

    Hey, I love your plugin!

    The only thing stopping me from actually using it is that it does not support hours... which I need for my project :(

    I am writing a time tracker destkop app that accumulates the time spent on different tasks on a monthly basis, so as you can imagine, the counter crosses the hour barrier very quickly...

    Do you think it's possible to add this functionality in the near future?

    Thanks!

    enhancement 
    opened by mdev88 4
  • HELP - How can you trigger an action when countdown reaches 0 ?

    HELP - How can you trigger an action when countdown reaches 0 ?

    I am a beginner developer with Flutter. Am using your package to display a countdown stopwatch. To manage state, I use the package Provider. Question 1 - Is it possible to manage the stream in my provider file and just "send" the "Displaytime" to the screen where the countdown must be displayed ? Question 2 - Is there a way to trigger an action when countdown reaches 0 ? In my app, when it reaches 0, it must change part in the test (it's a testing app for English learner). They have 3 minutes to answer 5 questions. (5 questions per part). So when they are out of time, it must change part... I just can't get it to work. I am not very good with Streams, so it's probably where I make a mistake. Can you help me ?

    opened by sylvainjack 1
  • Preset Time

    Preset Time

    Hello,

    Is there a way to force presettime countdown to 0 and set a new preset time ?.

    I've tried using clearPresetTime() function, but if i start the stopwatch countdown the stopwatch not start from the new preset time . example : remaining time is 5second and then i call clearPresetTime(), and then i set new preset time 20second and start the countdown again, but the timer started from 15second not 20second Screenshot_20220519_101150 Screenshot_20220519_101252

    Thank you in advance

    opened by naaera 1
  • Get Raw Second value in a variable

    Get Raw Second value in a variable

    Hi,

    Can you please explain, how I can assign the raw second value that is currently printed to an observable variable [I am using Getx for state management]?

    The reason that I am asking is that I want to ultimately use this to maintain a database at backend.

    Regards, Ameya

    opened by ameya730 1
  • I get the error 'Can be not set preset time because of timer is not reset. please reset timer.' even though I have reset timer

    I get the error 'Can be not set preset time because of timer is not reset. please reset timer.' even though I have reset timer

     void change_timer_value(int song_index) {
        int new_time = get_new_time();
        print(new_time);
    
        _stopWatchTimer.onExecute.add(StopWatchExecute.reset);
        _stopWatchTimer.setPresetSecondTime(new_time);
      }
    

    I'm trying to change the time of the _stopWatchTimer but when I try to do so it says I have to reset. Then when I try the same thing again it works. Only the first time it says I have to reset. Why does this happen? The problem is that the first reset doesn't update the _stopTime-variable so it can't change the time.

    enhancement 
    opened by PhilippRados 1
  • How Can I make background Timer ?

    How Can I make background Timer ?

    Hello Sir, I want to make, Background Timer If i start timer from a page , when i close The page ,it without disposing

    value will print in console log but if i go back to the page Stream Builder start from beginnings,

    But console log print old value as well,

    Now, how can i get the old value in stream builder?

    opened by tonmooy 1
  • Set timer to a specific time without having to reset it.

    Set timer to a specific time without having to reset it.

    Hello! Is there a way to set a timer to a specific time without having to reset it as required with the setPresetTime methods? Eg. when I try to do _stopWatchTimer.setPresetMinuteTime(45); I get "Can be not set preset time because of timer is not reset. please reset timer.".

    enhancement 
    opened by sebpeiris 1
  • Cannot stop stopWatch

    Cannot stop stopWatch

    I use the following commands to start and stop the stopwatch:

    _stopWatchTimer.onExecute.add(StopWatchExecute.start); _stopWatchTimer.onExecute.add(StopWatchExecute.stop); Unfortunately, the second command does not work, the stopwatch continues to run.

    opened by gruessung 1
Releases(2.0.0)
Owner
shohei
Never Inc. CEO & Engineer
shohei
A dart timer that can be configured to fire once or repeatedly with ability start, stop, resume and cancel.

A timer that can be configured to fire once or repeatedly with ability start, stop, resume and cancel. Getting started Add CompleteTimer to your pubsp

MohammadAminZamani.afshar 3 Jul 20, 2022
Flutter-watchtips - Flutter App (Embedded Watch Kit app with iOS version)

watchtips Update Version 2.2 The Watch tips project has been updated again, The interface has been tidied up and a seperate value for the tip cost has

Steve Rogers 137 Dec 31, 2022
A Flutter App To Watch Anime Online With No Ads

Tako Play A Mobile App to Watch Anime With No ADS !! . Please Do not put Tako-Pl

Kaung Satt Hein 133 Dec 22, 2022
Arispewdie - Flutter app to watch LIVE subscriber count of PewDiePie vs T-Series

PewDiePie VS T-Series Flutter app to watch LIVE subscriber count of PewDiePie vs

Behruz Hurramov 1 Jan 10, 2022
Flutter watch app ui design

Flutter-watch-app-ui-design A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get

Md.Hamid Hosen 0 Mar 18, 2022
a mobile app to search for information and watch movie, series and TV show trailers

inWatch Just a clean architecture app, to get trailers and informations of movies, series and TV shows, made with Getx, omdb API and Flutter sdk. The

Augusto da Silva 20 Nov 10, 2022
Bringing back contex.read and context.watch for riverpod

This package brings back the context extensions for riverpod that were discontinued in version 1.0.0. To read any provider, do context.read(myProvider

Kilian Schulte 2 Sep 28, 2022
watch it on YouTube

Furniture App - Flutter UI Watch it on YouTube Packages we are using: flutter_svg: link goole_fonts: link Fonts Poppins link We design two pages one i

Abu Anwar 570 Dec 9, 2022
PsTube - Watch and download videos without ads

PsTube - Formerly FluTube Watch and download videos without ads Features Beautiful user interface Lightweight and fast No Login Required Keep your lik

Prateek Sunal 249 Dec 21, 2022
Android l iOS mobile app that suggest random movies to watch 🍿

movirand A cross-platfrom mobile app that suggest random movies to watch Getting Started This project is a starting point for a Flutter application. A

Mhamed Ajjig 5 Jan 2, 2023
A simple timer for your workouts, built with Flutter!

Just Another Workout Timer A simple timer for your workouts, built with Flutter! NOTE: Due to the process of releasing updates on F-Droid, the version

Bastian Block 79 Nov 26, 2022
This is a Quiz App With Timer In Flutter

Quizstar ! This is a Complete Quiz App in FLUTTER using a lot of features such as Multiple Screens Timer (30 sec By Default) Button Color Changes On C

Prince 185 Dec 18, 2022
Chroneum - A Neumorphic Flutter timer and chronometer

Chroneum! A nice Flutter Neumorphic timer and chronometer. More Details The appl

Alessandro 2 Apr 4, 2022
Aplicativo de teste que roda em background timer atual utilizando Isolate.

# isolate_app A new Flutter project. ## Getting Started This project is a starting point for a Flutter application. A few resources to get you sta

Isaque Santos Paixão 1 Jun 20, 2022
Neha Tanwar 4 Feb 2, 2022
Debounce builder, debounce timer

Debounce builder, debounce timer Features debounce builder - Widget provides debounce function from DebounceTimer instance debounce timer

Pokhodyun Alexander 2 Dec 22, 2022
This is just the simplyfied Flutter Plugin use for one of the popular flutter plugin for social media login.

social_media_logins Flutter Plugin to login via Social Media Accounts. Available Social Media Logins: Facebook Google Apple Getting Started To use thi

Reymark Esponilla 3 Aug 24, 2022
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.

Flutter permission_handler plugin The Flutter permission_handler plugin is build following the federated plugin architecture. A detailed explanation o

Baseflow 1.7k Dec 31, 2022