Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

stop watch timer

stop watch timer

this is stop watch timer.
stop_watch_timer

example code

stop watch timer

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

example

installation

stop watch timer

add this to your package’s pubspec.yaml file:

dependencies:
  stop_watch_timer:

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

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.

set preset time

can be set preset time. this case is “00:01.23”.
when timer is idle state, can be set this.

// set millisecond.
_stopwatchtimer.setpresettime(msec: 1234);

// set hours. (ex. 1 hours)
_stopwatchtimer.setpresethourstime(1);

// set minute. (ex. 30 minute)
_stopwatchtimer.setpresetminutetime(30);

// set second. (ex. 120 second)
_stopwatchtimer.setpresetsecondtime(120);

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top