daxu0403 há 7 anos atrás
pai
commit
7d8fee0e34

BIN
android/.gradle/4.10.2/fileHashes/fileHashes.bin


BIN
android/.gradle/4.10.2/fileHashes/fileHashes.lock


BIN
android/.gradle/4.10.2/taskHistory/taskHistory.bin


BIN
android/.gradle/4.10.2/taskHistory/taskHistory.lock


BIN
android/.gradle/buildOutputCleanup/buildOutputCleanup.lock


+ 4 - 20
android/.idea/workspace.xml

@@ -31,8 +31,8 @@
       <file leaf-file-name="MainActivity.java" pinned="false" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/app/src/main/java/com/example/logisticsclient/MainActivity.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="279">
-              <caret line="162" column="32" lean-forward="true" selection-start-line="162" selection-start-column="32" selection-end-line="162" selection-end-column="32" />
+            <state relative-caret-position="309">
+              <caret line="164" column="9" lean-forward="true" selection-start-line="164" selection-start-column="9" selection-end-line="164" selection-end-column="9" />
               <folding>
                 <element signature="imports" expanded="true" />
                 <element signature="e#1612#3527#0" expanded="true" />
@@ -8373,21 +8373,6 @@
               <item name="android" type="1abcf292:AndroidViewProjectNode" />
               <item name="app" type="feadf853:AndroidModuleNode" />
             </path>
-            <path>
-              <item name="android" type="1abcf292:AndroidViewProjectNode" />
-              <item name="app" type="feadf853:AndroidModuleNode" />
-              <item name="java" type="edd41e36:AndroidSourceTypeNode" />
-            </path>
-            <path>
-              <item name="android" type="1abcf292:AndroidViewProjectNode" />
-              <item name="app" type="feadf853:AndroidModuleNode" />
-              <item name="java" type="edd41e36:AndroidSourceTypeNode" />
-              <item name="logisticsclient" type="cbb59c9e:AndroidPsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="android" type="1abcf292:AndroidViewProjectNode" />
-              <item name="Gradle Scripts" type="ae0cef3a:AndroidBuildScriptsGroupNode" />
-            </path>
           </expand>
           <select />
         </subPane>
@@ -8529,7 +8514,6 @@
   </component>
   <component name="ToolWindowManager">
     <frame x="20" y="43" width="1400" height="837" extended-state="0" />
-    <editor active="true" />
     <layout>
       <window_info anchor="bottom" id="TODO" order="6" />
       <window_info anchor="bottom" id="Android Profiler" show_stripe_button="false" />
@@ -8590,8 +8574,8 @@
     </entry>
     <entry file="file://$PROJECT_DIR$/app/src/main/java/com/example/logisticsclient/MainActivity.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="279">
-          <caret line="162" column="32" lean-forward="true" selection-start-line="162" selection-start-column="32" selection-end-line="162" selection-end-column="32" />
+        <state relative-caret-position="309">
+          <caret line="164" column="9" lean-forward="true" selection-start-line="164" selection-start-column="9" selection-end-line="164" selection-end-column="9" />
           <folding>
             <element signature="imports" expanded="true" />
             <element signature="e#1612#3527#0" expanded="true" />

+ 19 - 4
android/app/src/main/java/com/example/logisticsclient/MainActivity.java

@@ -183,11 +183,26 @@ public class MainActivity extends FlutterActivity {
    * @return
    */
   private boolean isEnableBluetooth() {
-    System.out.println("**********************************BT*******************************");
-    mBluetoothAdapter.enable();
+        System.out.println("**********************************BT*******************************");
+       if (Build.VERSION.SDK_INT >= 23) {
+           //校验是否已具有模糊定位权限
+           if (ContextCompat.checkSelfPermission(MainActivity.this,
+                   android.Manifest.permission.ACCESS_COARSE_LOCATION)
+                   != PackageManager.PERMISSION_GRANTED) {
+               ActivityCompat.requestPermissions(MainActivity.this,
+                       new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION},
+                       100);
+           }
+       }
+
+        if (mBluetoothAdapter.isEnabled()) {
+            return true;
+        }
 
-    return mBluetoothAdapter.isEnabled();
-  }
+        mBluetoothAdapter.enable();
+
+        return mBluetoothAdapter.isEnabled();
+    }
 
 
   /**

+ 11 - 3
lib/pages/my_page.dart

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
 import 'package:flutter_screenutil/flutter_screenutil.dart';
 import 'my_page/revise_password_page.dart';
 import 'package:flutter_picker/flutter_picker.dart';
+import '../util/bluetooth_utils.dart';
 import '../showDialog.dart';
 import '../login_page.dart';
 import '../util/api.dart';
@@ -27,6 +28,8 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
   List < String > stationList = [];
   Station stationObj;
   String name = '物流';
+   BluetoothUtils bluetooth =  BluetoothUtils();
+
   @override
   bool get wantKeepAlive => true;
 
@@ -283,10 +286,15 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
                     value: this.check,
                     activeColor: Colors.blue,
                     onChanged: (bool val) {
-                      this.setState(() {
-                        this.check = val;
+                      bluetooth.isEnableBluetooth().then((bool resp){
+                         this.setState(() {
+                            this.check = resp;
+                          });
                       });
-                      print('check:${this.check}');
+
+                      
+                     
+                      //print('check:${this.check}');
                     },
                   )
                 ],

+ 81 - 0
lib/util/bluetooth_utils.dart

@@ -0,0 +1,81 @@
+import 'package:flutter/services.dart';
+
+class BluetoothUtils {
+  static const mChannel = const MethodChannel('io.fivefire/method_channel');
+  static const eChannel = const EventChannel("io.fivefire/event_channel");
+
+  Future<bool> isBTDevice() async {//检查是否有蓝牙设备
+    try {
+      return await mChannel.invokeMethod('isBTDevice');
+    } on PlatformException catch (e) {
+      print("$e");
+      return false;
+    }
+  }
+
+  Future<bool> isEnableBluetooth() async {//打开蓝牙
+    try {
+      return await mChannel.invokeMethod('isEnableBluetooth');
+    } on PlatformException catch (e) {
+      print("$e");
+      return false;
+    }
+  }
+
+  Future scanBT() async {
+    try {
+      return await mChannel.invokeMethod('scanBT');
+    } on PlatformException catch (e) {
+      print("$e");
+    }
+  }
+
+  Future<Null> connnectBT(String address) async {
+    try {
+      Map<String, String> map = {"address": address};
+
+      return await mChannel.invokeMethod('connnectBT', map);
+    } on PlatformException catch (e) {
+      print("$e");
+    }
+  }
+
+  Future disConnnectBT() async {
+    try {
+    
+
+      return await mChannel.invokeMethod('disConnectBT');
+    } on PlatformException catch (e) {
+      print("$e");
+    }
+  }
+
+  Future printOrder(Map<String,String> pum,int type)async{
+     try {
+      Map<String,Object> map = {"pum":pum,"type": type};
+
+      return await mChannel.invokeMethod('printOrder', map);
+    } on PlatformException catch (e) {
+      print("$e");
+    }
+
+  }
+
+   EventChannel getEchannel(){
+     return eChannel;
+
+  }
+
+//   void initState() {
+//     eChannel.receiveBroadcastStream().listen(onEvent, onError: onError);
+//   }
+
+//    onEvent(Object obj){
+//     print(obj);
+   
+//   }
+
+//    onError(Object obj) {}
+
+   
+}