vra_camera_plugin 0.0.2
vra_camera_plugin: ^0.0.2 copied to clipboard
vieaura camera plugin.
example/lib/main.dart
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'dart:async';
import 'dart:ui' as ui;
import 'package:flutter/services.dart';
import 'package:vra_camera_plugin/vra_camera_plugin.dart';
List<CameraDescription> cameras = [];
void main() {
RenderErrorBox.backgroundColor = Colors.transparent;
RenderErrorBox.textStyle = ui.TextStyle(color: Colors.transparent);
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _photosResults = 'Welcome to New Camera plugin in Flutter';
late CameraController controller;
@override
void initState() {
super.initState();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> startCameraOnAndroidPhone() async {
controller.dispose();
dynamic photos;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
photos = await VraCameraPlugin.takeSinglePhotoOnAndroidPhone();
for (var element in photos) {
print(element);
}
} on PlatformException {
// ocrResult = 'Failed to get OCR result.';
}
setState(() {
});
// 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(() {
// _photosResults = photos!;
// });
}
Future<void> startCameraOnRealwear() async {
controller.dispose();
dynamic photos;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
photos = await VraCameraPlugin.takeSinglePhotoOnRealwear();
for (var element in photos) {
print(element);
}
} on PlatformException {
// ocrResult = 'Failed to get OCR result.';
}
setState(() {
});
// 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(() {
// _photosResults = photos!;
// });
}
Future<void> startRecordVideo() async {
controller.dispose();
dynamic video;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
video = await VraCameraPlugin.recordVideo();
print(video);
} on PlatformException {
// ocrResult = 'Failed to get OCR result.';
}
setState(() {
});
// 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(() {
// _photosResults = photos!;
// });
}
Future<void> initCamera() async {
cameras = await availableCameras();
if (cameras.isNotEmpty) {
controller = CameraController(cameras[0], ResolutionPreset.medium,
enableAudio: false);
await controller.initialize();
}
}
@override
Widget build(BuildContext context) {
return FutureBuilder<void>(
future: initCamera(),
builder: (BuildContext context, AsyncSnapshot<void> snapshot) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Camera Plugin example app'),
),
body: Stack(
children: [
CameraPreview(controller),
Align(
alignment: Alignment.center,
child: Text(_photosResults),
),
Align(
alignment: Alignment.topLeft,
child: TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.blue,
),
onPressed: startCameraOnAndroidPhone,
child: const Text('Android Phone'),
)
),
Align(
alignment: Alignment.topCenter,
child: TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.blue,
),
onPressed: startCameraOnRealwear,
child: const Text('Realwear'),
)
),
Align(
alignment: Alignment.topRight,
child: TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.blue,
),
onPressed: startRecordVideo,
child: const Text('Record Video'),
)
),
]
),
),
);
});
return MaterialApp(
home: CameraPreview(controller),
);
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Camera Plugin example app'),
),
body: Stack(
children: [
CameraPreview(controller),
Align(
alignment: Alignment.center,
child: Text(_photosResults),
),
Align(
alignment: Alignment.topLeft,
child: TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.blue,
),
onPressed: startCameraOnAndroidPhone,
child: const Text('Android Phone'),
)
),
Align(
alignment: Alignment.topRight,
child: TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.blue,
),
onPressed: startCameraOnRealwear,
child: const Text('Realwear'),
)
),
]
),
),
);
}
}