Skip to content

a-mabe/background_hiit_timer

Repository files navigation

background_hiit_timer

A Flutter package for creating a high-intensity interval training (HIIT) timer with background service capabilities. Originally created for OpenHIIT.

Screenshot 2024-11-10 at 4 22 43 PM


Table of Contents

  1. Installation
  2. Basic Usage
    1. Example Usage
  3. Advanced Configuration
  4. Contributing
    1. Code of Conduct
  5. Credits
  6. License

Installation

Add background_hiit_timer to your pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  background_hiit_timer: ^1.0.0

Basic Usage

Import background_hiit_timer in your Dart file:

import 'package:background_hiit_timer/background_hiit_timer.dart';
  1. Ensure that your app is properly configured to handle background execution on both Android and iOS platforms. Refer to flutter_background_service for details.

  2. Define a set of intervals:

final List<IntervalType> intervals = [
    IntervalType(
        id: "0",
        workoutId: "1",
        time: 10, // in seconds
        name: "Get ready",
        color: 0,
        intervalIndex: 0,
        startSound: "",
        halfwaySound: "",
        countdownSound: "countdown-beep",
        endSound: ""),

    ...

    IntervalType(
        id: "4",
        workoutId: "1",
        time: 10, // in seconds
        name: "Cooldown",
        color: 0,
        intervalIndex: 4,
        startSound: "long-rest-beep",
        countdownSound: "countdown-beep",
        endSound: "horn",
        halfwaySound: ""),
  ];
  1. Define a controller:
final CountdownController _controller = CountdownController(autoStart: true);
  1. Create a Countdown widget and configure it with your interval settings:
Countdown(
  controller: _controller,
  intervals: intervals,
  onFinished: () {},
  build: (_, TimerState timerState) {
    Text(timerState.currentMicroSeconds.toString())
  }
)

Example Usage

Check out the example directory in this repository for a complete example of how to use background_hiit_timer in a Flutter app.

Advanced Configuration

For more advanced information, view the advanced configuration documentation.

Contributing

View the contributing documentation. If contributing code changes, please checkout the testing documentation.

Code of Conduct

When contributing, please keep the Code of Conduct in mind.

Credits

This package is inspired by the timer_count_down package by Dizoft Team.

Shoutout to flutter_background_service for making the background timer possible.

License

MIT License. See LICENSE for details.