up_timer 0.0.1
up_timer: ^0.0.1 copied to clipboard
Forward Timer Package
up_timer #
A simple yet powerful Flutter package to create a forward (up) timer with full control over its behavior. Easily start, stop, reset, or set the timer manually. Customize the timer display with your own text styles.
✨ Features #
- ⏱️ Start, stop, and reset the timer
- ⌚ Set default/initial time
- 🎨 Customizable text style for timer display
- 🔁 Real-time updates using
AnimatedBuilder - 🧩 Easy to integrate and use with any Flutter app
🛠️ Getting Started #
Add this to your pubspec.yaml:
dependencies:
up_timer: ^1.0.0
Then import it:
import 'package:up_timer/up_timer.dart';
🚀 Usage #
- Create a UpTimerController
final _controller = UpTimerController();
- Use UpTimerWidget to display the timer
UpTimerWidget(
controller: _controller,
textStyle: const TextStyle(fontSize: 24, color: Colors.blue),
),
- Control the timer
// Start timer from 0 or specified elapsed seconds
_controller.start(); // Start from 0
_controller.start(elapsedSeconds: 120); // Start from 2 minutes
// Stop the timer
_controller.stop();
// Reset the timer to 0
_controller.reset();
// Set timer manually (e.g., show 5 minutes without starting)
_controller.setInitialTime(300);
📦 Example #
import 'package:flutter/material.dart';
import 'package:up_timer/up_timer.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: TimerDemo(),
);
}
}
class TimerDemo extends StatefulWidget {
@override
State<TimerDemo> createState() => _TimerDemoState();
}
class _TimerDemoState extends State<TimerDemo> {
final _controller = UpTimerController();
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Up Timer Example")),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
UpTimerWidget(controller: _controller),
const SizedBox(height: 20),
Wrap(
spacing: 10,
children: [
ElevatedButton(onPressed: _controller.start, child: const Text("Start")),
ElevatedButton(onPressed: _controller.stop, child: const Text("Stop")),
ElevatedButton(onPressed: _controller.reset, child: const Text("Reset")),
],
)
],
),
),
);
}
}
📚 API Summary #
| Method | Description |
|---|---|
start({int? elapsedSeconds}) |
Starts the timer from 0 or given seconds |
stop() |
Stops the timer |
reset() |
Resets timer to 0 |
setInitialTime(int elapsedSeconds) |
Set default time without starting |
formattedTime |
Returns formatted time HH:mm:ss |
📌 Additional Info #
- Fully written in Dart & Flutter with no platform-specific code
- Works across Android, iOS, Web, and Desktop
- Lightweight and easy to use
💡 Contributions #
Feel free to open issues or contribute by submitting PRs.