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

PlatformAndroidiOS
outdated

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();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    bool didSuccess;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    _smfitFlPlugin.delegate = this;
    var result = await _smfitFlPlugin.configSMFit("");
    didSuccess = result.$1;
    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _didSuccess = didSuccess;

      if (didSuccess){
        _smfitFlPlugin.startSession();
        _smfitFlPlugin.startDetection("HighKnees");
        // Future.delayed(Duration(seconds: 3),(){
        //   _smfitFlPlugin.stopDetection();
        //   _smfitFlPlugin.stopSession();
        // });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Text('Auth accepted: $_didSuccess\n'),
              SizedBox(
                height: 500,
                child: CameraWidget(),
              )
            ],
          )
        ),
      ),
    );
  }

  @override
  void captureSessionStop() {
    // TODO: implement captureSessionStop
  }

  @override
  void didReceiveError(String? error) {
    print(error);
    // TODO: implement didReceiveError
  }

  @override
  void didReceiveMovementData(MovementData movementData) {
    print(movementData);
    // TODO: implement didReceiveMovementData
  }

  @override
  void didReceivePoseData(List<PoseData> poseData) {
    print(poseData);
    // TODO: implement didReceivePoseData
  }

  @override
  void captureSessionStart(){
  }
}