jyou_sdk 0.3.9 copy "jyou_sdk: ^0.3.9" to clipboard
jyou_sdk: ^0.3.9 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();
                    debugPrint("$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();
                  debugPrint("$val");
                },),
              ElevatedButton(
                child: const Text("Stop Scan",style: TextStyle(color: Colors.black),),
                onPressed: ()async{
                  var val=await jyou.stopScan();
                  debugPrint("$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");
                  debugPrint("$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();
                  debugPrint("$val");
                },),

              ElevatedButton(
                child: const Text("close Temperature",style: TextStyle(color: Colors.black),),
                onPressed: ()async {
                  var val = await jyou.closeTemperature();
                  debugPrint("$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}');
                    }
                  },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
130
pub points
0%
popularity

Publisher

verified publisherkakzaki.dev

Jyou SDK Flutter Plugin

Homepage

Documentation

API reference

License

CPL-1.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on jyou_sdk