Skip to main content

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

A Flutter timer that persists and calculates elapsed time when the app is in the background or terminated.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:background_timer_package/background_timer_package.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'demo',
      theme: ThemeData(colorScheme: .fromSeed(seedColor: Colors.deepPurple)),
      home: const MyHomePage(title: 'Flutter Background Timer'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _controller = TimerController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          children: [
            BackgroundTimer(seconds: 120, controller: _controller),
            Row(
              spacing: 10,
              children: [
                ElevatedButton(
                  onPressed: () => _controller.pause(),
                  child: Text("Pause"),
                ),
                ElevatedButton(
                  onPressed: () => _controller.resume(),
                  child: Text("Resume"),
                ),
                ElevatedButton(
                  onPressed: () => _controller.reset(60),
                  child: Text("Reset to 1 min"),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
160
points
37
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter timer that persists and calculates elapsed time when the app is in the background or terminated.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

bloc, flutter, flutter_bloc, shared_preferences

More

Packages that depend on background_timer_package