witsystem_flutter_sdk_v2 5.3.2 copy "witsystem_flutter_sdk_v2: ^5.3.2" to clipboard
witsystem_flutter_sdk_v2: ^5.3.2 copied to clipboard

集成Android 和ios的witsystemSDK插件.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:witsystem_flutter_sdk_v2/SDK/api/callBack/AddBleScanCall.dart';
import 'package:witsystem_flutter_sdk_v2/SDK/api/callBack/BleDeviceCall.dart';
import 'package:witsystem_flutter_sdk_v2/SDK/api/parameter/BleConnectStateChange.dart';
import 'package:witsystem_flutter_sdk_v2/SDK/api/parameter/DeviceStatusInfo.dart';
import 'package:witsystem_flutter_sdk_v2/SDK/api/parameter/Hardware.dart';
import 'dart:async';

import 'package:witsystem_flutter_sdk_v2/SDK/config/WitsystemSDKConfig.dart';
import 'package:witsystem_flutter_sdk_v2/SDK/modles/DeviceUser.dart';
import 'package:witsystem_flutter_sdk_v2/SDK/sdk/SDK.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  StreamSubscription<BleConnectStateChange>? subscription;

  @override
  void initState() {
    super.initState();
    initPlatformState();
    String RSAPrivateKey = "-----BEGIN PRIVATE KEY-----Bv6MSqpWxxxxxxxxxxxx0kX2DJBOZ/W+lA=-----END PRIVATE KEY-----";
    String token = "exxxxxxxxxxjLF-H1L8E";
    WitsystemSDKConfig config =  WitsystemSDKConfig(
        appId: "wsf9f1xxx",
        appSecret: "xxxxxxx",
        token: token,
        AESKey: "xxxxxxxxxxxx",
        RSAPrivateKey: RSAPrivateKey);
    SDK().initSDK(config).then((value) {
      print("初始化成功");
      print(value);
    }).onError((error, stackTrace) {
      print("初始化失败");
      print(error);
    });
  }

  Future<void> initPlatformState() async {
    if (!mounted) return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('链接'),
          ),
          body: Column(
            children: [
              Row(children: [
                TextButton(
                  child: Text("连接"),
                  onPressed: () {
                    SDK().getBleDevice().then((value) {
                      value?.connect("Slock383B2694236F", true).then((value) {
                        print("连接成功>>>>>>>>>>>>>>>>");
                      }).onError((error, stackTrace) {
                        print("连接失败>>>>>>>>>>.");
                        print(error);
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败");
                      print(error);
                    });
                  },
                ),
                TextButton(
                  child: Text("开门"),
                  onPressed: () {
                    SDK().getBleDevice().then((value) {
                      value?.unlock().then((value) {
                        print("开门成功");
                        print(value);
                      }).onError((error, stackTrace) {
                        print("开门失败");
                        print(error);
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败");
                      print(error);
                    });
                  },
                ),
                TextButton(
                  child: Text("断开"),
                  onPressed: () {
                    SDK().getBleDevice().then((value) {
                      value?.disconnect().then((value) {
                        print("断开成功???");
                      }).onError((error, stackTrace) {
                        print("断开失败??");
                        print(error);
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败");
                      print(error);
                    });
                  },
                ),
              ]),

              Row(children: [
                TextButton(
                  child: Text("添加管理员密码"),
                  onPressed: () {
                    SDK().getBleDevice().then((value) {
                      print("获取对象成功");
                      print(value);
                      value?.addAdminPassword("123456").then((value) {
                        print("添加成功");
                      }).onError((error, stackTrace) {
                        print("添加失败");
                        print(error);
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败");
                      print(error);
                    });
                  },
                ),
                TextButton(
                  child: Text("添加卡"),
                  onPressed: () {
                    SDK().getBleDevice().then((value) {
                      print("获取对象成功");
                      print(value);
                      value?.addAdminCard().then((value) {
                        print("添加卡成功");
                      }).onError((error, stackTrace) {
                        print("添加卡失败");
                        print(error);
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败");
                      print(error);
                    });
                  },
                ),
                TextButton(
                  child: Text("添加指纹"),
                  onPressed: () {
                    SDK().getBleDevice().then((value) {
                      var bleDeviceCall =
                      BleDeviceCall<String>(success: (String uid) {
                        // 处理成功回调
                        print("添加指纹成功$uid");
                      }, fail: (error) {
                        print("添加指纹失败$error");
                      }, markProgress: (overall, current) {
                        print("添加指纹进度$overall:::$current");
                      });

                      value?.addAdminMark(bleDeviceCall);
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),
              ]),


              Row(children: [
                TextButton(
                  child: Text("检查升级"),
                  onPressed: () {
                    SDK().getBleDevice().then((value) {
                      value?.checkFirmwareUpdates().then((value1) {
                        print("检查升级返回的对象${value1?.toMap()}");

                        value?.upgradeFirmware(
                            firmwareUpdate: value1!,
                            call: BleDeviceCall<String>(success: (version) {
                              print("升级固件成功$version");
                            }, fail: (error) {
                              print("升级固件失败$error");
                            }, otaProgress: (c) {
                              print("升级固件进度:$c");
                            }));
                      }).onError((error, stackTrace) {
                        print("检查升级失败$error");
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),
                TextButton(
                  child: Text("监听连接状态"),
                  onPressed: () {
                    SDK().getBleDevice().then((value) {
                      subscription = value
                          ?.connectChange()
                          .listen((BleConnectStateChange event) {
                        print(
                            "首页监听》》》》》》》》监听对象${event.deviceId}:::${event.status}");
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),
                TextButton(
                  child: Text("取消监听连接"),
                  onPressed: () {
                    SDK().getBleDevice().then((value) {
                      value?.cancelConnectChange(subscription);
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),
              ]),

              Row(children: [

                TextButton(
                  child: Text("扫描添加的设备"),
                  onPressed: () {
                    bool isAdd=false;
                    SDK().getAddBleDevice().then((value) {
                      value?.scan(AddBleScanCall(scanResult:
                          (String deviceId, int rssi, List<int> data) {
                        print("扫描到的设备$deviceId :: $rssi:::$data");
                        value.stopScan();
                        if(!isAdd){
                          isAdd=true;
                          value.add(deviceId: deviceId, deviceName: "flutter 测试")
                              .then((value) {
                            print("添加成功${value.device?.deviceId}");
                          }).onError((error, stackTrace) {
                            print("添加失败$error");
                          });
                        }

                      }, fail: (PlatformException error) {
                        print("扫描设备识别$error");
                      }));
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),
                TextButton(
                  child: Text("停止扫描添加设备"),
                  onPressed: () {
                    SDK().getAddBleDevice().then((value) {
                      value?.stopScan();
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),
              ]),



              Row(children: [
                TextButton(
                  child: Text("获得设备列表"),
                  onPressed: () {
                    SDK().getDeviceManage().then((value) {
                      value?.deviceList().then((List<DeviceUser> value) {
                        for (var value1 in value) {
                          print("获取设备列表成功${value1.deviceName}");
                        }
                      }).onError((error, stackTrace) {
                        print("获取设备列表失败$error");
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),


                TextButton(
                  child: Text("设备支持的功能列表"),
                  onPressed: () {
                    SDK().getDeviceManage().then((value) {
                      value?.supportedHardwareList("Slock383B2694236F").then((value){
                        for (var value1 in value) {
                          print("获得功能列表成功$value1");
                        }
                      }).onError((error, stackTrace) {
                        print("获得功能列表失败$error");
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),

                TextButton(
                  child: Text("刷新"),
                  onPressed: () {
                    SDK().getDeviceManage().then((value) {
                      value?.refreshDevice("Slock383B2694236F").then((value){
                        print("刷新设备成功$value");
                      }).onError((error, stackTrace) {
                        print("刷新设备失败$error");
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),



              ],),

              Row(children: [
                TextButton(
                  child: Text("是否支持"),
                  onPressed: () {
                    SDK().getDeviceManage().then((value) {
                      value?.isSupportedHardware("Slock383B2694236F",Hardware.ble).then((value){
                        print("是否支持$value");
                      }).onError((error, stackTrace) {
                        print("是否支持$error");
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),


                TextButton(
                  child: Text("是否连接"),
                  onPressed: () {
                    SDK().getBleDevice().then((value) {
                      value?.isConnect().then((value){
                        print("是否已经连接$value");
                      }).onError((error, stackTrace) {
                        print("是否已经连接$error");
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),

                TextButton(
                  child: Text("读取设备状态"),
                  onPressed: () {
                    SDK().getBleDevice().then((value) {
                      value?.readDeviceStatus().then((value){
                        print("读取设备状态${value?.toMap()}");
                      }).onError((error, stackTrace) {
                        print("读取设备状态失败$error");
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),




                TextButton(
                  child: Text("设备支持的功能"),
                  onPressed: () {
                    SDK().getDeviceManage().then((value) {
                      value?.deviceFunctionInfo("Slock383B2694236F").then((value){
                        print("设备支持的功能${value?.passwordType}");
                      }).onError((error, stackTrace) {
                        print("设备支持的功能失败$error");
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),
              ],),

              Row(children: [

                TextButton(
                  child: Text("修改音量"),
                  onPressed: () {
                    SDK().getBleDevice().then((value) {
                      value?.readDeviceStatus().then((DeviceStatusInfo? state){
                        state?.volume=7;
                        value.updateDeviceStatus(state!).then((value) {
                          print("修改音量成功$value");
                        }).onError((error, stackTrace){
                          print("修改音量失败$error");
                        });

                      }).onError((error, stackTrace) {
                        print("修改音量失败$error");
                      });
                    }).onError((error, stackTrace) {
                      print("获取对象失败$error");
                    });
                  },
                ),


                TextButton(
                  child: Text("读取设备日志"),
                  onPressed: () {
                    SDK().getBleDevice().then((value) {
                      value?.readDeviceRecord().then(( list){
                        print("读取设备日志${list?.length}");
                      }).onError((error, stackTrace) {
                        print("读取设备日志失败$error");
                      });
                    }).onError((error, stackTrace) {
                      print("读取设备日志失败$error");
                    });
                  },
                ),


                TextButton(
                  child: Text("获得指定设备信息"),
                  onPressed: () {
                    SDK().getDeviceManage().then((value) {
                      value?.getDeviceInfo("Slock383B2694236F").then(( list){
                        print("获得指定设备信息${list}");
                      }).onError((error, stackTrace) {
                        print("获得指定设备信息失败$error");
                      });
                    }).onError((error, stackTrace) {
                      print("获得指定设备信息失败$error");
                    });
                  },
                ),


                TextButton(
                  child: Text("获得当前状态"),
                  onPressed: () {
                    SDK().getDeviceManage().then((value) {
                      value?.getDeviceStatus("Slock383B2694236F").then(( list){
                        print("获得当前状态${list}");
                      }).onError((error, stackTrace) {
                        print("获得当前状态失败$error");
                      });
                    }).onError((error, stackTrace) {
                      print("获得当前状态失败$error");
                    });
                  },
                ),
              ],)
            ],
          )),
    );
  }
}
2
likes
115
points
47
downloads

Publisher

unverified uploader

Weekly Downloads

集成Android 和ios的witsystemSDK插件.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on witsystem_flutter_sdk_v2