smfit_fl_plugin 0.1.0+3 copy "smfit_fl_plugin: ^0.1.0+3" to clipboard
smfit_fl_plugin: ^0.1.0+3 copied to clipboard

SMFit plugin

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:smfit_fl_plugin/smfit_fl_plugin_delegate.dart';
import 'package:smfit_fl_plugin/smfit_fl_plugin.dart';
import 'package:smfit_fl_plugin/smfit_camera_widget.dart';

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> implements SMFitFlPluginDelegate {
  bool _didSuccess = false;
  final _smfitFlPlugin = SMFitFlPlugin();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    bool didSuccess;

    // add this delegate to get exercise data
    _smfitFlPlugin.delegate = this;
    // Before doing anything you need to call configSMFit with your key and wait for the result if not you will not be able to access plugin functions
    var result = await _smfitFlPlugin.configSMFit("YOUR_KEY");
    didSuccess = result.$1;

    if (!mounted) return;

    setState(() {
      _didSuccess = didSuccess;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('SMFit example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Text('Auth accepted: $_didSuccess\n'),
              SizedBox(
                height: 500,
                child: CameraWidget(),
              ),
              TextButton(onPressed: startSession, child: const Text("Start Session")),
              TextButton(onPressed: startDetection, child: const Text("Start Detection")),
              TextButton(onPressed: stopDetection, child: const Text("Stop Detection")),
              TextButton(onPressed: stopSession, child: const Text("Stop Session"))
            ],
          )
        ),
      ),
    );
  }

  void startSession() async {
    // Call this function to start the session
    String? error = await _smfitFlPlugin.startSession();
    print("Start Detection error: ${error ?? "non"}");
  }

  void startDetection() async {
    // Call startDetection to start a exercise
    // exercise options: AlternateWindmillToeTouch ,Burpees ,Crunches ,GlutesBridge ,HighKnees ,JumpingJacks ,LateralRaises ,Lunge ,LungeFront ,LungeSide ,LungeSideLeft ,LungeSideRight ,LungeSideSplit ,PlankHighKneeToElbow ,PlankHighShoulderTaps ,PushupRegular ,Jumps ,ReverseSitToTableTop ,ShouldersPress ,SideStepJacks ,SkaterHops ,SkiJumps ,SquatAndRotationJab ,SquatRegular ,StandingObliqueCrunches ,StandingStepReverseAirFly ,SumoSquatSpreadHandsVariation ,LungeRegularStatic ,PlankHighStatic ,SquatRegularOverheadStatic ,SquatRegularStatic ,SquatSumoStatic ,TuckHold ,StandingSideBendRight ,StandingSideBendLeft ,JeffersonCurlRight ,LungeSideStaticRight ,LungeSideStaticLeft, SquatRegularOverhead
    String? error = await _smfitFlPlugin.startDetection("HighKnees");
    print("Start Detection error: ${error ?? "non"}");

  }

  void stopDetection() async{
    var result = await _smfitFlPlugin.stopDetection();
    String? error = result.$1;
    Map<String, Object?> data = result.$2;
    print("Stop Detection error: ${error ?? "non"} data: $data");
  }

  void stopSession() async {
    var result = await _smfitFlPlugin.stopSession();
    String? error = result.$1;
    Map<String, Object?> data = result.$2;
    print("Stop Session error: ${error ?? "non"} data: $data");
  }

    @override
  void captureSessionStop() {
    // This function will be called when the session stopped and the camera is no longer available
  }

  @override
  void didReceiveError(String? error) {
    // This function will be called every time tou will get a error
    print(error);
  }

  @override
  void didReceiveMovementData(MovementData movementData) {
    // This function will be called every frame
    // movementData - This struct holds all the feedback data:
    // didDetectRep - (Dynamic exercise) If user did perform repetition
    // isGoodRep - (Dynamic exercise) true if the repetition was good
    // isInPosition - (Static/Isometric exercise type) true if the user in position
    // currentRomValue - The current Range Of Motion of the user
    // specialParams - some dynamic exercises will have some special params for example the exercise "Jumps" has "JumpPeakHeight" and "currHeight"
    print(movementData);
  }

  @override
  void didReceivePoseData(List<PoseData> poseData) {
    //This function will be called every frame
    //poseData - This a array of joints and there position (can be empty if the user was not detected in the camera field of view)
    print(poseData);
  }

  @override
  void captureSessionStart(){
    //Once the camera data is available this function will be called
  }
}