https://github.com/bixat/rocket_timer
The rocket_timer package supports starting, pausing, stopping, resetting, and switching between countdown and normal modes
https://github.com/bixat/rocket_timer
dart flutter flutter-package timer
Last synced: 1 day ago
JSON representation
The rocket_timer package supports starting, pausing, stopping, resetting, and switching between countdown and normal modes
- Host: GitHub
- URL: https://github.com/bixat/rocket_timer
- Owner: bixat
- License: mit
- Created: 2023-06-20T14:54:04.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-10-01T12:15:31.000Z (about 2 years ago)
- Last Synced: 2025-03-31T17:56:07.139Z (6 months ago)
- Topics: dart, flutter, flutter-package, timer
- Language: Dart
- Homepage: https://pub.dev/packages/rocket_timer
- Size: 249 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Rocket Timer
The rocket_timer package provides a RocketTimer class for implementing countdown or normal timers in Flutter applications, as well as a RocketTimerBuilder widget for building widgets that respond to changes in a RocketTimer object. It supports starting, pausing, stopping, resetting, and switching between countdown and normal modes, and is easy to use and customize.
## Usage
To use the `RocketTimer` class, simply create a new instance of it and call its methods to control the timer:
```dart
import 'package:rocket_timer/rocket_timer.dart';final RocketTimer timer = RocketTimer(duration: 60, type: TimerType.countdown);
// Start the timer
timer.start();// Pause the timer
timer.pause();// Stop the timer
timer.stop();// Reset the timer
timer.reset();// Switch between countdown and normal modes
timer.switchMode();// Restart timer
timer.restart();```
To display the timer in a widget, you can use the `RocketTimerBuilder` widget which listens to changes in a `RocketTimer` object and rebuilds the widget tree accordingly:
```dart
import 'package:flutter/material.dart';
import 'package:rocket_timer/rocket_timer.dart';class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}class _MyHomePageState extends State {
final RocketTimer _rocketTimer = RocketTimer(duration: 60, type: TimerType.countdown);@override
void dispose() {
_rocketTimer.dispose();
super.dispose();
}@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: RocketTimerBuilder(
timer: _rocketTimer,
builder: (BuildContext context) {
return Text(
_rocketTimer.formattedDuration,
style: Theme.of(context).textTheme.headline1,
);
},
),
),
);
}
}
```## API Reference
See the full API reference for the `RocketTimer` class and the `RocketTimerBuilder` widget in the `rocket_timer` [package](https://pub.dev/packages/rocket_timer) documentation.