소스 검색

蓝牙扫描

daxu0403 7 년 전
부모
커밋
71fd0aec8d
2개의 변경된 파일64개의 추가작업 그리고 40개의 파일을 삭제
  1. 62 38
      lib/pages/my_page.dart
  2. 2 2
      lib/util/config.dart

+ 62 - 38
lib/pages/my_page.dart

@@ -29,6 +29,8 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
   Station stationObj;
   String name = '物流';
   BluetoothUtils bluetooth = BluetoothUtils();
+  List<String> btList = [];
+  Set<String> btSet = Set();
   List printTypeList = ["全部", "配件商", "修理厂", "司机", "货物", "货物外", "不打印"];
   static
   var printTypeMap = {
@@ -85,7 +87,14 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
   }
 
   onEvent(Object obj) {
-    print(obj.toString());
+    setState(() {
+      if(obj.toString().indexOf('||')!=-1){
+        int index = obj.toString().indexOf('||');
+        String temp = obj.toString().substring(0,index);
+        btSet.add(temp);
+        btList =btSet.toList();
+      }
+    });
   }
 
   onError(Object obj) {
@@ -180,7 +189,7 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
           _passWordWidget(),
           _linkPrint(check),
           _printType(),
-          //_quitWidget(context)
+          _btList()
         ],
       ),
     );
@@ -369,7 +378,8 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
                     value: this.check,
                     activeColor: Colors.blue,
                     onChanged: (bool val) {
-                      bluetooth.isBTDevice().then((resp) {
+                      if(val){
+                        bluetooth.isBTDevice().then((resp) {
                         if (resp) {
                           bluetooth.isEnableBluetooth().then((bool resp) {
                             this.setState(() {
@@ -380,6 +390,15 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
 
                         }
                       });
+                      }else{
+                        bluetooth.disConnnectBT();
+                        setState(() {
+                          this.check = val;
+                          btList.clear();
+                          btSet.clear();
+                        });
+                      }
+                      
                     },
                   )
                 ],
@@ -439,49 +458,54 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
       },
     );
   }
-  Widget _quitWidget(BuildContext context) {
+
+  Widget _btList() {
+    return Container(
+      height: ScreenUtil.getInstance().setHeight(350),
+      padding: EdgeInsets.all(ScreenUtil.getInstance().setHeight(30)),
+      child: ListView.builder(
+        itemCount:btList.length,
+        itemBuilder: (BuildContext context, int index) {
+         
+          return _btItem(btList[index]);
+         
+         
+        },
+      )
+    );
+  }
+
+  Widget _btItem(String name) {
     return InkWell(
-      child: Container(
-        height: ScreenUtil.getInstance().setHeight(90),
-        color: Colors.white,
-        padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setHeight(30), 0, 0, 0),
-        margin: EdgeInsets.only(top: ScreenUtil.getInstance().setHeight(20)),
-        child: Column(
+      child: Padding(
+        padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),
+        child: Row(
+          mainAxisAlignment: MainAxisAlignment.spaceBetween,
           children: < Widget > [
-            Expanded(
-              child: Center(
-                child: Row(
-                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
-                  children: < Widget > [
-                    Text('退出', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
-                    Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1))
-                  ],
-                ),
-              ),
+            Text(name),
+            CircleAvatar(
+              backgroundColor: Colors.grey,
+              radius: 6,
             )
           ],
         )
       ),
-      onTap: () {
-        showDialog < Null > (
-          context: context, //BuildContext对象
-          barrierDismissible: false,
-          builder: (BuildContext context) {
-            return new LoadingDialog( //调用对话框
-              text: '确认退出?', childCallback: (val) {
-                if (val) {
-                  clearKey();
-                  Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) {
-                    return LoginPage();
-                  }));
-                } else {
-                  return;
-                }
-              },
-            );
-          });
+      onTap: (){
+        print('链接');
       },
     );
+  }
 
+  Widget _searchBt(){
+    return InkWell(
+      child: Center(
+        child: Container(
+          width: 160,
+          height: 30,
+          color: Colors.blue,
+          child: Text('扫描中'),
+        ),
+      ),
+    );
   }
 }

+ 2 - 2
lib/util/config.dart

@@ -1,6 +1,6 @@
 class Config{
-  //String baseUrl = "https://logistics.5fire.tech/";
-  String baseUrl='http://192.168.100.11:8866/';
+  String baseUrl = "https://logistics.5fire.tech/";
+  //String baseUrl='http://192.168.100.11:8866/';
   int connectTimeout = 30000;
   int receiveTimeout = 30000;
 }