vuzix_flutter_plugin 0.0.8
vuzix_flutter_plugin: ^0.0.8 copied to clipboard
Vuzix z100 plugin.
example/lib/main.dart
import 'dart:convert';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:vuzix_flutter_plugin/vuzix_flutter_plugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Map<String, dynamic> _vuzixStatus = {};
String _sendNotificationResult = '';
String _sendTextResult = '';
String _sendImageResult = '';
String _sendImageWithTextResult = '';
String _initScrollLayoutResult = '';
String _scrollTextResult = '';
String _clearImageResult = '';
final _vuzixFlutterPlugin = VuzixFlutterPlugin();
TextEditingController notificationTextFieldController = TextEditingController();
TextEditingController textTextFieldController = TextEditingController();
TextEditingController imageUrlTextFieldController = TextEditingController();
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String vuzixStatus;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
vuzixStatus =
await _vuzixFlutterPlugin.checkVuzixStatus() ?? 'Unknown status';
} on PlatformException {
vuzixStatus = 'Failed to check Vuzix status.';
}
// 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(() {
try {
_vuzixStatus = jsonDecode(vuzixStatus);
} catch (ex) {
debugPrint("error: ${ex.toString()}");
}
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
const SizedBox(
height: 20,
),
// _vuzixStatus.containsKey("glassConnected")
// ? _vuzixStatus["glassConnected"] == true
// ? const Text('Connected')
// : const Text('Not Connected')
// : const Text('Not Connected'),
// const SizedBox(
// height: 20,
// ),
// _vuzixStatus.containsKey("sdkAvailable")
// ? _vuzixStatus["sdkAvailable"] == true
// ? const Text('Sdk Available')
// : const Text('Sdk Not Available')
// : const Text('Sdk Not Available'),
// const SizedBox(
// height: 20,
// ),
// _vuzixStatus.containsKey("glassLinked")
// ? _vuzixStatus["glassLinked"] == true
// ? const Text('Linked')
// : const Text('Not Linked')
// : const Text('Not Linked'),
// const SizedBox(
// height: 20,
// ),
// Notification
Padding(
padding: const EdgeInsets.only(left: 30.0, right: 30.0),
child: TextField(
controller: notificationTextFieldController,
decoration: const InputDecoration(
fillColor: Colors.white,
hintText: "Enter your message to notify here"),
),
),
TextButton(
onPressed: () async {
initPlatformState();
try {
_sendNotificationResult = await _vuzixFlutterPlugin
.sendNotification(notificationTextFieldController.text) ??
'Unknown result';
setState(() {});
} on PlatformException {
_sendNotificationResult =
'Failed to get notification result.';
}
},
style: TextButton.styleFrom(
foregroundColor: const Color(0xffFAFBFF),
backgroundColor: Colors.blue),
child: const Text("Send Notification"),
),
const SizedBox(
height: 20,
),
if (_sendNotificationResult != "")
const Text('Send Notification Result:'),
if (_sendNotificationResult != "")
Text('$_sendNotificationResult\n'),
// Text
Padding(
padding: const EdgeInsets.only(left: 30.0, right: 30.0),
child: TextField(
controller: textTextFieldController,
decoration: const InputDecoration(
fillColor: Colors.white,
hintText: "Enter your text to display here"),
),
),
TextButton(
onPressed: () async {
initPlatformState();
try {
_sendTextResult = await _vuzixFlutterPlugin
.sendText(textTextFieldController.text) ??
'Unknown result';
setState(() {});
} on PlatformException {
_sendTextResult =
'Failed to get send text result.';
}
},
style: TextButton.styleFrom(
foregroundColor: const Color(0xffFAFBFF),
backgroundColor: Colors.blue),
child: const Text("Send Text"),
),
const SizedBox(
height: 20,
),
if (_sendTextResult != "")
const Text('Send Text Result:'),
if (_sendTextResult != "")
Text('$_sendTextResult\n'),
// Image
Padding(
padding: const EdgeInsets.only(left: 30.0, right: 30.0),
child: TextField(
controller: imageUrlTextFieldController,
decoration: const InputDecoration(
fillColor: Colors.white,
hintText: "Enter your image url to send here"),
),
),
TextButton(
onPressed: () async {
initPlatformState();
debugPrint("_vuzixStatus: ${_vuzixStatus.toString()}");
try {
_sendImageResult = await _vuzixFlutterPlugin
.sendImage(imageUrlTextFieldController.text) ??
'Unknown result';
setState(() {});
} on PlatformException {
_sendImageResult =
'Failed to get send image result.';
}
},
style: TextButton.styleFrom(
foregroundColor: const Color(0xffFAFBFF),
backgroundColor: Colors.blue),
child: const Text("Send Image"),
),
const SizedBox(
height: 20,
),
if (_sendImageResult != "")
const Text('Send Image Result:'),
if (_sendImageResult != "")
Text('$_sendImageResult\n'),
// Image with Text
TextButton(
onPressed: () async {
initPlatformState();
debugPrint("_vuzixStatus: ${_vuzixStatus.toString()}");
try {
_sendImageWithTextResult = await _vuzixFlutterPlugin
.sendImageWithText(imageUrlTextFieldController.text, textTextFieldController.text) ??
'Unknown result';
setState(() {});
} on PlatformException {
_sendImageWithTextResult =
'Failed to get send image with text result.';
}
},
style: TextButton.styleFrom(
foregroundColor: const Color(0xffFAFBFF),
backgroundColor: Colors.blue),
child: const Text("Send Image with Text"),
),
const SizedBox(
height: 20,
),
if (_sendImageWithTextResult != "")
const Text('Send Image with Text Result:'),
if (_sendImageWithTextResult != "")
Text('$_sendImageWithTextResult\n'),
// Scroll test
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// Init Scroll Layout
TextButton(
onPressed: () async {
initPlatformState();
debugPrint("_vuzixStatus: ${_vuzixStatus.toString()}");
try {
_initScrollLayoutResult = await _vuzixFlutterPlugin
.initScrollLayout(textTextFieldController.text) ??
'Unknown result';
setState(() {});
} on PlatformException {
_initScrollLayoutResult =
'Failed to init scroll layout result.';
}
},
style: TextButton.styleFrom(
foregroundColor: const Color(0xffFAFBFF),
backgroundColor: Colors.blue),
child: const Text("Init Scroll Layout"),
),
// Scroll Down
TextButton(
onPressed: () async {
initPlatformState();
debugPrint("_vuzixStatus: ${_vuzixStatus.toString()}");
try {
_initScrollLayoutResult = await _vuzixFlutterPlugin
.scrollDown() ??
'Unknown result';
setState(() {});
} on PlatformException {
_initScrollLayoutResult =
'Failed to get scroll text result.';
}
},
style: TextButton.styleFrom(
foregroundColor: const Color(0xffFAFBFF),
backgroundColor: Colors.blue),
child: const Text("Scroll Text Layout"),
),
const SizedBox(
height: 20,
),
],
),
const SizedBox(
height: 20,
),
if (_initScrollLayoutResult != "")
const Text('Init Scroll Layout Result:'),
if (_initScrollLayoutResult != "")
Text('$_initScrollLayoutResult\n'),
if (_scrollTextResult != "")
const Text('Scroll Text Result:'),
if (_scrollTextResult != "")
Text('$_scrollTextResult\n'),
// Clear
TextButton(
onPressed: () async {
initPlatformState();
try {
_clearImageResult = await _vuzixFlutterPlugin
.clearCanvas() ??
'Unknown result';
setState(() {});
} on PlatformException {
_clearImageResult =
'Failed to get clear canvas result.';
}
},
style: TextButton.styleFrom(
foregroundColor: const Color(0xffFAFBFF),
backgroundColor: Colors.blue),
child: const Text("Clear"),
),
const SizedBox(
height: 20,
),
if (_clearImageResult != "")
const Text('Clear Result:'),
if (_clearImageResult != "")
Text('$_clearImageResult\n'),
],
),
),
),
theme: ThemeData(scaffoldBackgroundColor: const Color(0xFFEFEFEF)),
);
}
}