xtravision_flutter_sdk 0.6.0 copy "xtravision_flutter_sdk: ^0.6.0" to clipboard
xtravision_flutter_sdk: ^0.6.0 copied to clipboard

outdated

A XtraVision Flutter package for integrating Flutter App with XtraVision SaaS platform. Currently support Android and IOS Platform.

XtraVision Flutter Package #

Pub Version

A Flutter package for integrating Flutter App with XtraVision SaaS platform. xtravision_flutter_sdk provides an easy-to-use API for interacting with XtraVision SaaS platform's services, enabling seamless integration and streamlined user experiences.

Getting started #

Install: #

flutter pub add camera xtravision_flutter_sdk

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
    camera: ^0.10.4
    xtravision_flutter_sdk: ^0.4.0

Import it: #

Now in your Dart code, you can use below code to import it:

import 'package:xtravision_flutter_sdk/xtravision_flutter_sdk.dart';

Integration with iOS #

Add one row to the ios/Runner/Info.plist:

Privacy - Camera Usage Description and a usage description.

If editing Info.plist as text, add:

<key>NSCameraUsageDescription</key>
<string>your usage description here</string>

Integration With Android #

  • Change the minimum Android sdk version to 21 (or higher) in your android/app/build.gradle file.

    minSdkVersion 21
    
  • Add all required dependencies in the android/app/build.gradle file.

    implementation "androidx.lifecycle:lifecycle-runtime:2.0.0"
    implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
    annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0"
    

Integration with Codebase: #

Please refer below codebase for reference purpose.

  • In lib/main.dart, we get a list of cameras and select which are going to use (Either front or back). The selected camera will pass to the MyAssessmentView widget class.

    import 'package:flutter/material.dart';
    import 'package:camera/camera.dart';
    
    import 'my_assessment_view.dart';
    
    List<CameraDescription> cameras = [];
    
    Future<void> main() async {
        try {
            // Ensure that plugin services are initialized so that `availableCameras()`
            // can be called before `runApp()`
            WidgetsFlutterBinding.ensureInitialized();
    
            // Obtain a list of the available cameras on the device.
            cameras = await availableCameras();
        } on CameraException catch (e) {
            debugPrint('Error in fetching the cameras: $e');
        }
    
        runApp(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: 'XtraVision Demo App',
            home: Scaffold(
                appBar: AppBar(
                title: const Text('XtraVision Demo App'),
                ),
                body: const MyHomePage(),
            )
            );
        }
    }
    
    class MyHomePage extends StatefulWidget {
        const MyHomePage({super.key});
        @override
        State<MyHomePage> createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
        @override
        Widget build(BuildContext context) {
            // 0 for back camera, and one for front camera
            return MyAssessmentView(camera: cameras[1]);
        }
    }
    
    
  • lib/my_assessment_view.dart file looks like:

    import 'package:flutter/material.dart';
    import 'package:camera/camera.dart';
    import 'package:xtravision_flutter_sdk/xtravision_flutter_sdk.dart';
    
    class MyAssessmentView extends StatefulWidget {
        final CameraDescription camera;
    
        MyAssessmentView({required this.camera});
    
        @override
        State<MyAssessmentView> createState() => _MyAssessmentViewState();
    }
    
    class _MyAssessmentViewState extends State<MyAssessmentView> {
    
        late XtraVisionConnectionData connectionData = XtraVisionConnectionData();
        late XtraVisionLibData libData = XtraVisionLibData();
    
        @override
        void initState() {
            super.initState();
        }
    
        @override
        void dispose() {
            super.dispose();
        }
    
        XtraVisionConnectionData _getConnectionData() {
            connectionData.assessmentName = 'SQUATS'; // Set Assessment Name
            connectionData.authToken =
                "__AUTH_TOKEN__";   // Set User specific auth-token
    
            return connectionData;
        }
    
        XtraVisionLibData _getLibData() {
            // Get a specific camera from the list of available cameras.
            libData.camera = widget.camera;
            libData.onServerResponse = onServerResponse;
            libData.enableSkeletonView = true; // show skeleton view
    
    
            return libData;
        }
    
        onServerResponse(serverResponse) {
            //Imp: wrap below code in try catch block.
            try {
            // ignore: avoid_print
            print("XtraVision Server Response =============> ${serverResponse!}");
            } catch (exception) {
            // ignore: avoid_print
            print(exception);
            }
        }
    
        @override
        Widget build(BuildContext context) {
              
            return XtraVisionAssessmentWidget(
            connectionData: _getConnectionData(),
            libData: _getLibData(),
            );
        }
    }
    
    

IMPORTANT: Kindly configure all required connectionData and libData in above class as per your need:

Once all required integration steps completed then server response will be printed into your flutter console:

I/flutter (26670): XtraVision Server Response =============> {"errors": [], "data": {"additional_response": {"in_pose": false, "reps": {"active_right": 0, "active_left": 0, "total": 0}, "raw_reps": [], "active_side": ""}, "angles": {"elbow_right": 39, "elbow_left": 47, "shoulder_right": 0, "shoulder_left": 0, "hip_right": 75, "hip_left": 47, "knee_right": 0, "knee_left": 0, "ankle_right": 0, "ankle_left": 0}, "corrective_feedback": [], "message": {}, "session_id": "cb7ca2bf-3e7b-4386-bb35-11ea07143a73", "assessment": "SQUATS", "timestamp": "1681394705047", "out_of_screen_feedback": {}, "meta": {}, "category": "POSE_BASED_REPS"}}

Additional information #

We are internally using GoogleML Kit for extracting body key-points. It's important to note that the GoogleML kit is not working properly on emulators So it's recommended to test your app with xtravision_flutter_sdk on a physical Android/IOS device is the best way to ensure proper functionality. Physical devices typically provide better hardware support and performance compared to emulators.

Known Issue: #

  • Facing some height/width specific issue with landscape mode so it may not work.
1
likes
0
points
40
downloads

Publisher

verified publisherxtravision.ai

Weekly Downloads

A XtraVision Flutter package for integrating Flutter App with XtraVision SaaS platform. Currently support Android and IOS Platform.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

camera, flutter, google_mlkit_commons, google_mlkit_pose_detection, logger, web_socket_channel

More

Packages that depend on xtravision_flutter_sdk