sport_exercise_tracker_widget 1.0.0
sport_exercise_tracker_widget: ^1.0.0 copied to clipboard
A Flutter package for real-time exercise tracking with camera and pose detection.
ποΈββοΈ Sport Exercise Tracker Widget #
A Flutter package that provides a ready-to-use camera-based exercise tracker widget.
It allows developers to integrate real-time exercise tracking using the camera π₯ and provides automatic repetition counting with visual feedback π.
Perfect for fitness apps, personal trainer apps, or any app that wants to guide users through exercises safely and interactively.
β¨ Features #
- π₯ Real-time camera preview (front/back)
- π€ Pose detection using keypoints (shoulders, elbows, knees, hipsβ¦)
- π Automatic repetition counting using state machine architecture for mouvement sequence detection.
- ποΈ Configurable difficulty levels (
easy
,medium
,hard
) and exercise types (squat
,biceps curl
,leg raise
,lateral raise
) - π Visual feedback: keypoints, connecting lines, angles, repetition counter
- π¨ Adjustable UI styles (colors, line thickness, circle radius, angles text)
- π« Works offline β no external servers required
π§ How It Works (Algorithm & Logic) #
The widget uses pose keypoints & angle calculations to detect exercises accurately. Main workflow:
-
Pose Detection π€³
- Captures camera frames in real-time.
- Detects keypoints for joints (shoulders, elbows, knees, hips, etc.).
-
Angle Calculation π
- Calculates specific joint angles per exercise.
- Examples:
- Curl β elbow angle
- Squat β knee & hip angles
- Angles determine start & end positions of each repetition.
-
Difficulty Level Adjustment π―
- Each level applies a threshold angle offset.
- Higher difficulty β stricter angle requirement to count a repetition.
-
Timing Filter β±οΈ
- Ensures natural movement duration.
- Prevents false positives from fast, jerky, or random movements.
-
Repetition Counting π’
- Counts a rep when:
- Angle reaches start threshold (minRequiredAngle - Difficulty_Offset)
- Then reaches end threshold (minRequiredAngle + Difficulty_Offset)
- And timing constraints are satisfied
- Sends real-time callback via
onRepsRepetitionCount
.
- Counts a rep when:
-
Visual Feedback ποΈ
- Draws keypoints on camera feed
- Connects joints with lines for better guidance
- Optional angle labels for user reference
- Repetition counter shown on screen
π Usage Example #
import 'package:sport_exercise_tracker_widget/camera_sport_exercise_tracker_widget.dart';
CameraSportExerciseTrackerWidget(
cameraConfig: CameraConfig(cameraDirection: CameraLensDirection.front),
exerciseName: ExerciseName.curl,
enableExerciseRepsCounting: true,
resetExerciseRepsCounting: false,
difficultyLevel: ExerciseDifficultyLevel.medium,
showKeypointCircles: true,
showKeypointLines: true,
showAnglesText: true,
onRepsRepetitionCount: (reps) {
print("Reps counted: $reps");
},
);
π§© Exercise Tracker Functional Diagram:
π¬ Check the video demo here Video Demo #
π§ Whatβs Next / To Be Improved #
1. Separation of Concerns #
Currently, ExercisePosePainterWidget
calculates angles and counts repetitions.
Planned improvement: move the calculation logic to a parent widget and inject only the calculated angles and rep counts into the painter. This will make the widget cleaner and easier to maintain.
2. Add More Exercises #
Currently, 4 exercises are implemented. You can easily add more exercises based on your needs.
To add an exercise:
- Add the exercise in
models/exercises.dart
- In
enums.dart
, define itsminRequiredAngle
andoffsetAngles
And Thatβs it π, the new exercise will be available in the dropdown selector in the example code.