xtravision_flutter_sdk 0.5.0
xtravision_flutter_sdk: ^0.5.0 copied to clipboard
A XtraVision Flutter package for integrating Flutter App with XtraVision SaaS platform. Currently support Android and IOS Platform.
example/lib/main.dart
import 'package:demo_app/my_assessment_view.dart';
import 'package:flutter/material.dart';
// import 'package:my_package/my_package.dart';
import 'package:camera/camera.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(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'XtraVision Flutter App',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePage();
}
class _MyHomePage extends State<MyHomePage> {
String _selectedAssessment = 'SQUATS';
String _selectedRadio = 'front';
bool _isSkeletonEnable = true;
CameraDescription _selectedCamera = cameras[1]; // default camera: front
// List of All Assessments
final List<String> _options = ['SQUATS', 'PUSH_UPS', 'BANDED_T'];
void _handleOptionChanged(String value) {
debugPrint("_MyHomePage: Selected Assessment is $value");
setState(() {
_selectedAssessment = value;
});
}
void _handleSkeletonValue(bool value) {
debugPrint("_MyHomePage: Selected 2D Skeleton value is $value");
setState(() {
_isSkeletonEnable = value;
});
}
void _handleRadioChanged(String value) {
debugPrint("_MyHomePage: Selected Camera is `$value` ");
_selectedRadio = value;
setState(() {
if (value == 'front') {
_selectedCamera = cameras[1];
} else {
_selectedCamera = cameras[0]; // back camera
}
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'XtraVision App',
home: Scaffold(
appBar: AppBar(
title: const Text('XtraVision Demo App'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Choose Assessment",
style: TextStyle(fontSize: 20, color: Colors.black)),
DropdownButton<String>(
value: _selectedAssessment,
items: _options
.map((option) => DropdownMenuItem(
value: option,
child: Text(option),
))
.toList(),
onChanged: (v) => _handleOptionChanged(v!),
),
// const SizedBox(height: 16),
const Text("Choose Camera",
style: TextStyle(fontSize: 20, color: Colors.black)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Radio(
value: 'front',
groupValue: _selectedRadio,
onChanged: (v) => _handleRadioChanged(v!),
),
const Text('Front'),
Radio(
value: 'back',
groupValue: _selectedRadio,
onChanged: (v) => _handleRadioChanged(v!),
),
const Text('Back'),
],
),
// const SizedBox(height: 16),
const Text("Enable 2D Skeleton",
style: TextStyle(fontSize: 20, color: Colors.black)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Radio(
value: true,
groupValue: _isSkeletonEnable,
onChanged: (v) => _handleSkeletonValue(v as bool),
),
const Text('True'),
Radio(
value: false,
groupValue: _isSkeletonEnable,
onChanged: (v) => _handleSkeletonValue(v as bool),
),
const Text('False'),
],
),
ElevatedButton(
child: Text("Let's Start $_selectedAssessment"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MyAssessmentView(
camera: _selectedCamera,
assessmentName: _selectedAssessment,
isSkeletonEnable: _isSkeletonEnable)),
);
},
),
],
),
),
),
);
}
}