|
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
import 'my_page/revise_password_page.dart';
|
|
import 'my_page/revise_password_page.dart';
|
|
|
import 'package:flutter_picker/flutter_picker.dart';
|
|
import 'package:flutter_picker/flutter_picker.dart';
|
|
|
-import 'dart:convert';
|
|
|
|
|
import '../util/bluetooth_utils.dart';
|
|
import '../util/bluetooth_utils.dart';
|
|
|
import '../showDialog.dart';
|
|
import '../showDialog.dart';
|
|
|
import '../login_page.dart';
|
|
import '../login_page.dart';
|
|
@@ -60,6 +59,8 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
void initState() {
|
|
void initState() {
|
|
|
|
|
+ btList.clear();
|
|
|
|
|
+ btSet.clear();
|
|
|
super.initState();
|
|
super.initState();
|
|
|
getStationList().then((resp) {
|
|
getStationList().then((resp) {
|
|
|
if (isNotError(context, resp)) {
|
|
if (isNotError(context, resp)) {
|
|
@@ -128,6 +129,27 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
onEvent(Object obj) {
|
|
onEvent(Object obj) {
|
|
|
print('进入onEvent回调${obj}');
|
|
print('进入onEvent回调${obj}');
|
|
|
if (obj.toString().indexOf('||') != -1) { //过滤开始搜索和结束搜索
|
|
if (obj.toString().indexOf('||') != -1) { //过滤开始搜索和结束搜索
|
|
|
|
|
+ if(obj.toString().indexOf('CONNECTED')!=-1){
|
|
|
|
|
+ setState(() {
|
|
|
|
|
+ for(int i=0;i<btList.length;i++){
|
|
|
|
|
+ if(i==publicIndex){
|
|
|
|
|
+ btList[i].showLoadStauts = false;
|
|
|
|
|
+ btList[i].connectStatus = true;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ btList[i].showLoadStauts = false;
|
|
|
|
|
+ btList[i].connectStatus = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+ String tempStr = '';
|
|
|
|
|
+ for (int i = 0; i < btList.length; i++) {
|
|
|
|
|
+ tempStr += '${btList[i].name}&';
|
|
|
|
|
+ }
|
|
|
|
|
+ print(tempStr);
|
|
|
|
|
+ setKey('btList', tempStr);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
btSet.add(obj.toString()); //去重
|
|
btSet.add(obj.toString()); //去重
|
|
|
List tempBtList = btSet.toList();
|
|
List tempBtList = btSet.toList();
|
|
|
List<BtInfoObj> tempBtList2 = [];
|
|
List<BtInfoObj> tempBtList2 = [];
|
|
@@ -139,12 +161,10 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
setState(() {
|
|
setState(() {
|
|
|
btList =tempBtList2;
|
|
btList =tempBtList2;
|
|
|
});
|
|
});
|
|
|
- print('设置btList完成');
|
|
|
|
|
String tempStr = '';
|
|
String tempStr = '';
|
|
|
for (int i = 0; i < btList.length; i++) {
|
|
for (int i = 0; i < btList.length; i++) {
|
|
|
tempStr += '${btList[i].name}&';
|
|
tempStr += '${btList[i].name}&';
|
|
|
}
|
|
}
|
|
|
- print('设置临时字符串');
|
|
|
|
|
print(tempStr);
|
|
print(tempStr);
|
|
|
setKey('btList', tempStr);
|
|
setKey('btList', tempStr);
|
|
|
}
|
|
}
|
|
@@ -435,11 +455,13 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
bluetooth.isBTDevice().then((resp) {
|
|
bluetooth.isBTDevice().then((resp) {
|
|
|
if (resp) {
|
|
if (resp) {
|
|
|
bluetooth.isEnableBluetooth().then((bool resp) { //打开蓝牙
|
|
bluetooth.isEnableBluetooth().then((bool resp) { //打开蓝牙
|
|
|
- setState(() {
|
|
|
|
|
- check = true;
|
|
|
|
|
|
|
+ bluetooth.enableBluetooth().then((resp){
|
|
|
|
|
+ setState(() {
|
|
|
|
|
+ check = true;
|
|
|
|
|
+ });
|
|
|
|
|
+ setKey('check', 'true');
|
|
|
|
|
+ bluetooth.scanBT(); //
|
|
|
});
|
|
});
|
|
|
- setKey('check', 'true');
|
|
|
|
|
- bluetooth.scanBT(); //
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -449,6 +471,7 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
setState(() {
|
|
setState(() {
|
|
|
check = false;
|
|
check = false;
|
|
|
btList.clear();
|
|
btList.clear();
|
|
|
|
|
+ btSet.clear();
|
|
|
});
|
|
});
|
|
|
setKey('check', 'false');
|
|
setKey('check', 'false');
|
|
|
}
|
|
}
|
|
@@ -554,11 +577,11 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
),
|
|
),
|
|
|
),
|
|
),
|
|
|
onTap: () {
|
|
onTap: () {
|
|
|
- //bluetooth.connnectBT(btAddress);
|
|
|
|
|
|
|
+ if(btList[index].connectStatus) return;//已连接直接返回
|
|
|
bluetooth.connectBT(btAddress);
|
|
bluetooth.connectBT(btAddress);
|
|
|
setState(() {
|
|
setState(() {
|
|
|
btList[index].showLoadStauts = true;
|
|
btList[index].showLoadStauts = true;
|
|
|
- // publicIndex =
|
|
|
|
|
|
|
+ publicIndex =index;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
},
|
|
},
|