|
|
@@ -31,7 +31,7 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
BluetoothUtils bluetooth = BluetoothUtils();
|
|
|
List < BtInfoObj > btList = [];
|
|
|
Set btSet = Set();
|
|
|
- int publicIndex;
|
|
|
+ bool btLinkStatus = false;
|
|
|
List printTypeList = ["全部", "配件商", "修理厂", "司机", "货物", "货物外", "不打印"];
|
|
|
static
|
|
|
var printTypeMap = {
|
|
|
@@ -115,12 +115,20 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- for (int i = 0; i < tempList.length; i++) {
|
|
|
- BtInfoObj tempObj = BtInfoObj(name: tempList[i], showLoadStauts: false, connectStatus: false);
|
|
|
- setState(() {
|
|
|
- btList.add(tempObj);
|
|
|
- });
|
|
|
- }
|
|
|
+ getKey('checkedBt').then((value){
|
|
|
+ print(value);
|
|
|
+ for (int i = 0; i < tempList.length; i++) {
|
|
|
+ BtInfoObj tempObj;
|
|
|
+ if(value!=null && value==i.toString()){
|
|
|
+ tempObj = BtInfoObj(name: tempList[i], showLoadStauts: false, connectStatus: true);
|
|
|
+ }else{
|
|
|
+ tempObj = BtInfoObj(name: tempList[i], showLoadStauts: false, connectStatus: false);
|
|
|
+ }
|
|
|
+ setState(() {
|
|
|
+ btList.add(tempObj);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -129,44 +137,69 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
onEvent(Object obj) {
|
|
|
print('进入onEvent回调${obj}');
|
|
|
if (obj.toString().indexOf('||') != -1) { //过滤开始搜索和结束搜索
|
|
|
- if(obj.toString().indexOf('CONNECTED')!=-1){
|
|
|
- setState(() {
|
|
|
+ if(obj.toString().indexOf('DISCAONNECTED')!=-1){//当上一个连接断开后,将连接的蓝牙动画状态关闭
|
|
|
+ print('**************DISCAONNECTED***************');
|
|
|
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;
|
|
|
+ print(btList[i].connectStatus);
|
|
|
+ if(btList[i].connectStatus==true){
|
|
|
+ setState(() {
|
|
|
+ btList[i].showLoadStauts = false;
|
|
|
+ btLinkStatus = true;
|
|
|
+ });
|
|
|
+ setKey('checkedBt', i);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+ String tempStr = '';
|
|
|
+ for (int i = 0; i < btList.length; i++) {
|
|
|
+ tempStr += '${btList[i].name}&';
|
|
|
+ }
|
|
|
+ setKey('btList', tempStr);
|
|
|
+ return;
|
|
|
+ }else
|
|
|
+ if(obj.toString().indexOf('CONNECTED')!=-1){//连接回调成功,将连接状态改为蓝色,单扔显示连接动画
|
|
|
+ setState(() {
|
|
|
+ for(int i=0;i<btList.length;i++){
|
|
|
+ if(obj.toString().indexOf(btList[i].name)!=-1){
|
|
|
+ if(btLinkStatus){
|
|
|
+ btList[i].connectStatus = true;
|
|
|
+ }else{
|
|
|
+ btList[i].showLoadStauts = false;
|
|
|
+ btList[i].connectStatus = true;
|
|
|
+ btLinkStatus = true;
|
|
|
+ }
|
|
|
+ setKey('checkedBt', i.toString());
|
|
|
+ }else{
|
|
|
+ btList[i].showLoadStauts = false;
|
|
|
+ btList[i].connectStatus = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String tempStr = '';
|
|
|
+ for (int i = 0; i < btList.length; i++) {
|
|
|
+ tempStr += '${btList[i].name}&';
|
|
|
+ }
|
|
|
+ setKey('btList', tempStr);
|
|
|
+ return;
|
|
|
});
|
|
|
- String tempStr = '';
|
|
|
- for (int i = 0; i < btList.length; i++) {
|
|
|
- tempStr += '${btList[i].name}&';
|
|
|
- }
|
|
|
- print(tempStr);
|
|
|
- setKey('btList', tempStr);
|
|
|
- return;
|
|
|
- }
|
|
|
- btSet.add(obj.toString()); //去重
|
|
|
- List tempBtList = btSet.toList();
|
|
|
- List<BtInfoObj> tempBtList2 = [];
|
|
|
- for (int i = 0; i < tempBtList.length; i++) {
|
|
|
- tempBtList2.add(
|
|
|
- BtInfoObj(name: tempBtList[i], showLoadStauts: false, connectStatus: false)
|
|
|
- );
|
|
|
- }
|
|
|
- setState(() {
|
|
|
- btList =tempBtList2;
|
|
|
- });
|
|
|
- String tempStr = '';
|
|
|
- for (int i = 0; i < btList.length; i++) {
|
|
|
- tempStr += '${btList[i].name}&';
|
|
|
+
|
|
|
+ }else{
|
|
|
+ btSet.add(obj.toString()); //去重
|
|
|
+ List tempBtList = btSet.toList();
|
|
|
+ List<BtInfoObj> tempBtList2 = [];
|
|
|
+ for (int i = 0; i < tempBtList.length; i++) {
|
|
|
+ tempBtList2.add(
|
|
|
+ BtInfoObj(name: tempBtList[i], showLoadStauts: false, connectStatus: false)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ setState(() {
|
|
|
+ btList =tempBtList2;
|
|
|
+ });
|
|
|
+ String tempStr = '';
|
|
|
+ for (int i = 0; i < btList.length; i++) {
|
|
|
+ tempStr += '${btList[i].name}&';
|
|
|
+ }
|
|
|
+ print(tempStr);
|
|
|
+ setKey('btList', tempStr);
|
|
|
}
|
|
|
- print(tempStr);
|
|
|
- setKey('btList', tempStr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -458,6 +491,7 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
bluetooth.enableBluetooth().then((resp){
|
|
|
setState(() {
|
|
|
check = true;
|
|
|
+ btLinkStatus = false;
|
|
|
});
|
|
|
setKey('check', 'true');
|
|
|
bluetooth.scanBT(); //
|
|
|
@@ -564,8 +598,8 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
children: < Widget > [
|
|
|
Text(name),
|
|
|
obj.showLoadStauts ? SizedBox(
|
|
|
- width: ScreenUtil.getInstance().setWidth(35),
|
|
|
- height: ScreenUtil.getInstance().setHeight(35),
|
|
|
+ width: ScreenUtil.getInstance().setWidth(30),
|
|
|
+ height: ScreenUtil.getInstance().setHeight(30),
|
|
|
child: Image.asset('lib/images/loading.gif'),
|
|
|
) :
|
|
|
CircleAvatar(
|
|
|
@@ -578,10 +612,14 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
),
|
|
|
onTap: () {
|
|
|
if(btList[index].connectStatus) return;//已连接直接返回
|
|
|
+ for(int i=0;i<btList.length;i++){
|
|
|
+ if(btList[i].showLoadStauts==true){//任何一个蓝牙连接在加载中就直接返回
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
bluetooth.connectBT(btAddress);
|
|
|
setState(() {
|
|
|
btList[index].showLoadStauts = true;
|
|
|
- publicIndex =index;
|
|
|
});
|
|
|
|
|
|
},
|