Bladeren bron

搜索蓝牙数据做缓存

daxu0403 7 jaren geleden
bovenliggende
commit
07a3ad78ef
2 gewijzigde bestanden met toevoegingen van 45 en 21 verwijderingen
  1. 45 18
      lib/pages/my_page.dart
  2. 0 3
      lib/pages/order_taking_page.dart

+ 45 - 18
lib/pages/my_page.dart

@@ -31,7 +31,7 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
   String name = '物流';
   BluetoothUtils bluetooth = BluetoothUtils();
   List < BtInfoObj > btList = [];
-  Set < BtInfoObj > btSet = Set();
+  Set btSet = Set();
   List printTypeList = ["全部", "配件商", "修理厂", "司机", "货物", "货物外", "不打印"];
   static
   var printTypeMap = {
@@ -100,25 +100,52 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
         });
       }
     });
-    // getKey('btList').then((value){
-    //   //print(value);
-    //   if(value!=null && check==true){
-    //     List<BtInfoObj> tempList =json.decode(value);
-    //     setState(() {
-    //       btList=tempList;
-    //     });
-    //   }
-    // });
+    getKey('btList').then((value) {
+      print(value);
+      if (value != '' && check == true) {
+        List tempList = [];
+        for (int i = 0; i < 999; i++) {
+          if (value.indexOf('&') != -1) {
+            int index = value.indexOf('&');
+            tempList.add(value.substring(0, index));
+            value = value.substring(index + 1, value.length);
+          } else {
+            break;
+          }
+        }
+        for (int i = 0; i < tempList.length; i++) {
+          BtInfoObj tempObj = BtInfoObj(name: tempList[i], showLoadStauts: false, connectStatus: false);
+          setState(() {
+            btList.add(tempObj);
+          });
+        }
+      }
+    });
   }
 
+
   onEvent(Object obj) {
+    print('进入onEvent回调${obj}');
     if (obj.toString().indexOf('||') != -1) { //过滤开始搜索和结束搜索
-      BtInfoObj tempObj = BtInfoObj(name: obj.toString(), showLoadStauts: false, connectStatus: false);
-      btSet.add(tempObj);
+      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 = btSet.toList();
+        btList =tempBtList2;
       });
-      //setKey('btList', btList.toString());
+      print('设置btList完成');
+      String tempStr = '';
+      for (int i = 0; i < btList.length; i++) {
+        tempStr += '${btList[i].name}&';
+      }
+      print('设置临时字符串');
+      print(tempStr);
+      setKey('btList', tempStr);
     }
   }
 
@@ -489,21 +516,21 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
     return Container(
       height: ScreenUtil.getInstance().setHeight(350),
       padding: EdgeInsets.all(ScreenUtil.getInstance().setHeight(30)),
-      child: (btList.length > 0 && check==true) ? ListView.builder(
+      child: (btList.length > 0 && check == true) ? ListView.builder(
         itemCount: btList.length,
         itemBuilder: (BuildContext context, int index) {
           return _btItem(btList[index], index);
         },
-      ) : check==true?_searchBt():Center()
+      ) : check == true ? _searchBt() : Center()
     );
   }
 
   Widget _btItem(BtInfoObj obj, int index) {
-    print(obj.name);
+    // print(obj.name);
     int tempIndex = obj.name.indexOf('||');
     String name = obj.name.substring(0, tempIndex);
     String btAddress = obj.name.substring(tempIndex + 2, obj.name.length);
-    print(btAddress);
+    // print(btAddress);
     return InkWell(
       child: Padding(
         padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),

+ 0 - 3
lib/pages/order_taking_page.dart

@@ -316,14 +316,12 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
   }
 
   void switchLine(BuildContext context) { //切换线路
-    print(checkStatusList.toString());
     lineIdStr = '';
     for (int i = 0; i < checkStatusList.length; i++) {
       if (checkStatusList[i]) {
         lineIdStr += lineList[i].id.toString() + ',';
       }
     }
-    print(lineIdStr);
     if (lineIdStr == '') {
       setState(() {
         orderList = [];
@@ -336,7 +334,6 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
     lineIdStr = lineIdStr.substring(0, lineIdStr.length - 1);
 
     if (oldLineIdStr == lineIdStr) return;
-    print('11111');
     setState(() {
       orderList = [];
       hasNextPage = true;