timer_stop_watch 1.0.0 copy "timer_stop_watch: ^1.0.0" to clipboard
timer_stop_watch: ^1.0.0 copied to clipboard

Flutter Dart Package Try a timer and a stopwatch that can be modified freely.

timer_stop_watch #

You can freely use a timer and a stopwatch.

1

Installation #

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

dependencies:
  timer_stop_watch:

Use #

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

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

class _MyAppState extends State<MyApp> {
  final _timerStopWatch = TimerStopWatch(); // Create timer_stop_watch instance.
  late Stream<String> _timer; // Create a timer variable.
  late Stream<String> _stopwatch; // Create a Stopwatch variable
  
  @override
  void initState() {
    super.initState();
    _timer = _timerStopWatch.setTimer(hour: 1, minute: 1, seconds: 10, timeFormat: "hh:mm:ss");  // Timer initialization
    _stopwatch = _timerStopWatch.setStopwatch(timeFormat: "hh:mm:ss");  // Stopwatch initialization
  }
  
  @override
  void dispose() {
    await _timerStopWatch.dispose();  // Need to call dispose function.
    super.dispose();
  }
  
  @override
  Widget build(BuildContext context) {
    ...
  StreamBuilder(  // StreamBuilder must be used.
    stream: _timer,
    builder: (context, snapshot) {
      if (snapshot.hasData) {
        return Text(snapshot.data.toString());
      } else if (snapshot.hasError) {
        print(snapshot.error);
        return SizedBox();
      } else {
        return CircularProgressIndicator();
      }
    }),
    ...
  }
}

And Timer And Stopwatch Start

 ElevatedButton(
   onPressed: (){_timerStopWatch.startTimer();},
   child: Text("start"),
 ),
 ElevatedButton(
   onPressed: (){_timerStopWatch.startStopwatch();},
   child: Text("start"),
 ),

or To start the timer&stopwatch immediately

  _timer = _timerStopWatch.setTimer(hour: 1, minute: 1, seconds: 10, timeFormat: "hh:mm:ss", start: true);
  _stopwatch = _timerStopWatch.setStopwatch(timeFormat: "hh:mm:ss", start: true);

Timer And Stopwatch Pause

  ElevatedButton(
    onPressed: (){_timerStopWatch.pauseTimer();},
    child: Text("pause"),
  ),
  ElevatedButton(
    onPressed: (){_timerStopWatch.pauseStopwatch();},
    child: Text("pause"),
  ),

Timer And Stopwatch Reset

  ElevatedButton(
    onPressed: (){_timerStopWatch.resetTimer();},
    child: Text("Reset"),
  ),
  ElevatedButton(
    onPressed: (){_timerStopWatch.resetStopwatch();},
    child: Text("Reset"),
  ),

2
likes
140
pub points
75%
popularity

Publisher

unverified uploader

Flutter Dart Package Try a timer and a stopwatch that can be modified freely.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on timer_stop_watch