jyou_sdk 0.0.7
jyou_sdk: ^0.0.7 copied to clipboard
Jyou SDK Flutter Plugin
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:jyou_sdk/jyou_sdk.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
JyouSdk jyou=JyouSdk();
@override
void initState() {
jyou=JyouSdk();
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: ListView(
shrinkWrap: true,
primary: true,
physics: const ScrollPhysics(),
children: [
ElevatedButton(
child: const Text("Bind",style: TextStyle(color: Colors.black),),
onPressed: ()async{
var val=await jyou.bind();
print(val);
},),
ElevatedButton(
child: const Text("UnBind",style: TextStyle(color: Colors.black),),
onPressed: (){
jyou.unbind();
},),
ElevatedButton(
child: const Text("Scan",style: TextStyle(color: Colors.black),),
onPressed: ()async{
var val=await jyou.scan();
print(val);
},),
ElevatedButton(
child: const Text("Stop Scan",style: TextStyle(color: Colors.black),),
onPressed: ()async{
var val=await jyou.stopScan();
print(val);
},),
ElevatedButton(
child: const Text("Connect",style: TextStyle(color: Colors.black),),
onPressed: ()async {
var val = await jyou.connect(bname: "G12PRO-058D", bmac: "02:00:01:00:05:8D");
print(val);
},),
ElevatedButton(
child: const Text("Disconnect",style: TextStyle(color: Colors.black),),
onPressed: (){
jyou.disconnect();
},),
ElevatedButton(
child: const Text("open Temperature",style: TextStyle(color: Colors.black),),
onPressed: ()async {
var val = await jyou.openTemperature();
print(val);
},),
ElevatedButton(
child: const Text("close Temperature",style: TextStyle(color: Colors.black),),
onPressed: ()async {
var val = await jyou.closeTemperature();
print(val);
},),
StreamBuilder<dynamic>(
stream: JyouSdk.getDeviceListStream,
builder: (BuildContext context,AsyncSnapshot<dynamic>snapshot,) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
} else if (snapshot.connectionState == ConnectionState.active || snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
return const Text('Error');
} else if (snapshot.hasData) {
return Text(
snapshot.data.toString(),
style: const TextStyle(color: Colors.red, fontSize: 12)
);
} else {
return const Text('Empty data');
}
} else {
return Text('State: ${snapshot.connectionState}');
}
},
),
],
),
),
),
);
}
}