├── .gitignore ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── android ├── .gitignore ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties ├── libs │ └── gprintersdkv2.jar ├── settings.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── tablemi │ └── flutter_bluetooth_basic │ ├── Constant.java │ ├── DeviceConnFactoryManager.java │ ├── FlutterBluetoothBasicPlugin.java │ ├── PrinterCommand.java │ ├── ThreadFactoryBuilder.java │ └── ThreadPool.java ├── example ├── .gitignore ├── .metadata ├── README.md ├── android │ ├── .gitignore │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── tablemi │ │ │ │ │ └── flutter_bluetooth_basic_example │ │ │ │ │ └── MainActivity.java │ │ │ └── res │ │ │ │ ├── drawable │ │ │ │ └── launch_background.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ └── values │ │ │ │ └── styles.xml │ │ │ └── profile │ │ │ └── AndroidManifest.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ └── settings.gradle ├── ios │ ├── .gitignore │ ├── Flutter │ │ ├── AppFrameworkInfo.plist │ │ ├── Debug.xcconfig │ │ └── Release.xcconfig │ ├── Podfile │ ├── Podfile.lock │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── Runner │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ ├── Icon-App-20x20@1x.png │ │ │ ├── Icon-App-20x20@2x.png │ │ │ ├── Icon-App-20x20@3x.png │ │ │ ├── Icon-App-29x29@1x.png │ │ │ ├── Icon-App-29x29@2x.png │ │ │ ├── Icon-App-29x29@3x.png │ │ │ ├── Icon-App-40x40@1x.png │ │ │ ├── Icon-App-40x40@2x.png │ │ │ ├── Icon-App-40x40@3x.png │ │ │ ├── Icon-App-60x60@2x.png │ │ │ ├── Icon-App-60x60@3x.png │ │ │ ├── Icon-App-76x76@1x.png │ │ │ ├── Icon-App-76x76@2x.png │ │ │ └── Icon-App-83.5x83.5@2x.png │ │ └── LaunchImage.imageset │ │ │ ├── Contents.json │ │ │ ├── LaunchImage.png │ │ │ ├── LaunchImage@2x.png │ │ │ ├── LaunchImage@3x.png │ │ │ └── README.md │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── main.m ├── lib │ └── main.dart ├── pubspec.lock ├── pubspec.yaml └── test │ └── widget_test.dart ├── flutter_bluetooth_basic.iml ├── ios ├── .gitignore ├── Assets │ └── .gitkeep ├── Classes │ ├── BLEConnecter.h │ ├── Connecter.h │ ├── ConnecterBlock.h │ ├── ConnecterManager.h │ ├── ConnecterManager.m │ ├── EthernetConnecter.h │ ├── FlutterBluetoothBasicPlugin.h │ └── FlutterBluetoothBasicPlugin.m ├── flutter_bluetooth_basic.podspec └── libGSDK.a ├── lib ├── flutter_bluetooth_basic.dart └── src │ ├── bluetooth_device.dart │ ├── bluetooth_device.g.dart │ └── bluetooth_manager.dart ├── pubspec.lock ├── pubspec.yaml └── test └── flutter_bluetooth_basic_test.dart /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ 8 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 27321ebbad34b0a3fafe99fac037102196d655ff 8 | channel: stable 9 | 10 | project_type: plugin 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.7 2 | 3 | - Fix null Exception at _$BluetoothDeviceFromJson and BluetoothManager.state (PR https://github.com/andrey-ushakov/flutter_bluetooth_basic/pull/26). 4 | 5 | ## 0.1.6 6 | 7 | - Null-Safety 8 | 9 | ## 0.1.5 10 | 11 | - Updated pubspec.yaml 12 | 13 | ## 0.1.4 14 | 15 | - Android: start scan bug fixed (error handling) 16 | 17 | ## 0.1.3 18 | 19 | - Updated README.md 20 | 21 | ## 0.1.2 22 | 23 | - Added Android support 24 | 25 | ## 0.0.1 26 | 27 | - iOS only support 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020 Andrey U. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | * Neither the name of the copyright holder nor the names of its 14 | contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flutter_bluetooth_basic 2 | 3 | Flutter plugin that allows to find bluetooth devices & send raw bytes data. 4 | Supports both Android and iOS. 5 | 6 | Inspired by [bluetooth_print](https://github.com/thon-ju/bluetooth_print). 7 | 8 | 9 | ## Main Features 10 | * Android and iOS support 11 | * Scan for bluetooth devices 12 | * Send raw `List bytes` data to a device 13 | 14 | 15 | ## Getting Started 16 | 17 | For a full example please check */example* folder. Here are only the most important parts of the code to illustrate how to use the library. 18 | 19 | ```dart 20 | BluetoothManager bluetoothManager = BluetoothManager.instance; 21 | BluetoothDevice _device; 22 | 23 | bluetoothManager.startScan(timeout: Duration(seconds: 4)); 24 | bluetoothManager.state.listen((state) { 25 | switch (state) { 26 | case BluetoothManager.CONNECTED: 27 | // ... 28 | break; 29 | case BluetoothManager.DISCONNECTED: 30 | // ... 31 | break; 32 | default: 33 | break; 34 | } 35 | }); 36 | // bluetoothManager.scanResults is a Stream> sending the found devices. 37 | 38 | // _device = 39 | 40 | await bluetoothManager.connect(_device); 41 | 42 | List bytes = latin1.encode('Hello world!\n').toList(); 43 | await bluetoothManager.writeData(bytes); 44 | 45 | await bluetoothManager.disconnect(); 46 | ``` 47 | 48 | ## See also 49 | * Example of usage in a project: [esc_pos_printer](https://github.com/andrey-ushakov/esc_pos_printer) 50 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | group 'com.tablemi.flutter_bluetooth_basic' 2 | version '1.0' 3 | 4 | buildscript { 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.5.0' 12 | } 13 | } 14 | 15 | rootProject.allprojects { 16 | repositories { 17 | google() 18 | jcenter() 19 | } 20 | } 21 | 22 | apply plugin: 'com.android.library' 23 | 24 | android { 25 | compileSdkVersion 28 26 | 27 | defaultConfig { 28 | minSdkVersion 21 29 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 30 | } 31 | lintOptions { 32 | disable 'InvalidPackage' 33 | } 34 | } 35 | 36 | dependencies { 37 | implementation files('libs/gprintersdkv2.jar') 38 | } 39 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.enableR8=true 3 | android.useAndroidX=true 4 | android.enableJetifier=true 5 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip 6 | -------------------------------------------------------------------------------- /android/libs/gprintersdkv2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/android/libs/gprintersdkv2.jar -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'flutter_bluetooth_basic' 2 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /android/src/main/java/com/tablemi/flutter_bluetooth_basic/Constant.java: -------------------------------------------------------------------------------- 1 | package com.tablemi.flutter_bluetooth_basic; 2 | 3 | public class Constant { 4 | public static final int abnormal_Disconnection = 0x011; // Abnormal disconnection 5 | } -------------------------------------------------------------------------------- /android/src/main/java/com/tablemi/flutter_bluetooth_basic/DeviceConnFactoryManager.java: -------------------------------------------------------------------------------- 1 | package com.tablemi.flutter_bluetooth_basic; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.hardware.usb.UsbDevice; 6 | import android.os.Bundle; 7 | import android.os.Handler; 8 | import android.os.Message; 9 | import android.util.Log; 10 | import com.gprinter.io.*; 11 | 12 | import java.io.IOException; 13 | import java.util.Vector; 14 | import java.util.concurrent.ScheduledExecutorService; 15 | import java.util.concurrent.ScheduledThreadPoolExecutor; 16 | import java.util.concurrent.TimeUnit; 17 | 18 | public class DeviceConnFactoryManager { 19 | 20 | public PortManager mPort; 21 | 22 | private static final String TAG = DeviceConnFactoryManager.class.getSimpleName(); 23 | 24 | public CONN_METHOD connMethod; 25 | 26 | private String ip; 27 | 28 | private int port; 29 | 30 | private String macAddress; 31 | 32 | private UsbDevice mUsbDevice; 33 | 34 | private Context mContext; 35 | 36 | private String serialPortPath; 37 | 38 | private int baudrate; 39 | 40 | private int id; 41 | 42 | private static DeviceConnFactoryManager[] deviceConnFactoryManagers = new DeviceConnFactoryManager[4]; 43 | 44 | private boolean isOpenPort; 45 | /** 46 | * ESC查询打印机实时状态指令 // ESC query printer real-time status instruction 47 | */ 48 | private byte[] esc = {0x10, 0x04, 0x02}; 49 | 50 | /** 51 | * ESC查询打印机实时状态 缺纸状态 52 | */ 53 | private static final int ESC_STATE_PAPER_ERR = 0x20; 54 | 55 | /** 56 | * ESC指令查询打印机实时状态 打印机开盖状态 57 | */ 58 | private static final int ESC_STATE_COVER_OPEN = 0x04; 59 | 60 | /** 61 | * ESC指令查询打印机实时状态 打印机报错状态 62 | */ 63 | private static final int ESC_STATE_ERR_OCCURS = 0x40; 64 | 65 | /** 66 | * TSC查询打印机状态指令 67 | */ 68 | private byte[] tsc = {0x1b, '!', '?'}; 69 | 70 | /** 71 | * TSC指令查询打印机实时状态 打印机缺纸状态 72 | */ 73 | private static final int TSC_STATE_PAPER_ERR = 0x04; 74 | 75 | /** 76 | * TSC指令查询打印机实时状态 打印机开盖状态 77 | */ 78 | private static final int TSC_STATE_COVER_OPEN = 0x01; 79 | 80 | /** 81 | * TSC指令查询打印机实时状态 打印机出错状态 82 | */ 83 | private static final int TSC_STATE_ERR_OCCURS = 0x80; 84 | 85 | private byte[] cpcl={0x1b,0x68}; 86 | 87 | /** 88 | * CPCL指令查询打印机实时状态 打印机缺纸状态 89 | */ 90 | private static final int CPCL_STATE_PAPER_ERR = 0x01; 91 | /** 92 | * CPCL指令查询打印机实时状态 打印机开盖状态 93 | */ 94 | private static final int CPCL_STATE_COVER_OPEN = 0x02; 95 | 96 | private byte[] sendCommand; 97 | /** 98 | * 判断打印机所使用指令是否是ESC指令 99 | */ 100 | private PrinterCommand currentPrinterCommand; 101 | public static final byte FLAG = 0x10; 102 | private static final int READ_DATA = 10000; 103 | private static final int DEFAUIT_COMMAND=20000; 104 | private static final String READ_DATA_CNT = "read_data_cnt"; 105 | private static final String READ_BUFFER_ARRAY = "read_buffer_array"; 106 | public static final String ACTION_CONN_STATE = "action_connect_state"; 107 | public static final String ACTION_QUERY_PRINTER_STATE = "action_query_printer_state"; 108 | public static final String STATE = "state"; 109 | public static final String DEVICE_ID = "id"; 110 | public static final int CONN_STATE_DISCONNECT = 0x90; 111 | public static final int CONN_STATE_CONNECTING = CONN_STATE_DISCONNECT << 1; 112 | public static final int CONN_STATE_FAILED = CONN_STATE_DISCONNECT << 2; 113 | public static final int CONN_STATE_CONNECTED = CONN_STATE_DISCONNECT << 3; 114 | public PrinterReader reader; 115 | private int queryPrinterCommandFlag; 116 | private final int ESC = 1; 117 | private final int TSC = 3; 118 | private final int CPCL = 2; 119 | public enum CONN_METHOD { 120 | //蓝牙连接 121 | BLUETOOTH("BLUETOOTH"), 122 | //USB连接 123 | USB("USB"), 124 | //wifi连接 125 | WIFI("WIFI"), 126 | //串口连接 127 | SERIAL_PORT("SERIAL_PORT"); 128 | 129 | private String name; 130 | 131 | private CONN_METHOD(String name) { 132 | this.name = name; 133 | } 134 | 135 | @Override 136 | public String toString() { 137 | return this.name; 138 | } 139 | } 140 | 141 | public static DeviceConnFactoryManager[] getDeviceConnFactoryManagers() { 142 | return deviceConnFactoryManagers; 143 | } 144 | 145 | /** 146 | * 打开端口 147 | * 148 | * @return 149 | */ 150 | public void openPort() { 151 | deviceConnFactoryManagers[id].isOpenPort = false; 152 | 153 | switch (deviceConnFactoryManagers[id].connMethod) { 154 | case BLUETOOTH: 155 | mPort = new BluetoothPort(macAddress); 156 | isOpenPort = deviceConnFactoryManagers[id].mPort.openPort(); 157 | break; 158 | case USB: 159 | mPort = new UsbPort(mContext, mUsbDevice); 160 | isOpenPort = mPort.openPort(); 161 | break; 162 | case WIFI: 163 | mPort = new EthernetPort(ip, port); 164 | isOpenPort = mPort.openPort(); 165 | break; 166 | case SERIAL_PORT: 167 | mPort = new SerialPort(serialPortPath, baudrate, 0); 168 | isOpenPort = mPort.openPort(); 169 | break; 170 | default: 171 | break; 172 | } 173 | 174 | //端口打开成功后,检查连接打印机所使用的打印机指令ESC、TSC 175 | if (isOpenPort) { 176 | queryCommand(); 177 | } else { 178 | if (this.mPort != null) { 179 | this.mPort=null; 180 | } 181 | 182 | } 183 | } 184 | 185 | /** 186 | * 查询当前连接打印机所使用打印机指令(ESC(EscCommand.java)、TSC(LabelCommand.java)) 187 | */ 188 | private void queryCommand() { 189 | //开启读取打印机返回数据线程 190 | reader = new PrinterReader(); 191 | reader.start(); //读取数据线程 192 | //查询打印机所使用指令 193 | queryPrinterCommand(); //小票机连接不上 注释这行,添加下面那三行代码。使用ESC指令 194 | 195 | } 196 | 197 | /** 198 | * 获取端口连接方式 199 | * 200 | * @return 201 | */ 202 | public CONN_METHOD getConnMethod() { 203 | return connMethod; 204 | } 205 | 206 | /** 207 | * Get port open status (true open, false not open) 208 | * 209 | * @return 210 | */ 211 | public boolean getConnState() { 212 | return isOpenPort; 213 | } 214 | 215 | /** 216 | * 获取连接蓝牙的物理地址 217 | * 218 | * @return 219 | */ 220 | public String getMacAddress() { 221 | return macAddress; 222 | } 223 | 224 | /** 225 | * 获取连接网口端口号 226 | * 227 | * @return 228 | */ 229 | public int getPort() { 230 | return port; 231 | } 232 | 233 | /** 234 | * 获取连接网口的IP 235 | * 236 | * @return 237 | */ 238 | public String getIp() { 239 | return ip; 240 | } 241 | 242 | /** 243 | * 获取连接的USB设备信息 244 | * 245 | * @return 246 | */ 247 | public UsbDevice usbDevice() { 248 | return mUsbDevice; 249 | } 250 | 251 | /** 252 | * 关闭端口 253 | */ 254 | public void closePort(int id) { 255 | if (this.mPort != null) { 256 | if(reader!=null) { 257 | reader.cancel(); 258 | reader = null; 259 | } 260 | boolean b= this.mPort.closePort(); 261 | if(b) { 262 | this.mPort=null; 263 | isOpenPort = false; 264 | currentPrinterCommand = null; 265 | } 266 | } 267 | 268 | } 269 | 270 | /** 271 | * 获取串口号 272 | * 273 | * @return 274 | */ 275 | public String getSerialPortPath() { 276 | return serialPortPath; 277 | } 278 | 279 | /** 280 | * 获取波特率 281 | * 282 | * @return 283 | */ 284 | public int getBaudrate() { 285 | return baudrate; 286 | } 287 | 288 | public static void closeAllPort() { 289 | for (DeviceConnFactoryManager deviceConnFactoryManager : deviceConnFactoryManagers) { 290 | if (deviceConnFactoryManager != null) { 291 | Log.e(TAG, "cloaseAllPort() id -> " + deviceConnFactoryManager.id); 292 | deviceConnFactoryManager.closePort(deviceConnFactoryManager.id); 293 | deviceConnFactoryManagers[deviceConnFactoryManager.id] = null; 294 | } 295 | } 296 | } 297 | 298 | private DeviceConnFactoryManager(Build build) { 299 | this.connMethod = build.connMethod; 300 | this.macAddress = build.macAddress; 301 | this.port = build.port; 302 | this.ip = build.ip; 303 | this.mUsbDevice = build.usbDevice; 304 | this.mContext = build.context; 305 | this.serialPortPath = build.serialPortPath; 306 | this.baudrate = build.baudrate; 307 | this.id = build.id; 308 | deviceConnFactoryManagers[id] = this; 309 | } 310 | 311 | /** 312 | * 获取当前打印机指令 313 | * 314 | * @return PrinterCommand 315 | */ 316 | public PrinterCommand getCurrentPrinterCommand() { 317 | return deviceConnFactoryManagers[id].currentPrinterCommand; 318 | } 319 | 320 | public static final class Build { 321 | private String ip; 322 | private String macAddress; 323 | private UsbDevice usbDevice; 324 | private int port; 325 | private CONN_METHOD connMethod; 326 | private Context context; 327 | private String serialPortPath; 328 | private int baudrate; 329 | private int id; 330 | 331 | public DeviceConnFactoryManager.Build setIp(String ip) { 332 | this.ip = ip; 333 | return this; 334 | } 335 | 336 | public DeviceConnFactoryManager.Build setMacAddress(String macAddress) { 337 | this.macAddress = macAddress; 338 | return this; 339 | } 340 | 341 | public DeviceConnFactoryManager.Build setUsbDevice(UsbDevice usbDevice) { 342 | this.usbDevice = usbDevice; 343 | return this; 344 | } 345 | 346 | public DeviceConnFactoryManager.Build setPort(int port) { 347 | this.port = port; 348 | return this; 349 | } 350 | 351 | public DeviceConnFactoryManager.Build setConnMethod(CONN_METHOD connMethod) { 352 | this.connMethod = connMethod; 353 | return this; 354 | } 355 | 356 | public DeviceConnFactoryManager.Build setContext(Context context) { 357 | this.context = context; 358 | return this; 359 | } 360 | 361 | public DeviceConnFactoryManager.Build setId(int id) { 362 | this.id = id; 363 | return this; 364 | } 365 | 366 | public DeviceConnFactoryManager.Build setSerialPort(String serialPortPath) { 367 | this.serialPortPath = serialPortPath; 368 | return this; 369 | } 370 | 371 | public DeviceConnFactoryManager.Build setBaudrate(int baudrate) { 372 | this.baudrate = baudrate; 373 | return this; 374 | } 375 | 376 | public DeviceConnFactoryManager build() { 377 | return new DeviceConnFactoryManager(this); 378 | } 379 | } 380 | 381 | public void sendDataImmediately(final Vector data) { 382 | if (this.mPort == null) { 383 | return; 384 | } 385 | try { 386 | this.mPort.writeDataImmediately(data, 0, data.size()); 387 | } catch (Exception e) { 388 | // Abort Send 389 | mHandler.obtainMessage(Constant.abnormal_Disconnection).sendToTarget(); 390 | e.printStackTrace(); 391 | 392 | } 393 | } 394 | public void sendByteDataImmediately(final byte [] data) { 395 | if (this.mPort == null) { 396 | return; 397 | }else { 398 | Vector datas = new Vector<>(); 399 | for(int i = 0; i < data.length; ++i) { 400 | datas.add(Byte.valueOf(data[i])); 401 | } 402 | try { 403 | this.mPort.writeDataImmediately(datas, 0, datas.size()); 404 | } catch (IOException e) { 405 | // Abort Send 406 | e.printStackTrace(); 407 | mHandler.obtainMessage(Constant.abnormal_Disconnection).sendToTarget(); 408 | } 409 | } 410 | } 411 | public int readDataImmediately(byte[] buffer){ 412 | int r = 0; 413 | if (this.mPort == null) { 414 | return r; 415 | } 416 | 417 | try { 418 | r = this.mPort.readData(buffer); 419 | } catch (IOException e) { 420 | 421 | } 422 | 423 | return r; 424 | } 425 | 426 | /** 427 | * 查询打印机当前使用的指令(ESC、CPCL、TSC、) 428 | */ 429 | private void queryPrinterCommand() { 430 | queryPrinterCommandFlag = ESC; 431 | ThreadPool.getInstantiation().addSerialTask(new Runnable() { 432 | @Override 433 | public void run() { 434 | //开启计时器,隔2000毫秒没有没返回值时发送查询打印机状态指令,先发票据,面单,标签 435 | final ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder("Timer"); 436 | final ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(1, threadFactoryBuilder); 437 | scheduledExecutorService.scheduleAtFixedRate(threadFactoryBuilder.newThread(new Runnable() { 438 | @Override 439 | public void run() { 440 | if (currentPrinterCommand == null && queryPrinterCommandFlag > TSC) { 441 | if (reader != null) {//三种状态,查询无返回值,发送连接失败广播 442 | reader.cancel(); 443 | mPort.closePort(); 444 | isOpenPort = false; 445 | 446 | scheduledExecutorService.shutdown(); 447 | } 448 | } 449 | if (currentPrinterCommand != null) { 450 | if (scheduledExecutorService != null && !scheduledExecutorService.isShutdown()) { 451 | scheduledExecutorService.shutdown(); 452 | } 453 | return; 454 | } 455 | switch (queryPrinterCommandFlag) { 456 | case ESC: 457 | //发送ESC查询打印机状态指令 458 | sendCommand = esc; 459 | break; 460 | case TSC: 461 | //发送ESC查询打印机状态指令 462 | sendCommand = tsc; 463 | break; 464 | case CPCL: 465 | //发送CPCL查询打印机状态指令 466 | sendCommand = cpcl; 467 | break; 468 | default: 469 | break; 470 | } 471 | Vector data = new Vector<>(sendCommand.length); 472 | for (int i = 0; i < sendCommand.length; i++) { 473 | data.add(sendCommand[i]); 474 | } 475 | sendDataImmediately(data); 476 | queryPrinterCommandFlag++; 477 | } 478 | }), 1500, 1500, TimeUnit.MILLISECONDS); 479 | } 480 | }); 481 | } 482 | 483 | class PrinterReader extends Thread { 484 | private boolean isRun = false; 485 | 486 | private byte[] buffer = new byte[100]; 487 | 488 | public PrinterReader() { 489 | isRun = true; 490 | } 491 | 492 | @Override 493 | public void run() { 494 | try { 495 | while (isRun) { 496 | //读取打印机返回信息,打印机没有返回纸返回-1 497 | Log.e(TAG,"wait read "); 498 | int len = readDataImmediately(buffer); 499 | Log.e(TAG," read "+len); 500 | if (len > 0) { 501 | Message message = Message.obtain(); 502 | message.what = READ_DATA; 503 | Bundle bundle = new Bundle(); 504 | bundle.putInt(READ_DATA_CNT, len); //数据长度 505 | bundle.putByteArray(READ_BUFFER_ARRAY, buffer); //数据 506 | message.setData(bundle); 507 | mHandler.sendMessage(message); 508 | } 509 | } 510 | } catch (Exception e) {//异常断开 511 | if (deviceConnFactoryManagers[id] != null) { 512 | closePort(id); 513 | mHandler.obtainMessage(Constant.abnormal_Disconnection).sendToTarget(); 514 | } 515 | } 516 | } 517 | 518 | public void cancel() { 519 | isRun = false; 520 | } 521 | } 522 | 523 | private Handler mHandler = new Handler() { 524 | @Override 525 | public void handleMessage(Message msg) { 526 | switch (msg.what) { 527 | case Constant.abnormal_Disconnection://异常断开连接 528 | Log.d(TAG, "abnormal disconnection"); 529 | sendStateBroadcast(Constant.abnormal_Disconnection); 530 | break; 531 | case DEFAUIT_COMMAND://默认模式 532 | 533 | break; 534 | case READ_DATA: 535 | int cnt = msg.getData().getInt(READ_DATA_CNT); //数据长度 >0; 536 | byte[] buffer = msg.getData().getByteArray(READ_BUFFER_ARRAY); //数据 537 | //这里只对查询状态返回值做处理,其它返回值可参考编程手册来解析 538 | if (buffer == null) { 539 | return; 540 | } 541 | int result = judgeResponseType(buffer[0]); //数据右移 542 | String status = ""; 543 | if (sendCommand == esc) { 544 | //设置当前打印机模式为ESC模式 545 | if (currentPrinterCommand == null) { 546 | currentPrinterCommand = PrinterCommand.ESC; 547 | sendStateBroadcast(CONN_STATE_CONNECTED); 548 | } else {//查询打印机状态 549 | if (result == 0) {//打印机状态查询 550 | Intent intent = new Intent(ACTION_QUERY_PRINTER_STATE); 551 | intent.putExtra(DEVICE_ID, id); 552 | if(mContext!=null){ 553 | mContext.sendBroadcast(intent); 554 | } 555 | } else if (result == 1) {//查询打印机实时状态 556 | if ((buffer[0] & ESC_STATE_PAPER_ERR) > 0) { 557 | status += " Printer out of paper"; 558 | } 559 | if ((buffer[0] & ESC_STATE_COVER_OPEN) > 0) { 560 | status += " Printer open cover"; 561 | } 562 | if ((buffer[0] & ESC_STATE_ERR_OCCURS) > 0) { 563 | status += " Printer error"; 564 | } 565 | Log.d(TAG, status); 566 | } 567 | } 568 | }else if (sendCommand == tsc) { 569 | //设置当前打印机模式为TSC模式 570 | if (currentPrinterCommand == null) { 571 | currentPrinterCommand = PrinterCommand.TSC; 572 | sendStateBroadcast(CONN_STATE_CONNECTED); 573 | } else { 574 | if (cnt == 1) {//查询打印机实时状态 575 | if ((buffer[0] & TSC_STATE_PAPER_ERR) > 0) {//缺纸 576 | status += " Printer out of paper"; 577 | } 578 | if ((buffer[0] & TSC_STATE_COVER_OPEN) > 0) {//开盖 579 | status += " Printer open cover"; 580 | } 581 | if ((buffer[0] & TSC_STATE_ERR_OCCURS) > 0) {//打印机报错 582 | status += " Printer error"; 583 | } 584 | Log.d(TAG, status); 585 | } else {//打印机状态查询 586 | Intent intent = new Intent(ACTION_QUERY_PRINTER_STATE); 587 | intent.putExtra(DEVICE_ID, id); 588 | if(mContext!=null){ 589 | mContext.sendBroadcast(intent); 590 | } 591 | } 592 | } 593 | }else if(sendCommand==cpcl){ 594 | if (currentPrinterCommand == null) { 595 | currentPrinterCommand = PrinterCommand.CPCL; 596 | sendStateBroadcast(CONN_STATE_CONNECTED); 597 | }else { 598 | if (cnt == 1) { 599 | 600 | if ((buffer[0] ==CPCL_STATE_PAPER_ERR)) {//缺纸 601 | status += " Printer out of paper"; 602 | } 603 | if ((buffer[0] ==CPCL_STATE_COVER_OPEN)) {//开盖 604 | status += " Printer open cover"; 605 | } 606 | Log.d(TAG, status); 607 | } else {//打印机状态查询 608 | Intent intent = new Intent(ACTION_QUERY_PRINTER_STATE); 609 | intent.putExtra(DEVICE_ID, id); 610 | if(mContext!=null){ 611 | mContext.sendBroadcast(intent); 612 | } 613 | } 614 | } 615 | } 616 | break; 617 | default: 618 | break; 619 | } 620 | } 621 | }; 622 | 623 | /** 624 | * 发送广播 625 | * @param state 626 | */ 627 | private void sendStateBroadcast(int state) { 628 | Intent intent = new Intent(ACTION_CONN_STATE); 629 | intent.putExtra(STATE, state); 630 | intent.putExtra(DEVICE_ID, id); 631 | if(mContext != null){ 632 | mContext.sendBroadcast(intent);//此处若报空指针错误,需要在清单文件application标签里注册此类,参考demo 633 | } 634 | } 635 | 636 | /** 637 | * 判断是实时状态(10 04 02)还是查询状态(1D 72 01) 638 | */ 639 | private int judgeResponseType(byte r) { 640 | return (byte) ((r & FLAG) >> 4); 641 | } 642 | 643 | } -------------------------------------------------------------------------------- /android/src/main/java/com/tablemi/flutter_bluetooth_basic/FlutterBluetoothBasicPlugin.java: -------------------------------------------------------------------------------- 1 | package com.tablemi.flutter_bluetooth_basic; 2 | 3 | import android.Manifest; 4 | import android.app.Activity; 5 | import android.bluetooth.BluetoothAdapter; 6 | import android.bluetooth.BluetoothDevice; 7 | import android.bluetooth.BluetoothManager; 8 | import android.bluetooth.le.BluetoothLeScanner; 9 | import android.bluetooth.le.ScanCallback; 10 | import android.bluetooth.le.ScanResult; 11 | import android.bluetooth.le.ScanSettings; 12 | import android.content.BroadcastReceiver; 13 | import android.content.Context; 14 | import android.content.Intent; 15 | import android.content.IntentFilter; 16 | import android.content.pm.PackageManager; 17 | import android.util.Log; 18 | import androidx.core.app.ActivityCompat; 19 | import androidx.core.content.ContextCompat; 20 | import io.flutter.plugin.common.EventChannel; 21 | import io.flutter.plugin.common.EventChannel.EventSink; 22 | import io.flutter.plugin.common.EventChannel.StreamHandler; 23 | import io.flutter.plugin.common.MethodCall; 24 | import io.flutter.plugin.common.MethodChannel; 25 | import io.flutter.plugin.common.MethodChannel.MethodCallHandler; 26 | import io.flutter.plugin.common.MethodChannel.Result; 27 | import io.flutter.plugin.common.PluginRegistry.Registrar; 28 | import io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener; 29 | 30 | import java.util.ArrayList; 31 | import java.util.HashMap; 32 | import java.util.List; 33 | import java.util.Map; 34 | import java.util.Vector; 35 | 36 | /** FlutterBluetoothBasicPlugin */ 37 | public class FlutterBluetoothBasicPlugin implements MethodCallHandler, RequestPermissionsResultListener { 38 | private static final String TAG = "BluetoothBasicPlugin"; 39 | private int id = 0; 40 | private ThreadPool threadPool; 41 | private static final int REQUEST_COARSE_LOCATION_PERMISSIONS = 1451; 42 | private static final String NAMESPACE = "flutter_bluetooth_basic"; 43 | private final Registrar registrar; 44 | private final Activity activity; 45 | private final MethodChannel channel; 46 | private final EventChannel stateChannel; 47 | private final BluetoothManager mBluetoothManager; 48 | private BluetoothAdapter mBluetoothAdapter; 49 | 50 | private MethodCall pendingCall; 51 | private Result pendingResult; 52 | 53 | public static void registerWith(Registrar registrar) { 54 | final FlutterBluetoothBasicPlugin instance = new FlutterBluetoothBasicPlugin(registrar); 55 | registrar.addRequestPermissionsResultListener(instance); 56 | } 57 | 58 | FlutterBluetoothBasicPlugin(Registrar r){ 59 | this.registrar = r; 60 | this.activity = r.activity(); 61 | this.channel = new MethodChannel(registrar.messenger(), NAMESPACE + "/methods"); 62 | this.stateChannel = new EventChannel(registrar.messenger(), NAMESPACE + "/state"); 63 | this.mBluetoothManager = (BluetoothManager) registrar.activity().getSystemService(Context.BLUETOOTH_SERVICE); 64 | this.mBluetoothAdapter = mBluetoothManager.getAdapter(); 65 | channel.setMethodCallHandler(this); 66 | stateChannel.setStreamHandler(stateStreamHandler); 67 | } 68 | 69 | @Override 70 | public void onMethodCall(MethodCall call, Result result) { 71 | if (mBluetoothAdapter == null && !"isAvailable".equals(call.method)) { 72 | result.error("bluetooth_unavailable", "Bluetooth is unavailable", null); 73 | return; 74 | } 75 | 76 | final Map args = call.arguments(); 77 | 78 | switch (call.method){ 79 | case "state": 80 | state(result); 81 | break; 82 | case "isAvailable": 83 | result.success(mBluetoothAdapter != null); 84 | break; 85 | case "isOn": 86 | result.success(mBluetoothAdapter.isEnabled()); 87 | break; 88 | case "isConnected": 89 | result.success(threadPool != null); 90 | break; 91 | case "startScan": { 92 | if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) 93 | != PackageManager.PERMISSION_GRANTED) { 94 | ActivityCompat.requestPermissions( 95 | activity, 96 | new String[] {Manifest.permission.ACCESS_COARSE_LOCATION}, 97 | REQUEST_COARSE_LOCATION_PERMISSIONS); 98 | pendingCall = call; 99 | pendingResult = result; 100 | break; 101 | } 102 | startScan(call, result); 103 | break; 104 | } 105 | case "stopScan": 106 | stopScan(); 107 | result.success(null); 108 | break; 109 | case "connect": 110 | connect(result, args); 111 | break; 112 | case "disconnect": 113 | result.success(disconnect()); 114 | break; 115 | case "destroy": 116 | result.success(destroy()); 117 | break; 118 | case "writeData": 119 | writeData(result, args); 120 | break; 121 | default: 122 | result.notImplemented(); 123 | break; 124 | } 125 | 126 | } 127 | 128 | private void getDevices(Result result){ 129 | List> devices = new ArrayList<>(); 130 | for (BluetoothDevice device : mBluetoothAdapter.getBondedDevices()) { 131 | Map ret = new HashMap<>(); 132 | ret.put("address", device.getAddress()); 133 | ret.put("name", device.getName()); 134 | ret.put("type", device.getType()); 135 | devices.add(ret); 136 | } 137 | 138 | result.success(devices); 139 | } 140 | 141 | private void state(Result result){ 142 | try { 143 | switch(mBluetoothAdapter.getState()) { 144 | case BluetoothAdapter.STATE_OFF: 145 | result.success(BluetoothAdapter.STATE_OFF); 146 | break; 147 | case BluetoothAdapter.STATE_ON: 148 | result.success(BluetoothAdapter.STATE_ON); 149 | break; 150 | case BluetoothAdapter.STATE_TURNING_OFF: 151 | result.success(BluetoothAdapter.STATE_TURNING_OFF); 152 | break; 153 | case BluetoothAdapter.STATE_TURNING_ON: 154 | result.success(BluetoothAdapter.STATE_TURNING_ON); 155 | break; 156 | default: 157 | result.success(0); 158 | break; 159 | } 160 | } catch (SecurityException e) { 161 | result.error("invalid_argument", "Argument 'address' not found", null); 162 | } 163 | 164 | } 165 | 166 | private void startScan(MethodCall call, Result result) { 167 | Log.d(TAG,"start scan "); 168 | 169 | try { 170 | startScan(); 171 | result.success(null); 172 | } catch (Exception e) { 173 | result.error("startScan", e.getMessage(), null); 174 | } 175 | } 176 | 177 | private void invokeMethodUIThread(final String name, final BluetoothDevice device) { 178 | final Map ret = new HashMap<>(); 179 | ret.put("address", device.getAddress()); 180 | ret.put("name", device.getName()); 181 | ret.put("type", device.getType()); 182 | 183 | activity.runOnUiThread( 184 | new Runnable() { 185 | @Override 186 | public void run() { 187 | channel.invokeMethod(name, ret); 188 | } 189 | }); 190 | } 191 | 192 | private ScanCallback mScanCallback = new ScanCallback() { 193 | @Override 194 | public void onScanResult(int callbackType, ScanResult result) { 195 | BluetoothDevice device = result.getDevice(); 196 | if(device != null && device.getName() != null){ 197 | invokeMethodUIThread("ScanResult", device); 198 | } 199 | } 200 | }; 201 | 202 | private void startScan() throws IllegalStateException { 203 | BluetoothLeScanner scanner = mBluetoothAdapter.getBluetoothLeScanner(); 204 | if(scanner == null) throw new IllegalStateException("getBluetoothLeScanner() is null. Is the Adapter on?"); 205 | 206 | // 0:lowPower 1:balanced 2:lowLatency -1:opportunistic 207 | ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build(); 208 | scanner.startScan(null, settings, mScanCallback); 209 | } 210 | 211 | private void stopScan() { 212 | BluetoothLeScanner scanner = mBluetoothAdapter.getBluetoothLeScanner(); 213 | if(scanner != null) scanner.stopScan(mScanCallback); 214 | } 215 | 216 | private void connect(Result result, Map args) { 217 | if (args.containsKey("address")) { 218 | String address = (String) args.get("address"); 219 | disconnect(); 220 | 221 | new DeviceConnFactoryManager.Build() 222 | .setId(id) 223 | // Set the connection method 224 | .setConnMethod(DeviceConnFactoryManager.CONN_METHOD.BLUETOOTH) 225 | // Set the connected Bluetooth mac address 226 | .setMacAddress(address) 227 | .build(); 228 | // Open port 229 | threadPool = ThreadPool.getInstantiation(); 230 | threadPool.addSerialTask(new Runnable() { 231 | @Override 232 | public void run() { 233 | DeviceConnFactoryManager.getDeviceConnFactoryManagers()[id].openPort(); 234 | } 235 | }); 236 | 237 | result.success(true); 238 | } else { 239 | result.error("invalid_argument", "Argument 'address' not found", null); 240 | } 241 | 242 | } 243 | 244 | /** 245 | * Reconnect to recycle the last connected object to avoid memory leaks 246 | */ 247 | private boolean disconnect(){ 248 | 249 | if(DeviceConnFactoryManager.getDeviceConnFactoryManagers()[id]!=null&&DeviceConnFactoryManager.getDeviceConnFactoryManagers()[id].mPort!=null) { 250 | DeviceConnFactoryManager.getDeviceConnFactoryManagers()[id].reader.cancel(); 251 | DeviceConnFactoryManager.getDeviceConnFactoryManagers()[id].mPort.closePort(); 252 | DeviceConnFactoryManager.getDeviceConnFactoryManagers()[id].mPort=null; 253 | } 254 | return true; 255 | } 256 | 257 | private boolean destroy() { 258 | DeviceConnFactoryManager.closeAllPort(); 259 | if (threadPool != null) { 260 | threadPool.stopThreadPool(); 261 | } 262 | 263 | return true; 264 | } 265 | 266 | @SuppressWarnings("unchecked") 267 | private void writeData(Result result, Map args) { 268 | if (args.containsKey("bytes")) { 269 | final ArrayList bytes = (ArrayList)args.get("bytes"); 270 | 271 | threadPool = ThreadPool.getInstantiation(); 272 | threadPool.addSerialTask(new Runnable() { 273 | @Override 274 | public void run() { 275 | Vector vectorData = new Vector<>(); 276 | for(int i = 0; i < bytes.size(); ++i) { 277 | Integer val = bytes.get(i); 278 | vectorData.add(Byte.valueOf( Integer.toString(val > 127 ? val-256 : val ) )); 279 | } 280 | 281 | DeviceConnFactoryManager.getDeviceConnFactoryManagers()[id].sendDataImmediately(vectorData); 282 | } 283 | }); 284 | } else { 285 | result.error("bytes_empty", "Bytes param is empty", null); 286 | } 287 | } 288 | 289 | @Override 290 | public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 291 | 292 | if (requestCode == REQUEST_COARSE_LOCATION_PERMISSIONS) { 293 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { 294 | startScan(pendingCall, pendingResult); 295 | } else { 296 | pendingResult.error("no_permissions", "This app requires location permissions for scanning", null); 297 | pendingResult = null; 298 | } 299 | return true; 300 | } 301 | return false; 302 | 303 | } 304 | 305 | private final StreamHandler stateStreamHandler = new StreamHandler() { 306 | private EventSink sink; 307 | 308 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { 309 | @Override 310 | public void onReceive(Context context, Intent intent) { 311 | final String action = intent.getAction(); 312 | Log.d(TAG, "stateStreamHandler, current action: " + action); 313 | 314 | if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { 315 | threadPool = null; 316 | sink.success(intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1)); 317 | } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { 318 | sink.success(1); 319 | } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) { 320 | threadPool = null; 321 | sink.success(0); 322 | } 323 | } 324 | }; 325 | 326 | @Override 327 | public void onListen(Object o, EventSink eventSink) { 328 | sink = eventSink; 329 | IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); 330 | filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); 331 | filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); 332 | filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); 333 | activity.registerReceiver(mReceiver, filter); 334 | } 335 | 336 | @Override 337 | public void onCancel(Object o) { 338 | sink = null; 339 | activity.unregisterReceiver(mReceiver); 340 | } 341 | }; 342 | 343 | 344 | 345 | } 346 | -------------------------------------------------------------------------------- /android/src/main/java/com/tablemi/flutter_bluetooth_basic/PrinterCommand.java: -------------------------------------------------------------------------------- 1 | package com.tablemi.flutter_bluetooth_basic; 2 | 3 | public enum PrinterCommand { 4 | ESC, 5 | TSC, 6 | CPCL 7 | } 8 | -------------------------------------------------------------------------------- /android/src/main/java/com/tablemi/flutter_bluetooth_basic/ThreadFactoryBuilder.java: -------------------------------------------------------------------------------- 1 | package com.tablemi.flutter_bluetooth_basic; 2 | 3 | import java.util.concurrent.ThreadFactory; 4 | 5 | public class ThreadFactoryBuilder implements ThreadFactory { 6 | 7 | private String name; 8 | private int counter; 9 | 10 | public ThreadFactoryBuilder(String name) { 11 | this.name = name; 12 | counter = 1; 13 | } 14 | 15 | @Override 16 | public Thread newThread(Runnable runnable) { 17 | Thread thread = new Thread(runnable, name); 18 | thread.setName("ThreadFactoryBuilder_" + name + "_" + counter); 19 | return thread; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /android/src/main/java/com/tablemi/flutter_bluetooth_basic/ThreadPool.java: -------------------------------------------------------------------------------- 1 | package com.tablemi.flutter_bluetooth_basic; 2 | 3 | import android.util.Log; 4 | 5 | import java.util.ArrayDeque; 6 | import java.util.concurrent.*; 7 | 8 | 9 | public class ThreadPool { 10 | 11 | private Runnable mActive; 12 | 13 | private static ThreadPool threadPool; 14 | /** 15 | * java线程池 16 | */ 17 | private ThreadPoolExecutor threadPoolExecutor; 18 | 19 | /** 20 | * 系统最大可用线程 21 | */ 22 | private final static int CPU_AVAILABLE = Runtime.getRuntime().availableProcessors(); 23 | 24 | /** 25 | * 最大线程数 26 | */ 27 | private final static int MAX_POOL_COUNTS = CPU_AVAILABLE * 2 + 1; 28 | 29 | /** 30 | * 线程存活时间 31 | */ 32 | private final static long AVAILABLE = 1L; 33 | 34 | /** 35 | * 核心线程数 36 | */ 37 | private final static int CORE_POOL_SIZE = CPU_AVAILABLE + 1; 38 | 39 | /** 40 | * 线程池缓存队列 41 | */ 42 | private BlockingQueue mWorkQueue = new ArrayBlockingQueue<>(CORE_POOL_SIZE); 43 | 44 | private ArrayDeque mArrayDeque = new ArrayDeque<>(); 45 | 46 | private ThreadFactory threadFactory = new ThreadFactoryBuilder("ThreadPool"); 47 | 48 | private ThreadPool() { 49 | threadPoolExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_COUNTS, AVAILABLE, TimeUnit.SECONDS, mWorkQueue,threadFactory); 50 | } 51 | 52 | public static ThreadPool getInstantiation() { 53 | if (threadPool == null) { 54 | threadPool = new ThreadPool(); 55 | } 56 | return threadPool; 57 | } 58 | 59 | public void addParallelTask(Runnable runnable) { //并行线程 60 | if (runnable == null) { 61 | throw new NullPointerException("addTask(Runnable runnable)传入参数为空"); 62 | } 63 | if (threadPoolExecutor.getActiveCount() 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 26 | 27 | android { 28 | compileSdkVersion 28 29 | 30 | lintOptions { 31 | disable 'InvalidPackage' 32 | } 33 | 34 | defaultConfig { 35 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 36 | applicationId "com.tablemi.flutter_bluetooth_basic_example" 37 | minSdkVersion 21 38 | targetSdkVersion 28 39 | versionCode flutterVersionCode.toInteger() 40 | versionName flutterVersionName 41 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 42 | } 43 | 44 | buildTypes { 45 | release { 46 | // TODO: Add your own signing config for the release build. 47 | // Signing with the debug keys for now, so `flutter run --release` works. 48 | signingConfig signingConfigs.debug 49 | } 50 | } 51 | } 52 | 53 | flutter { 54 | source '../..' 55 | } 56 | 57 | dependencies { 58 | testImplementation 'junit:junit:4.12' 59 | androidTestImplementation 'androidx.test:runner:1.1.1' 60 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' 61 | } 62 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 8 | 12 | 19 | 20 | 21 | 22 | 23 | 24 | 26 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/tablemi/flutter_bluetooth_basic_example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.tablemi.flutter_bluetooth_basic_example; 2 | 3 | import androidx.annotation.NonNull; 4 | import io.flutter.embedding.android.FlutterActivity; 5 | import io.flutter.embedding.engine.FlutterEngine; 6 | import io.flutter.plugins.GeneratedPluginRegistrant; 7 | 8 | public class MainActivity extends FlutterActivity { 9 | @Override 10 | public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { 11 | GeneratedPluginRegistrant.registerWith(flutterEngine); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | jcenter() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:3.5.3' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | google() 15 | jcenter() 16 | } 17 | } 18 | 19 | rootProject.buildDir = '../build' 20 | subprojects { 21 | project.buildDir = "${rootProject.buildDir}/${project.name}" 22 | } 23 | subprojects { 24 | project.evaluationDependsOn(':app') 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.enableR8=true 3 | android.useAndroidX=true 4 | android.enableJetifier=true 5 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip 7 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() 4 | 5 | def plugins = new Properties() 6 | def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') 7 | if (pluginsFile.exists()) { 8 | pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } 9 | } 10 | 11 | plugins.each { name, path -> 12 | def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() 13 | include ":$name" 14 | project(":$name").projectDir = pluginDirectory 15 | } 16 | -------------------------------------------------------------------------------- /example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | *.mode1v3 2 | *.mode2v3 3 | *.moved-aside 4 | *.pbxuser 5 | *.perspectivev3 6 | **/*sync/ 7 | .sconsign.dblite 8 | .tags* 9 | **/.vagrant/ 10 | **/DerivedData/ 11 | Icon? 12 | **/Pods/ 13 | **/.symlinks/ 14 | profile 15 | xcuserdata 16 | **/.generated/ 17 | Flutter/App.framework 18 | Flutter/Flutter.framework 19 | Flutter/Flutter.podspec 20 | Flutter/Generated.xcconfig 21 | Flutter/app.flx 22 | Flutter/app.zip 23 | Flutter/flutter_assets/ 24 | Flutter/flutter_export_environment.sh 25 | ServiceDefinitions.json 26 | Runner/GeneratedPluginRegistrant.* 27 | 28 | # Exceptions to above rules. 29 | !default.mode1v3 30 | !default.mode2v3 31 | !default.pbxuser 32 | !default.perspectivev3 33 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 8.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | # platform :ios, '9.0' 3 | 4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 6 | 7 | project 'Runner', { 8 | 'Debug' => :debug, 9 | 'Profile' => :release, 10 | 'Release' => :release, 11 | } 12 | 13 | def parse_KV_file(file, separator='=') 14 | file_abs_path = File.expand_path(file) 15 | if !File.exists? file_abs_path 16 | return []; 17 | end 18 | generated_key_values = {} 19 | skip_line_start_symbols = ["#", "/"] 20 | File.foreach(file_abs_path) do |line| 21 | next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ } 22 | plugin = line.split(pattern=separator) 23 | if plugin.length == 2 24 | podname = plugin[0].strip() 25 | path = plugin[1].strip() 26 | podpath = File.expand_path("#{path}", file_abs_path) 27 | generated_key_values[podname] = podpath 28 | else 29 | puts "Invalid plugin specification: #{line}" 30 | end 31 | end 32 | generated_key_values 33 | end 34 | 35 | target 'Runner' do 36 | # Flutter Pod 37 | 38 | copied_flutter_dir = File.join(__dir__, 'Flutter') 39 | copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework') 40 | copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec') 41 | unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path) 42 | # Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet. 43 | # That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration. 44 | # CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist. 45 | 46 | generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig') 47 | unless File.exist?(generated_xcode_build_settings_path) 48 | raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first" 49 | end 50 | generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path) 51 | cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR']; 52 | 53 | unless File.exist?(copied_framework_path) 54 | FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir) 55 | end 56 | unless File.exist?(copied_podspec_path) 57 | FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir) 58 | end 59 | end 60 | 61 | # Keep pod path relative so it can be checked into Podfile.lock. 62 | pod 'Flutter', :path => 'Flutter' 63 | 64 | # Plugin Pods 65 | 66 | # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock 67 | # referring to absolute paths on developers' machines. 68 | system('rm -rf .symlinks') 69 | system('mkdir -p .symlinks/plugins') 70 | plugin_pods = parse_KV_file('../.flutter-plugins') 71 | plugin_pods.each do |name, path| 72 | symlink = File.join('.symlinks', 'plugins', name) 73 | File.symlink(path, symlink) 74 | pod name, :path => File.join(symlink, 'ios') 75 | end 76 | end 77 | 78 | # Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system. 79 | install! 'cocoapods', :disable_input_output_paths => true 80 | 81 | post_install do |installer| 82 | installer.pods_project.targets.each do |target| 83 | target.build_configurations.each do |config| 84 | config.build_settings['ENABLE_BITCODE'] = 'NO' 85 | end 86 | end 87 | end 88 | -------------------------------------------------------------------------------- /example/ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - Flutter (1.0.0) 3 | - flutter_bluetooth_basic (0.0.1): 4 | - Flutter 5 | - path_provider (0.0.1): 6 | - Flutter 7 | 8 | DEPENDENCIES: 9 | - Flutter (from `Flutter`) 10 | - flutter_bluetooth_basic (from `.symlinks/plugins/flutter_bluetooth_basic/ios`) 11 | - path_provider (from `.symlinks/plugins/path_provider/ios`) 12 | 13 | EXTERNAL SOURCES: 14 | Flutter: 15 | :path: Flutter 16 | flutter_bluetooth_basic: 17 | :path: ".symlinks/plugins/flutter_bluetooth_basic/ios" 18 | path_provider: 19 | :path: ".symlinks/plugins/path_provider/ios" 20 | 21 | SPEC CHECKSUMS: 22 | Flutter: 0e3d915762c693b495b44d77113d4970485de6ec 23 | flutter_bluetooth_basic: 0e4e27e22b50b3a25cc1d1e131953feb4af414f4 24 | path_provider: fb74bd0465e96b594bb3b5088ee4a4e7bb1f2a9d 25 | 26 | PODFILE CHECKSUM: 3dbe063e9c90a5d7c9e4e76e70a821b9e2c1d271 27 | 28 | COCOAPODS: 1.8.4 29 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 11 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 12 | 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 13 | 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 14 | 92AC2DEF0FE1AD4381FF46F0 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EBFC51A13E362D761AD92AB2 /* libPods-Runner.a */; }; 15 | 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; 16 | 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 17 | 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; 18 | 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; 19 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 20 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 21 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXCopyFilesBuildPhase section */ 25 | 9705A1C41CF9048500538489 /* Embed Frameworks */ = { 26 | isa = PBXCopyFilesBuildPhase; 27 | buildActionMask = 2147483647; 28 | dstPath = ""; 29 | dstSubfolderSpec = 10; 30 | files = ( 31 | 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, 32 | 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, 33 | ); 34 | name = "Embed Frameworks"; 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXCopyFilesBuildPhase section */ 38 | 39 | /* Begin PBXFileReference section */ 40 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 41 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 42 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 43 | 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 44 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 45 | 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 46 | 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 47 | 89FC27FEE05299E830AC2A76 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 48 | 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 49 | 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 50 | 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 51 | 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 52 | 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 53 | 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 54 | 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 55 | 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 56 | 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 57 | B365B4D6871B56C59378C336 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 58 | EBFC51A13E362D761AD92AB2 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 59 | F3316B1877E9B2F711FD6F98 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 60 | /* End PBXFileReference section */ 61 | 62 | /* Begin PBXFrameworksBuildPhase section */ 63 | 97C146EB1CF9000F007C117D /* Frameworks */ = { 64 | isa = PBXFrameworksBuildPhase; 65 | buildActionMask = 2147483647; 66 | files = ( 67 | 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, 68 | 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, 69 | 92AC2DEF0FE1AD4381FF46F0 /* libPods-Runner.a in Frameworks */, 70 | ); 71 | runOnlyForDeploymentPostprocessing = 0; 72 | }; 73 | /* End PBXFrameworksBuildPhase section */ 74 | 75 | /* Begin PBXGroup section */ 76 | 230AA67EDFEF05D8734536AD /* Pods */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | F3316B1877E9B2F711FD6F98 /* Pods-Runner.debug.xcconfig */, 80 | 89FC27FEE05299E830AC2A76 /* Pods-Runner.release.xcconfig */, 81 | B365B4D6871B56C59378C336 /* Pods-Runner.profile.xcconfig */, 82 | ); 83 | path = Pods; 84 | sourceTree = ""; 85 | }; 86 | 4BC1EA12D25798CAE0ED6C20 /* Frameworks */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | EBFC51A13E362D761AD92AB2 /* libPods-Runner.a */, 90 | ); 91 | name = Frameworks; 92 | sourceTree = ""; 93 | }; 94 | 9740EEB11CF90186004384FC /* Flutter */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 3B80C3931E831B6300D905FE /* App.framework */, 98 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 99 | 9740EEBA1CF902C7004384FC /* Flutter.framework */, 100 | 9740EEB21CF90195004384FC /* Debug.xcconfig */, 101 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 102 | 9740EEB31CF90195004384FC /* Generated.xcconfig */, 103 | ); 104 | name = Flutter; 105 | sourceTree = ""; 106 | }; 107 | 97C146E51CF9000F007C117D = { 108 | isa = PBXGroup; 109 | children = ( 110 | 9740EEB11CF90186004384FC /* Flutter */, 111 | 97C146F01CF9000F007C117D /* Runner */, 112 | 97C146EF1CF9000F007C117D /* Products */, 113 | 230AA67EDFEF05D8734536AD /* Pods */, 114 | 4BC1EA12D25798CAE0ED6C20 /* Frameworks */, 115 | ); 116 | sourceTree = ""; 117 | }; 118 | 97C146EF1CF9000F007C117D /* Products */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 97C146EE1CF9000F007C117D /* Runner.app */, 122 | ); 123 | name = Products; 124 | sourceTree = ""; 125 | }; 126 | 97C146F01CF9000F007C117D /* Runner */ = { 127 | isa = PBXGroup; 128 | children = ( 129 | 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, 130 | 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, 131 | 97C146FA1CF9000F007C117D /* Main.storyboard */, 132 | 97C146FD1CF9000F007C117D /* Assets.xcassets */, 133 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 134 | 97C147021CF9000F007C117D /* Info.plist */, 135 | 97C146F11CF9000F007C117D /* Supporting Files */, 136 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 137 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 138 | ); 139 | path = Runner; 140 | sourceTree = ""; 141 | }; 142 | 97C146F11CF9000F007C117D /* Supporting Files */ = { 143 | isa = PBXGroup; 144 | children = ( 145 | 97C146F21CF9000F007C117D /* main.m */, 146 | ); 147 | name = "Supporting Files"; 148 | sourceTree = ""; 149 | }; 150 | /* End PBXGroup section */ 151 | 152 | /* Begin PBXNativeTarget section */ 153 | 97C146ED1CF9000F007C117D /* Runner */ = { 154 | isa = PBXNativeTarget; 155 | buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; 156 | buildPhases = ( 157 | D8BFF256A8E2C306C228A524 /* [CP] Check Pods Manifest.lock */, 158 | 9740EEB61CF901F6004384FC /* Run Script */, 159 | 97C146EA1CF9000F007C117D /* Sources */, 160 | 97C146EB1CF9000F007C117D /* Frameworks */, 161 | 97C146EC1CF9000F007C117D /* Resources */, 162 | 9705A1C41CF9048500538489 /* Embed Frameworks */, 163 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */, 164 | 224C8CE2EFE4315A68DB0D58 /* [CP] Embed Pods Frameworks */, 165 | ); 166 | buildRules = ( 167 | ); 168 | dependencies = ( 169 | ); 170 | name = Runner; 171 | productName = Runner; 172 | productReference = 97C146EE1CF9000F007C117D /* Runner.app */; 173 | productType = "com.apple.product-type.application"; 174 | }; 175 | /* End PBXNativeTarget section */ 176 | 177 | /* Begin PBXProject section */ 178 | 97C146E61CF9000F007C117D /* Project object */ = { 179 | isa = PBXProject; 180 | attributes = { 181 | LastUpgradeCheck = 1020; 182 | ORGANIZATIONNAME = "The Chromium Authors"; 183 | TargetAttributes = { 184 | 97C146ED1CF9000F007C117D = { 185 | CreatedOnToolsVersion = 7.3.1; 186 | DevelopmentTeam = 8YA3WTV6AF; 187 | }; 188 | }; 189 | }; 190 | buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; 191 | compatibilityVersion = "Xcode 3.2"; 192 | developmentRegion = en; 193 | hasScannedForEncodings = 0; 194 | knownRegions = ( 195 | en, 196 | Base, 197 | ); 198 | mainGroup = 97C146E51CF9000F007C117D; 199 | productRefGroup = 97C146EF1CF9000F007C117D /* Products */; 200 | projectDirPath = ""; 201 | projectRoot = ""; 202 | targets = ( 203 | 97C146ED1CF9000F007C117D /* Runner */, 204 | ); 205 | }; 206 | /* End PBXProject section */ 207 | 208 | /* Begin PBXResourcesBuildPhase section */ 209 | 97C146EC1CF9000F007C117D /* Resources */ = { 210 | isa = PBXResourcesBuildPhase; 211 | buildActionMask = 2147483647; 212 | files = ( 213 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 214 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 215 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 216 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 217 | ); 218 | runOnlyForDeploymentPostprocessing = 0; 219 | }; 220 | /* End PBXResourcesBuildPhase section */ 221 | 222 | /* Begin PBXShellScriptBuildPhase section */ 223 | 224C8CE2EFE4315A68DB0D58 /* [CP] Embed Pods Frameworks */ = { 224 | isa = PBXShellScriptBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | ); 228 | inputPaths = ( 229 | ); 230 | name = "[CP] Embed Pods Frameworks"; 231 | outputPaths = ( 232 | ); 233 | runOnlyForDeploymentPostprocessing = 0; 234 | shellPath = /bin/sh; 235 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; 236 | showEnvVarsInLog = 0; 237 | }; 238 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { 239 | isa = PBXShellScriptBuildPhase; 240 | buildActionMask = 2147483647; 241 | files = ( 242 | ); 243 | inputPaths = ( 244 | ); 245 | name = "Thin Binary"; 246 | outputPaths = ( 247 | ); 248 | runOnlyForDeploymentPostprocessing = 0; 249 | shellPath = /bin/sh; 250 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; 251 | }; 252 | 9740EEB61CF901F6004384FC /* Run Script */ = { 253 | isa = PBXShellScriptBuildPhase; 254 | buildActionMask = 2147483647; 255 | files = ( 256 | ); 257 | inputPaths = ( 258 | ); 259 | name = "Run Script"; 260 | outputPaths = ( 261 | ); 262 | runOnlyForDeploymentPostprocessing = 0; 263 | shellPath = /bin/sh; 264 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; 265 | }; 266 | D8BFF256A8E2C306C228A524 /* [CP] Check Pods Manifest.lock */ = { 267 | isa = PBXShellScriptBuildPhase; 268 | buildActionMask = 2147483647; 269 | files = ( 270 | ); 271 | inputFileListPaths = ( 272 | ); 273 | inputPaths = ( 274 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 275 | "${PODS_ROOT}/Manifest.lock", 276 | ); 277 | name = "[CP] Check Pods Manifest.lock"; 278 | outputFileListPaths = ( 279 | ); 280 | outputPaths = ( 281 | "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", 282 | ); 283 | runOnlyForDeploymentPostprocessing = 0; 284 | shellPath = /bin/sh; 285 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 286 | showEnvVarsInLog = 0; 287 | }; 288 | /* End PBXShellScriptBuildPhase section */ 289 | 290 | /* Begin PBXSourcesBuildPhase section */ 291 | 97C146EA1CF9000F007C117D /* Sources */ = { 292 | isa = PBXSourcesBuildPhase; 293 | buildActionMask = 2147483647; 294 | files = ( 295 | 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */, 296 | 97C146F31CF9000F007C117D /* main.m in Sources */, 297 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, 298 | ); 299 | runOnlyForDeploymentPostprocessing = 0; 300 | }; 301 | /* End PBXSourcesBuildPhase section */ 302 | 303 | /* Begin PBXVariantGroup section */ 304 | 97C146FA1CF9000F007C117D /* Main.storyboard */ = { 305 | isa = PBXVariantGroup; 306 | children = ( 307 | 97C146FB1CF9000F007C117D /* Base */, 308 | ); 309 | name = Main.storyboard; 310 | sourceTree = ""; 311 | }; 312 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { 313 | isa = PBXVariantGroup; 314 | children = ( 315 | 97C147001CF9000F007C117D /* Base */, 316 | ); 317 | name = LaunchScreen.storyboard; 318 | sourceTree = ""; 319 | }; 320 | /* End PBXVariantGroup section */ 321 | 322 | /* Begin XCBuildConfiguration section */ 323 | 249021D3217E4FDB00AE95B9 /* Profile */ = { 324 | isa = XCBuildConfiguration; 325 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 326 | buildSettings = { 327 | ALWAYS_SEARCH_USER_PATHS = NO; 328 | CLANG_ANALYZER_NONNULL = YES; 329 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 330 | CLANG_CXX_LIBRARY = "libc++"; 331 | CLANG_ENABLE_MODULES = YES; 332 | CLANG_ENABLE_OBJC_ARC = YES; 333 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 334 | CLANG_WARN_BOOL_CONVERSION = YES; 335 | CLANG_WARN_COMMA = YES; 336 | CLANG_WARN_CONSTANT_CONVERSION = YES; 337 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 338 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 339 | CLANG_WARN_EMPTY_BODY = YES; 340 | CLANG_WARN_ENUM_CONVERSION = YES; 341 | CLANG_WARN_INFINITE_RECURSION = YES; 342 | CLANG_WARN_INT_CONVERSION = YES; 343 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 344 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 345 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 346 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 347 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 348 | CLANG_WARN_STRICT_PROTOTYPES = YES; 349 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 350 | CLANG_WARN_UNREACHABLE_CODE = YES; 351 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 352 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 353 | COPY_PHASE_STRIP = NO; 354 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 355 | ENABLE_NS_ASSERTIONS = NO; 356 | ENABLE_STRICT_OBJC_MSGSEND = YES; 357 | GCC_C_LANGUAGE_STANDARD = gnu99; 358 | GCC_NO_COMMON_BLOCKS = YES; 359 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 360 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 361 | GCC_WARN_UNDECLARED_SELECTOR = YES; 362 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 363 | GCC_WARN_UNUSED_FUNCTION = YES; 364 | GCC_WARN_UNUSED_VARIABLE = YES; 365 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 366 | MTL_ENABLE_DEBUG_INFO = NO; 367 | SDKROOT = iphoneos; 368 | SUPPORTED_PLATFORMS = iphoneos; 369 | TARGETED_DEVICE_FAMILY = "1,2"; 370 | VALIDATE_PRODUCT = YES; 371 | }; 372 | name = Profile; 373 | }; 374 | 249021D4217E4FDB00AE95B9 /* Profile */ = { 375 | isa = XCBuildConfiguration; 376 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 377 | buildSettings = { 378 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 379 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 380 | DEVELOPMENT_TEAM = 8YA3WTV6AF; 381 | ENABLE_BITCODE = NO; 382 | FRAMEWORK_SEARCH_PATHS = ( 383 | "$(inherited)", 384 | "$(PROJECT_DIR)/Flutter", 385 | ); 386 | INFOPLIST_FILE = Runner/Info.plist; 387 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 388 | LIBRARY_SEARCH_PATHS = ( 389 | "$(inherited)", 390 | "$(PROJECT_DIR)/Flutter", 391 | ); 392 | PRODUCT_BUNDLE_IDENTIFIER = com.tablemi.flutterBluetoothBasicExample; 393 | PRODUCT_NAME = "$(TARGET_NAME)"; 394 | VERSIONING_SYSTEM = "apple-generic"; 395 | }; 396 | name = Profile; 397 | }; 398 | 97C147031CF9000F007C117D /* Debug */ = { 399 | isa = XCBuildConfiguration; 400 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 401 | buildSettings = { 402 | ALWAYS_SEARCH_USER_PATHS = NO; 403 | CLANG_ANALYZER_NONNULL = YES; 404 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 405 | CLANG_CXX_LIBRARY = "libc++"; 406 | CLANG_ENABLE_MODULES = YES; 407 | CLANG_ENABLE_OBJC_ARC = YES; 408 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 409 | CLANG_WARN_BOOL_CONVERSION = YES; 410 | CLANG_WARN_COMMA = YES; 411 | CLANG_WARN_CONSTANT_CONVERSION = YES; 412 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 413 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 414 | CLANG_WARN_EMPTY_BODY = YES; 415 | CLANG_WARN_ENUM_CONVERSION = YES; 416 | CLANG_WARN_INFINITE_RECURSION = YES; 417 | CLANG_WARN_INT_CONVERSION = YES; 418 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 419 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 420 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 421 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 422 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 423 | CLANG_WARN_STRICT_PROTOTYPES = YES; 424 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 425 | CLANG_WARN_UNREACHABLE_CODE = YES; 426 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 427 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 428 | COPY_PHASE_STRIP = NO; 429 | DEBUG_INFORMATION_FORMAT = dwarf; 430 | ENABLE_STRICT_OBJC_MSGSEND = YES; 431 | ENABLE_TESTABILITY = YES; 432 | GCC_C_LANGUAGE_STANDARD = gnu99; 433 | GCC_DYNAMIC_NO_PIC = NO; 434 | GCC_NO_COMMON_BLOCKS = YES; 435 | GCC_OPTIMIZATION_LEVEL = 0; 436 | GCC_PREPROCESSOR_DEFINITIONS = ( 437 | "DEBUG=1", 438 | "$(inherited)", 439 | ); 440 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 441 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 442 | GCC_WARN_UNDECLARED_SELECTOR = YES; 443 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 444 | GCC_WARN_UNUSED_FUNCTION = YES; 445 | GCC_WARN_UNUSED_VARIABLE = YES; 446 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 447 | MTL_ENABLE_DEBUG_INFO = YES; 448 | ONLY_ACTIVE_ARCH = YES; 449 | SDKROOT = iphoneos; 450 | TARGETED_DEVICE_FAMILY = "1,2"; 451 | }; 452 | name = Debug; 453 | }; 454 | 97C147041CF9000F007C117D /* Release */ = { 455 | isa = XCBuildConfiguration; 456 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 457 | buildSettings = { 458 | ALWAYS_SEARCH_USER_PATHS = NO; 459 | CLANG_ANALYZER_NONNULL = YES; 460 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 461 | CLANG_CXX_LIBRARY = "libc++"; 462 | CLANG_ENABLE_MODULES = YES; 463 | CLANG_ENABLE_OBJC_ARC = YES; 464 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 465 | CLANG_WARN_BOOL_CONVERSION = YES; 466 | CLANG_WARN_COMMA = YES; 467 | CLANG_WARN_CONSTANT_CONVERSION = YES; 468 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 469 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 470 | CLANG_WARN_EMPTY_BODY = YES; 471 | CLANG_WARN_ENUM_CONVERSION = YES; 472 | CLANG_WARN_INFINITE_RECURSION = YES; 473 | CLANG_WARN_INT_CONVERSION = YES; 474 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 475 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 476 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 477 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 478 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 479 | CLANG_WARN_STRICT_PROTOTYPES = YES; 480 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 481 | CLANG_WARN_UNREACHABLE_CODE = YES; 482 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 483 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 484 | COPY_PHASE_STRIP = NO; 485 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 486 | ENABLE_NS_ASSERTIONS = NO; 487 | ENABLE_STRICT_OBJC_MSGSEND = YES; 488 | GCC_C_LANGUAGE_STANDARD = gnu99; 489 | GCC_NO_COMMON_BLOCKS = YES; 490 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 491 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 492 | GCC_WARN_UNDECLARED_SELECTOR = YES; 493 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 494 | GCC_WARN_UNUSED_FUNCTION = YES; 495 | GCC_WARN_UNUSED_VARIABLE = YES; 496 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 497 | MTL_ENABLE_DEBUG_INFO = NO; 498 | SDKROOT = iphoneos; 499 | SUPPORTED_PLATFORMS = iphoneos; 500 | TARGETED_DEVICE_FAMILY = "1,2"; 501 | VALIDATE_PRODUCT = YES; 502 | }; 503 | name = Release; 504 | }; 505 | 97C147061CF9000F007C117D /* Debug */ = { 506 | isa = XCBuildConfiguration; 507 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 508 | buildSettings = { 509 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 510 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 511 | DEVELOPMENT_TEAM = 8YA3WTV6AF; 512 | ENABLE_BITCODE = NO; 513 | FRAMEWORK_SEARCH_PATHS = ( 514 | "$(inherited)", 515 | "$(PROJECT_DIR)/Flutter", 516 | ); 517 | INFOPLIST_FILE = Runner/Info.plist; 518 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 519 | LIBRARY_SEARCH_PATHS = ( 520 | "$(inherited)", 521 | "$(PROJECT_DIR)/Flutter", 522 | ); 523 | PRODUCT_BUNDLE_IDENTIFIER = com.tablemi.flutterBluetoothBasicExample; 524 | PRODUCT_NAME = "$(TARGET_NAME)"; 525 | VERSIONING_SYSTEM = "apple-generic"; 526 | }; 527 | name = Debug; 528 | }; 529 | 97C147071CF9000F007C117D /* Release */ = { 530 | isa = XCBuildConfiguration; 531 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 532 | buildSettings = { 533 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 534 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 535 | DEVELOPMENT_TEAM = 8YA3WTV6AF; 536 | ENABLE_BITCODE = NO; 537 | FRAMEWORK_SEARCH_PATHS = ( 538 | "$(inherited)", 539 | "$(PROJECT_DIR)/Flutter", 540 | ); 541 | INFOPLIST_FILE = Runner/Info.plist; 542 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 543 | LIBRARY_SEARCH_PATHS = ( 544 | "$(inherited)", 545 | "$(PROJECT_DIR)/Flutter", 546 | ); 547 | PRODUCT_BUNDLE_IDENTIFIER = com.tablemi.flutterBluetoothBasicExample; 548 | PRODUCT_NAME = "$(TARGET_NAME)"; 549 | VERSIONING_SYSTEM = "apple-generic"; 550 | }; 551 | name = Release; 552 | }; 553 | /* End XCBuildConfiguration section */ 554 | 555 | /* Begin XCConfigurationList section */ 556 | 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { 557 | isa = XCConfigurationList; 558 | buildConfigurations = ( 559 | 97C147031CF9000F007C117D /* Debug */, 560 | 97C147041CF9000F007C117D /* Release */, 561 | 249021D3217E4FDB00AE95B9 /* Profile */, 562 | ); 563 | defaultConfigurationIsVisible = 0; 564 | defaultConfigurationName = Release; 565 | }; 566 | 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { 567 | isa = XCConfigurationList; 568 | buildConfigurations = ( 569 | 97C147061CF9000F007C117D /* Debug */, 570 | 97C147071CF9000F007C117D /* Release */, 571 | 249021D4217E4FDB00AE95B9 /* Profile */, 572 | ); 573 | defaultConfigurationIsVisible = 0; 574 | defaultConfigurationName = Release; 575 | }; 576 | /* End XCConfigurationList section */ 577 | }; 578 | rootObject = 97C146E61CF9000F007C117D /* Project object */; 579 | } 580 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : FlutterAppDelegate 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | #import "GeneratedPluginRegistrant.h" 3 | 4 | @implementation AppDelegate 5 | 6 | - (BOOL)application:(UIApplication *)application 7 | didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 8 | [GeneratedPluginRegistrant registerWithRegistry:self]; 9 | // Override point for customization after application launch. 10 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; 11 | } 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | flutter_bluetooth_basic_example 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | $(FLUTTER_BUILD_NAME) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | NSBluetoothAlwaysUsageDescription 43 | Allow App use bluetooth? 44 | NSBluetoothPeripheralUsageDescription 45 | Allow App use bluetooth? 46 | UIBackgroundModes 47 | 48 | bluetooth-central 49 | bluetooth-peripheral 50 | 51 | UIViewControllerBasedStatusBarAppearance 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /example/ios/Runner/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char* argv[]) { 6 | @autoreleasepool { 7 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | // import 'dart:typed_data'; 3 | 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutter_bluetooth_basic/flutter_bluetooth_basic.dart'; 6 | 7 | void main() => runApp(MyApp()); 8 | 9 | class MyApp extends StatelessWidget { 10 | @override 11 | Widget build(BuildContext context) { 12 | return MaterialApp( 13 | title: 'Bluetooth scanner', 14 | theme: ThemeData( 15 | primarySwatch: Colors.blue, 16 | ), 17 | home: MyHomePage(title: 'Bluetooth Scanner'), 18 | ); 19 | } 20 | } 21 | 22 | class MyHomePage extends StatefulWidget { 23 | MyHomePage({Key key, this.title}) : super(key: key); 24 | final String title; 25 | 26 | @override 27 | _MyHomePageState createState() => _MyHomePageState(); 28 | } 29 | 30 | class _MyHomePageState extends State { 31 | BluetoothManager bluetoothManager = BluetoothManager.instance; 32 | 33 | bool _connected = false; 34 | BluetoothDevice _device; 35 | String tips = 'no device connect'; 36 | 37 | @override 38 | void initState() { 39 | super.initState(); 40 | 41 | WidgetsBinding.instance.addPostFrameCallback((_) => initBluetooth()); 42 | } 43 | 44 | // Platform messages are asynchronous, so we initialize in an async method. 45 | Future initBluetooth() async { 46 | bluetoothManager.startScan(timeout: Duration(seconds: 4)); 47 | 48 | bool isConnected = await bluetoothManager.isConnected; 49 | 50 | bluetoothManager.state.listen((state) { 51 | print('cur device status: $state'); 52 | 53 | switch (state) { 54 | case BluetoothManager.CONNECTED: 55 | setState(() { 56 | _connected = true; 57 | tips = 'connect success'; 58 | }); 59 | break; 60 | case BluetoothManager.DISCONNECTED: 61 | setState(() { 62 | _connected = false; 63 | tips = 'disconnect success'; 64 | }); 65 | break; 66 | default: 67 | break; 68 | } 69 | }); 70 | 71 | if (!mounted) return; 72 | 73 | if (isConnected) { 74 | setState(() { 75 | _connected = true; 76 | }); 77 | } 78 | } 79 | 80 | void _onConnect() async { 81 | if (_device != null && _device.address != null) { 82 | await bluetoothManager.connect(_device); 83 | } else { 84 | setState(() { 85 | tips = 'please select device'; 86 | }); 87 | print('please select device'); 88 | } 89 | } 90 | 91 | void _onDisconnect() async { 92 | await bluetoothManager.disconnect(); 93 | } 94 | 95 | void _sendData() async { 96 | List bytes = latin1.encode('Hello world!\n\n\n').toList(); 97 | 98 | // Set codetable west. Add import 'dart:typed_data'; 99 | // List bytes = Uint8List.fromList(List.from('\x1Bt'.codeUnits)..add(6)); 100 | // Text with special characters 101 | // bytes += latin1.encode('blåbærgrød\n\n\n'); 102 | 103 | await bluetoothManager.writeData(bytes); 104 | } 105 | 106 | @override 107 | Widget build(BuildContext context) { 108 | return Scaffold( 109 | appBar: AppBar( 110 | title: Text(widget.title), 111 | ), 112 | body: RefreshIndicator( 113 | onRefresh: () => 114 | bluetoothManager.startScan(timeout: Duration(seconds: 4)), 115 | child: SingleChildScrollView( 116 | child: Column( 117 | children: [ 118 | Row( 119 | mainAxisAlignment: MainAxisAlignment.center, 120 | children: [ 121 | Padding( 122 | padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10), 123 | child: Text(tips), 124 | ), 125 | ], 126 | ), 127 | Divider(), 128 | StreamBuilder>( 129 | stream: bluetoothManager.scanResults, 130 | initialData: [], 131 | builder: (c, snapshot) => Column( 132 | children: snapshot.data 133 | .map((d) => ListTile( 134 | title: Text(d.name ?? ''), 135 | subtitle: Text(d.address), 136 | onTap: () async { 137 | setState(() { 138 | _device = d; 139 | }); 140 | }, 141 | trailing: 142 | _device != null && _device.address == d.address 143 | ? Icon( 144 | Icons.check, 145 | color: Colors.green, 146 | ) 147 | : null, 148 | )) 149 | .toList(), 150 | ), 151 | ), 152 | Divider(), 153 | Container( 154 | padding: EdgeInsets.fromLTRB(20, 5, 20, 10), 155 | child: Column( 156 | children: [ 157 | Row( 158 | mainAxisAlignment: MainAxisAlignment.center, 159 | children: [ 160 | OutlineButton( 161 | child: Text('connect'), 162 | onPressed: _connected ? null : _onConnect, 163 | ), 164 | SizedBox(width: 10.0), 165 | OutlineButton( 166 | child: Text('disconnect'), 167 | onPressed: _connected ? _onDisconnect : null, 168 | ), 169 | ], 170 | ), 171 | OutlineButton( 172 | child: Text('Send test data'), 173 | onPressed: _connected ? _sendData : null, 174 | ), 175 | ], 176 | ), 177 | ) 178 | ], 179 | ), 180 | ), 181 | ), 182 | floatingActionButton: StreamBuilder( 183 | stream: bluetoothManager.isScanning, 184 | initialData: false, 185 | builder: (c, snapshot) { 186 | if (snapshot.data) { 187 | return FloatingActionButton( 188 | child: Icon(Icons.stop), 189 | onPressed: () => bluetoothManager.stopScan(), 190 | backgroundColor: Colors.red, 191 | ); 192 | } else { 193 | return FloatingActionButton( 194 | child: Icon(Icons.search), 195 | onPressed: () => 196 | bluetoothManager.startScan(timeout: Duration(seconds: 4))); 197 | } 198 | }, 199 | ), 200 | ); 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /example/pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "2.8.2" 11 | boolean_selector: 12 | dependency: transitive 13 | description: 14 | name: boolean_selector 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "2.1.0" 18 | characters: 19 | dependency: transitive 20 | description: 21 | name: characters 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "1.2.0" 25 | charcode: 26 | dependency: transitive 27 | description: 28 | name: charcode 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "1.3.1" 32 | clock: 33 | dependency: transitive 34 | description: 35 | name: clock 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "1.1.0" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.15.0" 46 | cupertino_icons: 47 | dependency: "direct main" 48 | description: 49 | name: cupertino_icons 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "0.1.3" 53 | fake_async: 54 | dependency: transitive 55 | description: 56 | name: fake_async 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "1.2.0" 60 | ffi: 61 | dependency: transitive 62 | description: 63 | name: ffi 64 | url: "https://pub.dartlang.org" 65 | source: hosted 66 | version: "1.1.2" 67 | file: 68 | dependency: transitive 69 | description: 70 | name: file 71 | url: "https://pub.dartlang.org" 72 | source: hosted 73 | version: "6.1.2" 74 | flutter: 75 | dependency: "direct main" 76 | description: flutter 77 | source: sdk 78 | version: "0.0.0" 79 | flutter_bluetooth_basic: 80 | dependency: "direct dev" 81 | description: 82 | path: ".." 83 | relative: true 84 | source: path 85 | version: "0.1.5" 86 | flutter_test: 87 | dependency: "direct dev" 88 | description: flutter 89 | source: sdk 90 | version: "0.0.0" 91 | json_annotation: 92 | dependency: transitive 93 | description: 94 | name: json_annotation 95 | url: "https://pub.dartlang.org" 96 | source: hosted 97 | version: "3.1.1" 98 | matcher: 99 | dependency: transitive 100 | description: 101 | name: matcher 102 | url: "https://pub.dartlang.org" 103 | source: hosted 104 | version: "0.12.11" 105 | meta: 106 | dependency: transitive 107 | description: 108 | name: meta 109 | url: "https://pub.dartlang.org" 110 | source: hosted 111 | version: "1.7.0" 112 | path: 113 | dependency: transitive 114 | description: 115 | name: path 116 | url: "https://pub.dartlang.org" 117 | source: hosted 118 | version: "1.8.0" 119 | path_provider: 120 | dependency: "direct main" 121 | description: 122 | name: path_provider 123 | url: "https://pub.dartlang.org" 124 | source: hosted 125 | version: "1.6.28" 126 | path_provider_linux: 127 | dependency: transitive 128 | description: 129 | name: path_provider_linux 130 | url: "https://pub.dartlang.org" 131 | source: hosted 132 | version: "0.0.1+2" 133 | path_provider_macos: 134 | dependency: transitive 135 | description: 136 | name: path_provider_macos 137 | url: "https://pub.dartlang.org" 138 | source: hosted 139 | version: "0.0.4+8" 140 | path_provider_platform_interface: 141 | dependency: transitive 142 | description: 143 | name: path_provider_platform_interface 144 | url: "https://pub.dartlang.org" 145 | source: hosted 146 | version: "1.0.4" 147 | path_provider_windows: 148 | dependency: transitive 149 | description: 150 | name: path_provider_windows 151 | url: "https://pub.dartlang.org" 152 | source: hosted 153 | version: "0.0.5" 154 | platform: 155 | dependency: transitive 156 | description: 157 | name: platform 158 | url: "https://pub.dartlang.org" 159 | source: hosted 160 | version: "3.0.2" 161 | plugin_platform_interface: 162 | dependency: transitive 163 | description: 164 | name: plugin_platform_interface 165 | url: "https://pub.dartlang.org" 166 | source: hosted 167 | version: "1.0.3" 168 | process: 169 | dependency: transitive 170 | description: 171 | name: process 172 | url: "https://pub.dartlang.org" 173 | source: hosted 174 | version: "4.2.3" 175 | rxdart: 176 | dependency: transitive 177 | description: 178 | name: rxdart 179 | url: "https://pub.dartlang.org" 180 | source: hosted 181 | version: "0.26.0" 182 | sky_engine: 183 | dependency: transitive 184 | description: flutter 185 | source: sdk 186 | version: "0.0.99" 187 | source_span: 188 | dependency: transitive 189 | description: 190 | name: source_span 191 | url: "https://pub.dartlang.org" 192 | source: hosted 193 | version: "1.8.1" 194 | stack_trace: 195 | dependency: transitive 196 | description: 197 | name: stack_trace 198 | url: "https://pub.dartlang.org" 199 | source: hosted 200 | version: "1.10.0" 201 | stream_channel: 202 | dependency: transitive 203 | description: 204 | name: stream_channel 205 | url: "https://pub.dartlang.org" 206 | source: hosted 207 | version: "2.1.0" 208 | string_scanner: 209 | dependency: transitive 210 | description: 211 | name: string_scanner 212 | url: "https://pub.dartlang.org" 213 | source: hosted 214 | version: "1.1.0" 215 | term_glyph: 216 | dependency: transitive 217 | description: 218 | name: term_glyph 219 | url: "https://pub.dartlang.org" 220 | source: hosted 221 | version: "1.2.0" 222 | test_api: 223 | dependency: transitive 224 | description: 225 | name: test_api 226 | url: "https://pub.dartlang.org" 227 | source: hosted 228 | version: "0.4.3" 229 | typed_data: 230 | dependency: transitive 231 | description: 232 | name: typed_data 233 | url: "https://pub.dartlang.org" 234 | source: hosted 235 | version: "1.3.0" 236 | vector_math: 237 | dependency: transitive 238 | description: 239 | name: vector_math 240 | url: "https://pub.dartlang.org" 241 | source: hosted 242 | version: "2.1.0" 243 | win32: 244 | dependency: transitive 245 | description: 246 | name: win32 247 | url: "https://pub.dartlang.org" 248 | source: hosted 249 | version: "2.2.9" 250 | xdg_directories: 251 | dependency: transitive 252 | description: 253 | name: xdg_directories 254 | url: "https://pub.dartlang.org" 255 | source: hosted 256 | version: "0.1.2" 257 | sdks: 258 | dart: ">=2.13.0 <3.0.0" 259 | flutter: ">=1.20.0" 260 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_bluetooth_basic_example 2 | description: Demonstrates how to use the flutter_bluetooth_basic plugin. 3 | publish_to: 'none' 4 | 5 | environment: 6 | sdk: ">=2.1.0 <3.0.0" 7 | 8 | dependencies: 9 | flutter: 10 | sdk: flutter 11 | cupertino_icons: ^0.1.2 12 | path_provider: ^1.4.5 13 | 14 | dev_dependencies: 15 | flutter_test: 16 | sdk: flutter 17 | 18 | flutter_bluetooth_basic: 19 | path: ../ 20 | 21 | flutter: 22 | uses-material-design: true 23 | -------------------------------------------------------------------------------- /example/test/widget_test.dart: -------------------------------------------------------------------------------- 1 | // This is a basic Flutter widget test. 2 | // 3 | // To perform an interaction with a widget in your test, use the WidgetTester 4 | // utility that Flutter provides. For example, you can send tap and scroll 5 | // gestures. You can also use WidgetTester to find child widgets in the widget 6 | // tree, read text, and verify that the values of widget properties are correct. 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_test/flutter_test.dart'; 10 | 11 | import 'package:flutter_bluetooth_basic_example/main.dart'; 12 | 13 | void main() { 14 | testWidgets('Verify Platform version', (WidgetTester tester) async { 15 | // Build our app and trigger a frame. 16 | await tester.pumpWidget(MyApp()); 17 | 18 | // Verify that platform version is retrieved. 19 | expect( 20 | find.byWidgetPredicate( 21 | (Widget widget) => widget is Text && 22 | widget.data.startsWith('Running on:'), 23 | ), 24 | findsOneWidget, 25 | ); 26 | }); 27 | } 28 | -------------------------------------------------------------------------------- /flutter_bluetooth_basic.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /ios/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vagrant/ 3 | .sconsign.dblite 4 | .svn/ 5 | 6 | .DS_Store 7 | *.swp 8 | profile 9 | 10 | DerivedData/ 11 | build/ 12 | GeneratedPluginRegistrant.h 13 | GeneratedPluginRegistrant.m 14 | 15 | .generated/ 16 | 17 | *.pbxuser 18 | *.mode1v3 19 | *.mode2v3 20 | *.perspectivev3 21 | 22 | !default.pbxuser 23 | !default.mode1v3 24 | !default.mode2v3 25 | !default.perspectivev3 26 | 27 | xcuserdata 28 | 29 | *.moved-aside 30 | 31 | *.pyc 32 | *sync/ 33 | Icon? 34 | .tags* 35 | 36 | /Flutter/Generated.xcconfig 37 | /Flutter/flutter_export_environment.sh -------------------------------------------------------------------------------- /ios/Assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/ios/Assets/.gitkeep -------------------------------------------------------------------------------- /ios/Classes/BLEConnecter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Connecter.h 3 | // GSDK 4 | // 5 | 6 | #import "Connecter.h" 7 | #import 8 | 9 | @interface BLEConnecter :Connecter 10 | 11 | @property(nonatomic,strong)CBCharacteristic *airPatchChar; 12 | @property(nonatomic,strong)CBCharacteristic *transparentDataWriteChar; 13 | @property(nonatomic,strong)CBCharacteristic *transparentDataReadOrNotifyChar; 14 | @property(nonatomic,strong)CBCharacteristic *connectionParameterChar; 15 | 16 | @property(nonatomic,strong)CBUUID *transServiceUUID; 17 | @property(nonatomic,strong)CBUUID *transTxUUID; 18 | @property(nonatomic,strong)CBUUID *transRxUUID; 19 | @property(nonatomic,strong)CBUUID *disUUID1; 20 | @property(nonatomic,strong)CBUUID *disUUID2; 21 | @property(nonatomic,strong)NSArray *serviceUUID; 22 | 23 | @property(nonatomic,copy)DiscoverDevice discover; 24 | @property(nonatomic,copy)UpdateState updateState; 25 | @property(nonatomic,copy)WriteProgress writeProgress; 26 | 27 | /**数据包大小,默认130个字节*/ 28 | @property(nonatomic,assign)NSUInteger datagramSize; 29 | 30 | @property(nonatomic,strong)CBPeripheral *connPeripheral; 31 | 32 | //+(instancetype)sharedInstance; 33 | 34 | /** 35 | * 方法说明:设置特定的Service UUID,以及Service对应的具有读、写特征值 36 | * @param serviceUUID 蓝牙模块的service uuid 37 | * @param txUUID 具有写入权限特征值 38 | * @param rxUUID 具有读取权限特征值 39 | */ 40 | - (void)configureTransparentServiceUUID: (NSString *)serviceUUID txUUID:(NSString *)txUUID rxUUID:(NSString *)rxUUID; 41 | 42 | /** 43 | * 方法说明:扫描外设 44 | * @param serviceUUIDs 需要连接的外设UUID 45 | * @param options 其它可选操作 46 | * @param discover 发现设备 47 | * peripheral 发现的外设 48 | * advertisementData 49 | * RSSI 外设信号强度 50 | */ 51 | -(void)scanForPeripheralsWithServices:(nullable NSArray *)serviceUUIDs options:(nullable NSDictionary *)options discover:(void(^_Nullable)(CBPeripheral *_Nullable peripheral,NSDictionary *_Nullable advertisementData,NSNumber *_Nullable RSSI))discover; 52 | 53 | /** 54 | * 方法说明:停止扫描蓝牙外设 55 | */ 56 | -(void)stopScan; 57 | 58 | /** 59 | * 方法说明:更新蓝牙状态 60 | * @param state 更新蓝牙状态 61 | */ 62 | -(void)didUpdateState:(void(^_Nullable)(NSInteger state))state; 63 | 64 | /** 65 | * 方法说明:连接外设 66 | * @param peripheral 需要连接的外设 67 | * @param options 其它可选操作 68 | * @param timeout 连接超时 69 | * @param connectState 连接状态 70 | */ 71 | -(void)connectPeripheral:(CBPeripheral *_Nullable)peripheral options:(nullable NSDictionary *)options timeout:(NSUInteger)timeout connectBlack:(void(^_Nullable)(ConnectState state)) connectState; 72 | 73 | /** 74 | * 方法说明:连接外设 75 | * @param peripheral 需要连接的外设 76 | * @param options 其它可选操作 77 | */ 78 | -(void)connectPeripheral:(CBPeripheral * _Nullable)peripheral options:(nullable NSDictionary *)options; 79 | 80 | /** 81 | * 方法说明:断开连接 82 | * @param peripheral 需要断开连接的外设 83 | */ 84 | -(void)closePeripheral:(nonnull CBPeripheral *)peripheral; 85 | 86 | /** 87 | * 方法说明: 往蓝牙模块中写入数据 // Method description: write data to Bluetooth module 88 | * @param data 往蓝牙模块中写入的数据 // Data written to the Bluetooth module 89 | * @param progress 写入数据的进度 // Progress of writing data 90 | * @param callBack 读取蓝牙模块返回数据 // Read Bluetooth module data 91 | */ 92 | -(void)write:(NSData *_Nullable)data progress:(void(^_Nullable)(NSUInteger total,NSUInteger progress))progress receCallBack:(void (^_Nullable)(NSData *_Nullable))callBack; 93 | 94 | /** 95 | * 方法说明: 往蓝牙模块中写入数据 // Method description: write data to Bluetooth module 96 | * @param characteristic 特征值 97 | * @param data 往蓝牙模块中写入的数据 // Data written to the Bluetooth module 98 | * @param type 写入方式CBCharacteristicWriteWithResponse写入方式是带流控写入方式。CBCharacteristicWriteWithoutResponse不带流控写入方式

@see CBCharacteristicWriteType

99 | * Writing method CBCharacteristicWriteWithResponse The writing method is a writing method with flow control. CBCharacteristicWriteWithoutResponseWithout flow control write method

@see CBCharacteristicWriteType

100 | */ 101 | -(void)writeValue:(NSData *)data forCharacteristic:(nonnull CBCharacteristic *)characteristic type:(CBCharacteristicWriteType)type; 102 | @end 103 | -------------------------------------------------------------------------------- /ios/Classes/Connecter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Connecter.h 3 | // GSDK 4 | // 5 | #import 6 | #import "ConnecterBlock.h" 7 | 8 | @interface Connecter:NSObject 9 | 10 | //读取数据 11 | @property(nonatomic,copy)ReadData readData; 12 | //连接状态 13 | @property(nonatomic,copy)ConnectDeviceState state; 14 | 15 | /** 16 | * 方法说明: 连接 // Method description: connect 17 | */ 18 | -(void)connect; 19 | 20 | /** 21 | * 方法说明: 连接到指定设备 // Method description: connect to the specified device 22 | * @param connectState 连接状态 23 | */ 24 | -(void)connect:(void(^)(ConnectState state))connectState; 25 | 26 | /** 27 | * 方法说明: 关闭连接 28 | */ 29 | -(void)close; 30 | 31 | /** 32 | * 发送数据 // send data 33 | * 向输出流中写入数据 // Write data to the output stream 34 | */ 35 | -(void)write:(NSData *)data receCallBack:(void(^)(NSData *data))callBack; 36 | -(void)write:(NSData *)data; 37 | 38 | /** 39 | * 读取数据 40 | * @parma data 读取到的数据 41 | */ 42 | -(void)read:(void(^)(NSData *data))data; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /ios/Classes/ConnecterBlock.h: -------------------------------------------------------------------------------- 1 | // 2 | // ConnecterBlock.h 3 | // GSDK 4 | // 5 | 6 | #ifndef ConnecterBlock_h 7 | #define ConnecterBlock_h 8 | #import 9 | 10 | /** 11 | * @enum ConnectState 12 | * @discussion 连接状态 13 | * @constant CONNECT_STATE_DISCONNECT ConnectDeviceState返回state为该状态是表示已断开连接 14 | * @constant CONNECT_STATE_CONNECTING ConnectDeviceState返回state为该状态是表示正在连接中 15 | * @constant CONNECT_STATE_CONNECTED ConnectDeviceState返回state为该状态是表示连接成功 16 | * @constant CONNECT_STATE_TIMEOUT ConnectDeviceState返回state为该状态是表示连接超时 17 | * @constant CONNECT_STATE_FAILT ConnectDeviceState返回state为该状态是表示连接失败 18 | */ 19 | typedef enum : NSUInteger { 20 | NOT_FOUND_DEVICE,//未找到设备 21 | CONNECT_STATE_DISCONNECT,//断开连接 22 | CONNECT_STATE_CONNECTING,//连接中 23 | CONNECT_STATE_CONNECTED,//连接上 24 | CONNECT_STATE_TIMEOUT,//连接超时 25 | CONNECT_STATE_FAILT//连接失败 26 | }ConnectState; 27 | 28 | /**发现设备 Discover devices*/ 29 | typedef void(^DiscoverDevice)(CBPeripheral *_Nullable peripheral,NSDictionary * _Nullable advertisementData,NSNumber * _Nullable RSSI); 30 | /**蓝牙状态更新 Bluetooth status update*/ 31 | typedef void(^UpdateState)(NSInteger state); 32 | /**连接状态 Connection Status*/ 33 | typedef void(^ConnectDeviceState)(ConnectState state); 34 | /**读取数据 Read data*/ 35 | typedef void(^ReadData)(NSData * _Nullable data); 36 | /**发送数据进度 只适用于蓝牙发送数据 Sending data progress ** Only for Bluetooth sending data*/ 37 | typedef void(^WriteProgress)(NSUInteger total,NSUInteger progress); 38 | typedef void (^Error)(id error); 39 | 40 | #endif /* ConnecterBlock_h */ 41 | -------------------------------------------------------------------------------- /ios/Classes/ConnecterManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // ConnecterManager.h 3 | // GSDK 4 | // 5 | 6 | #import 7 | #import "BLEConnecter.h" 8 | #import "EthernetConnecter.h" 9 | #import "Connecter.h" 10 | 11 | /** 12 | * @enum ConnectMethod 13 | * @discussion 连接方式 14 | * @constant BLUETOOTH 蓝牙连接 15 | * @constant ETHERNET 网口连接(wifi连接) 16 | */ 17 | typedef enum : NSUInteger{ 18 | BLUETOOTH, 19 | ETHERNET 20 | }ConnectMethod; 21 | 22 | #define Manager [ConnecterManager sharedInstance] 23 | 24 | @interface ConnecterManager : NSObject 25 | @property(nonatomic,strong)BLEConnecter *bleConnecter; 26 | @property(nonatomic,strong)Connecter *connecter; 27 | 28 | +(instancetype)sharedInstance; 29 | 30 | /** 31 | * 方法说明:关闭连接 32 | */ 33 | -(void)close; 34 | 35 | /** 36 | * 方法说明: 向输出流中写入数据(只适用于蓝牙) // Method description: write data to the output stream (only for Bluetooth) 37 | * @param data 需要写入的数据 38 | * @param progress 写入数据进度 39 | * @param callBack 读取输入流中的数据 40 | */ 41 | -(void)write:(NSData *_Nullable)data progress:(void(^_Nullable)(NSUInteger total,NSUInteger progress))progress receCallBack:(void (^_Nullable)(NSData *_Nullable))callBack; 42 | 43 | /** 44 | * 方法说明:向输出流中写入数据 // Method description: writing data to the output stream 45 | * @param callBack 读取数据接口 46 | */ 47 | -(void)write:(NSData *)data receCallBack:(void (^)(NSData *))callBack; 48 | 49 | /** 50 | * 方法说明:向输出流中写入数据 // Method description: writing data to the output stream 51 | * @param data 需要写入的数据 52 | */ 53 | -(void)write:(NSData *)data; 54 | 55 | /** 56 | * 方法说明:停止扫描 57 | */ 58 | -(void)stopScan; 59 | 60 | /** 61 | * 方法说明:更新蓝牙状态 62 | * @param state 蓝牙状态 63 | */ 64 | -(void)didUpdateState:(void(^)(NSInteger state))state; 65 | 66 | /** 67 | * 方法说明:连接外设 68 | * @param peripheral 需连接的外设 69 | * @param options 其它可选操作 70 | * @param timeout 连接时间 71 | * @param connectState 连接状态 72 | */ 73 | -(void)connectPeripheral:(CBPeripheral *)peripheral options:(nullable NSDictionary *)options timeout:(NSUInteger)timeout connectBlack:(void(^_Nullable)(ConnectState state)) connectState; 74 | 75 | /** 76 | * 方法说明:连接外设 77 | * @param peripheral 需连接的外设 78 | * @param options 其它可选操作 79 | */ 80 | -(void)connectPeripheral:(CBPeripheral * _Nullable)peripheral options:(nullable NSDictionary *)options; 81 | 82 | /** 83 | * 方法说明:扫描外设 84 | * @param serviceUUIDs 需要发现外设的UUID,设置为nil则发现周围所有外设 85 | * @param options 其它可选操作 86 | * @param discover 发现的设备 87 | */ 88 | -(void)scanForPeripheralsWithServices:(nullable NSArray *)serviceUUIDs options:(nullable NSDictionary *)options discover:(void(^_Nullable)(CBPeripheral *_Nullable peripheral,NSDictionary *_Nullable advertisementData,NSNumber *_Nullable RSSI))discover; 89 | 90 | 91 | 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /ios/Classes/ConnecterManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // ConnecterManager.m 3 | // GSDK 4 | // 5 | // 6 | 7 | #import "ConnecterManager.h" 8 | 9 | @interface ConnecterManager(){ 10 | ConnectMethod currentConnMethod; 11 | } 12 | @end 13 | 14 | @implementation ConnecterManager 15 | 16 | static ConnecterManager *manager; 17 | static dispatch_once_t once; 18 | 19 | +(instancetype)sharedInstance { 20 | dispatch_once(&once, ^{ 21 | manager = [[ConnecterManager alloc]init]; 22 | }); 23 | return manager; 24 | } 25 | 26 | /** 27 | * 方法说明:扫描外设 28 | * @param serviceUUIDs 需要发现外设的UUID,设置为nil则发现周围所有外设 29 | * @param options 其它可选操作 30 | * @param discover 发现的设备 31 | */ 32 | -(void)scanForPeripheralsWithServices:(nullable NSArray *)serviceUUIDs options:(nullable NSDictionary *)options discover:(void(^_Nullable)(CBPeripheral *_Nullable peripheral,NSDictionary *_Nullable advertisementData,NSNumber *_Nullable RSSI))discover{ 33 | [_bleConnecter scanForPeripheralsWithServices:serviceUUIDs options:options discover:discover]; 34 | } 35 | 36 | /** 37 | * 方法说明:更新蓝牙状态 38 | * @param state 蓝牙状态 39 | */ 40 | -(void)didUpdateState:(void(^)(NSInteger state))state { 41 | if (_bleConnecter == nil) { 42 | currentConnMethod = BLUETOOTH; 43 | [self initConnecter:currentConnMethod]; 44 | } 45 | [_bleConnecter didUpdateState:state]; 46 | } 47 | 48 | -(void)initConnecter:(ConnectMethod)connectMethod { 49 | switch (connectMethod) { 50 | case BLUETOOTH: 51 | _bleConnecter = [BLEConnecter new]; 52 | _connecter = _bleConnecter; 53 | break; 54 | default: 55 | break; 56 | } 57 | } 58 | 59 | /** 60 | * 方法说明:停止扫描 61 | */ 62 | -(void)stopScan { 63 | [_bleConnecter stopScan]; 64 | } 65 | 66 | /** 67 | * 连接 68 | */ 69 | -(void)connectPeripheral:(CBPeripheral *)peripheral options:(nullable NSDictionary *)options timeout:(NSUInteger)timeout connectBlack:(void(^_Nullable)(ConnectState state)) connectState{ 70 | [_bleConnecter connectPeripheral:peripheral options:options timeout:timeout connectBlack:connectState]; 71 | } 72 | 73 | -(void)connectPeripheral:(CBPeripheral * _Nullable)peripheral options:(nullable NSDictionary *)options { 74 | [_bleConnecter connectPeripheral:peripheral options:options]; 75 | } 76 | 77 | -(void)write:(NSData *_Nullable)data progress:(void(^_Nullable)(NSUInteger total,NSUInteger progress))progress receCallBack:(void (^_Nullable)(NSData *_Nullable))callBack { 78 | [_bleConnecter write:data progress:progress receCallBack:callBack]; 79 | } 80 | 81 | -(void)write:(NSData *)data receCallBack:(void (^)(NSData *))callBack { 82 | #ifdef DEBUG 83 | NSLog(@"[ConnecterManager] write:receCallBack:"); 84 | #endif 85 | _bleConnecter.writeProgress = nil; 86 | [_connecter write:data receCallBack:callBack]; 87 | } 88 | 89 | -(void)write:(NSData *)data { 90 | #ifdef DEBUG 91 | NSLog(@"[ConnecterManager] write:"); 92 | #endif 93 | _bleConnecter.writeProgress = nil; 94 | [_connecter write:data]; 95 | } 96 | 97 | -(void)close { 98 | if (_connecter) { 99 | [_connecter close]; 100 | } 101 | switch (currentConnMethod) { 102 | case BLUETOOTH: 103 | _bleConnecter = nil; 104 | break; 105 | } 106 | } 107 | 108 | @end 109 | -------------------------------------------------------------------------------- /ios/Classes/EthernetConnecter.h: -------------------------------------------------------------------------------- 1 | // 2 | // EthernetConnecter.h 3 | // GSDK 4 | // 5 | 6 | #import "Connecter.h" 7 | 8 | @interface EthernetConnecter :Connecter 9 | /**连接设备的ip地址*/ 10 | @property(nonatomic,strong)NSString *ip; 11 | /**连接设备的端口号*/ 12 | @property(nonatomic,assign)int port; 13 | 14 | //+(instancetype)sharedInstance; 15 | 16 | /** 17 | * 方法说明: 连接设备 18 | * @param ip 连接设备的ip地址 19 | * @param port 连接设备的端口号 20 | * @param connectState 连接状态 @see ConnectState 21 | * @param callback 输入流数据回调 22 | */ 23 | -(void)connectIP:(NSString *)ip port:(int)port connectState:(void (^)(ConnectState state))connectState callback:(void(^)(NSData *data))callback; 24 | 25 | -(void)connectIP:(NSString *)ip port:(int)port connectState:(void (^)(ConnectState))connectState; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /ios/Classes/FlutterBluetoothBasicPlugin.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import "ConnecterManager.h" 4 | 5 | #define NAMESPACE @"flutter_bluetooth_basic" 6 | 7 | @interface FlutterBluetoothBasicPlugin : NSObject 8 | @property(nonatomic,copy)ConnectDeviceState state; 9 | @end 10 | 11 | @interface BluetoothPrintStreamHandler : NSObject 12 | @property FlutterEventSink sink; 13 | @end 14 | -------------------------------------------------------------------------------- /ios/Classes/FlutterBluetoothBasicPlugin.m: -------------------------------------------------------------------------------- 1 | #import "FlutterBluetoothBasicPlugin.h" 2 | #import "ConnecterManager.h" 3 | 4 | @interface FlutterBluetoothBasicPlugin () 5 | @property(nonatomic, retain) NSObject *registrar; 6 | @property(nonatomic, retain) FlutterMethodChannel *channel; 7 | @property(nonatomic, retain) BluetoothPrintStreamHandler *stateStreamHandler; 8 | @property(nonatomic) NSMutableDictionary *scannedPeripherals; 9 | @end 10 | 11 | @implementation FlutterBluetoothBasicPlugin 12 | + (void)registerWithRegistrar:(NSObject*)registrar { 13 | FlutterMethodChannel* channel = [FlutterMethodChannel 14 | methodChannelWithName:NAMESPACE @"/methods" 15 | binaryMessenger:[registrar messenger]]; 16 | FlutterEventChannel* stateChannel = [FlutterEventChannel eventChannelWithName:NAMESPACE @"/state" binaryMessenger:[registrar messenger]]; 17 | FlutterBluetoothBasicPlugin* instance = [[FlutterBluetoothBasicPlugin alloc] init]; 18 | 19 | instance.channel = channel; 20 | instance.scannedPeripherals = [NSMutableDictionary new]; 21 | 22 | // STATE 23 | BluetoothPrintStreamHandler* stateStreamHandler = [[BluetoothPrintStreamHandler alloc] init]; 24 | [stateChannel setStreamHandler:stateStreamHandler]; 25 | instance.stateStreamHandler = stateStreamHandler; 26 | 27 | [registrar addMethodCallDelegate:instance channel:channel]; 28 | } 29 | 30 | - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { 31 | NSLog(@"call method -> %@", call.method); 32 | 33 | if ([@"state" isEqualToString:call.method]) { 34 | result(nil); 35 | } else if([@"isAvailable" isEqualToString:call.method]) { 36 | 37 | result(@(YES)); 38 | } else if([@"isConnected" isEqualToString:call.method]) { 39 | 40 | result(@(NO)); 41 | } else if([@"isOn" isEqualToString:call.method]) { 42 | result(@(YES)); 43 | }else if([@"startScan" isEqualToString:call.method]) { 44 | NSLog(@"getDevices method -> %@", call.method); 45 | [self.scannedPeripherals removeAllObjects]; 46 | 47 | if (Manager.bleConnecter == nil) { 48 | [Manager didUpdateState:^(NSInteger state) { 49 | switch (state) { 50 | case CBCentralManagerStateUnsupported: 51 | NSLog(@"The platform/hardware doesn't support Bluetooth Low Energy."); 52 | break; 53 | case CBCentralManagerStateUnauthorized: 54 | NSLog(@"The app is not authorized to use Bluetooth Low Energy."); 55 | break; 56 | case CBCentralManagerStatePoweredOff: 57 | NSLog(@"Bluetooth is currently powered off."); 58 | break; 59 | case CBCentralManagerStatePoweredOn: 60 | [self startScan]; 61 | NSLog(@"Bluetooth power on"); 62 | break; 63 | case CBCentralManagerStateUnknown: 64 | default: 65 | break; 66 | } 67 | }]; 68 | } else { 69 | [self startScan]; 70 | } 71 | 72 | result(nil); 73 | } else if([@"stopScan" isEqualToString:call.method]) { 74 | [Manager stopScan]; 75 | result(nil); 76 | } else if([@"connect" isEqualToString:call.method]) { 77 | NSDictionary *device = [call arguments]; 78 | @try { 79 | NSLog(@"connect device begin -> %@", [device objectForKey:@"name"]); 80 | CBPeripheral *peripheral = [_scannedPeripherals objectForKey:[device objectForKey:@"address"]]; 81 | 82 | self.state = ^(ConnectState state) { 83 | [self updateConnectState:state]; 84 | }; 85 | [Manager connectPeripheral:peripheral options:nil timeout:2 connectBlack: self.state]; 86 | 87 | result(nil); 88 | } @catch(FlutterError *e) { 89 | result(e); 90 | } 91 | } else if([@"disconnect" isEqualToString:call.method]) { 92 | @try { 93 | [Manager close]; 94 | result(nil); 95 | } @catch(FlutterError *e) { 96 | result(e); 97 | } 98 | } else if([@"writeData" isEqualToString:call.method]) { 99 | @try { 100 | NSDictionary *args = [call arguments]; 101 | 102 | NSMutableArray *bytes = [args objectForKey:@"bytes"]; 103 | 104 | NSNumber* lenBuf = [args objectForKey:@"length"]; 105 | int len = [lenBuf intValue]; 106 | char cArray[len]; 107 | 108 | for (int i = 0; i < len; ++i) { 109 | // NSLog(@"** ind_%d (d): %@, %d", i, bytes[i], [bytes[i] charValue]); 110 | cArray[i] = [bytes[i] charValue]; 111 | } 112 | NSData *data2 = [NSData dataWithBytes:cArray length:sizeof(cArray)]; 113 | // NSLog(@"bytes in hex: %@", [data2 description]); 114 | [Manager write:data2]; 115 | result(nil); 116 | } @catch(FlutterError *e) { 117 | result(e); 118 | } 119 | } 120 | } 121 | 122 | -(void)startScan { 123 | [Manager scanForPeripheralsWithServices:nil options:nil discover:^(CBPeripheral * _Nullable peripheral, NSDictionary * _Nullable advertisementData, NSNumber * _Nullable RSSI) { 124 | if (peripheral.name != nil) { 125 | 126 | NSLog(@"find device -> %@", peripheral.name); 127 | [self.scannedPeripherals setObject:peripheral forKey:[[peripheral identifier] UUIDString]]; 128 | 129 | NSDictionary *device = [NSDictionary dictionaryWithObjectsAndKeys:peripheral.identifier.UUIDString,@"address",peripheral.name,@"name",nil,@"type",nil]; 130 | [_channel invokeMethod:@"ScanResult" arguments:device]; 131 | } 132 | }]; 133 | 134 | } 135 | 136 | -(void)updateConnectState:(ConnectState)state { 137 | dispatch_async(dispatch_get_main_queue(), ^{ 138 | NSNumber *ret = @0; 139 | switch (state) { 140 | case CONNECT_STATE_CONNECTING: 141 | NSLog(@"status -> %@", @"Connecting ..."); 142 | ret = @0; 143 | break; 144 | case CONNECT_STATE_CONNECTED: 145 | NSLog(@"status -> %@", @"Connection success"); 146 | ret = @1; 147 | break; 148 | case CONNECT_STATE_FAILT: 149 | NSLog(@"status -> %@", @"Connection failed"); 150 | ret = @0; 151 | break; 152 | case CONNECT_STATE_DISCONNECT: 153 | NSLog(@"status -> %@", @"Disconnected"); 154 | ret = @0; 155 | break; 156 | default: 157 | NSLog(@"status -> %@", @"Connection timed out"); 158 | ret = @0; 159 | break; 160 | } 161 | 162 | NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:ret,@"id",nil]; 163 | if(_stateStreamHandler.sink != nil) { 164 | self.stateStreamHandler.sink([dict objectForKey:@"id"]); 165 | } 166 | }); 167 | } 168 | 169 | @end 170 | 171 | @implementation BluetoothPrintStreamHandler 172 | 173 | - (FlutterError*)onListenWithArguments:(id)arguments eventSink:(FlutterEventSink)eventSink { 174 | self.sink = eventSink; 175 | return nil; 176 | } 177 | 178 | - (FlutterError*)onCancelWithArguments:(id)arguments { 179 | self.sink = nil; 180 | return nil; 181 | } 182 | 183 | @end 184 | -------------------------------------------------------------------------------- /ios/flutter_bluetooth_basic.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. 3 | # Run `pod lib lint flutter_bluetooth_basic.podspec' to validate before publishing. 4 | # 5 | Pod::Spec.new do |s| 6 | s.name = 'flutter_bluetooth_basic' 7 | s.version = '0.0.1' 8 | s.summary = 'A new flutter plugin project.' 9 | s.description = <<-DESC 10 | A new flutter plugin project. 11 | DESC 12 | s.homepage = 'http://example.com' 13 | s.license = { :file => '../LICENSE' } 14 | s.author = { 'Your Company' => 'email@example.com' } 15 | s.source = { :path => '.' } 16 | s.source_files = 'Classes/**/*' 17 | s.public_header_files = 'Classes/**/*.h' 18 | s.static_framework = true 19 | s.dependency 'Flutter' 20 | # s.platform = :ios, '8.0' 21 | 22 | # Import all * .a libraries in the Classes folder 23 | s.frameworks = ["SystemConfiguration", "CoreTelephony","WebKit"] 24 | s.vendored_libraries = '**/*.a' 25 | 26 | # Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported. 27 | # s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' } 28 | end 29 | -------------------------------------------------------------------------------- /ios/libGSDK.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-ushakov/flutter_bluetooth_basic/a7d60a3a77b8b3e3af2f3db86cde56fcb000949c/ios/libGSDK.a -------------------------------------------------------------------------------- /lib/flutter_bluetooth_basic.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * flutter_bluetooth_basic 3 | * Created by Andrey U. 4 | * 5 | * See LICENSE for distribution and usage details. 6 | */ 7 | library flutter_bluetooth_basic; 8 | 9 | export './src/bluetooth_manager.dart'; 10 | export './src/bluetooth_device.dart'; 11 | -------------------------------------------------------------------------------- /lib/src/bluetooth_device.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'bluetooth_device.g.dart'; 4 | 5 | @JsonSerializable(includeIfNull: false) 6 | class BluetoothDevice { 7 | BluetoothDevice(); 8 | 9 | String? name; 10 | String? address; 11 | int? type = 0; 12 | bool? connected = false; 13 | 14 | factory BluetoothDevice.fromJson(Map json) => 15 | _$BluetoothDeviceFromJson(json); 16 | Map toJson() => _$BluetoothDeviceToJson(this); 17 | } 18 | -------------------------------------------------------------------------------- /lib/src/bluetooth_device.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'bluetooth_device.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | BluetoothDevice _$BluetoothDeviceFromJson(Map json) { 10 | return BluetoothDevice() 11 | ..name = json['name'] as String? 12 | ..address = json['address'] as String? 13 | ..type = json['type'] as int? 14 | ..connected = json['connected'] as bool?; 15 | } 16 | 17 | Map _$BluetoothDeviceToJson(BluetoothDevice instance) { 18 | final val = {}; 19 | 20 | void writeNotNull(String key, dynamic value) { 21 | if (value != null) { 22 | val[key] = value; 23 | } 24 | } 25 | 26 | writeNotNull('name', instance.name); 27 | writeNotNull('address', instance.address); 28 | writeNotNull('type', instance.type); 29 | writeNotNull('connected', instance.connected); 30 | return val; 31 | } 32 | -------------------------------------------------------------------------------- /lib/src/bluetooth_manager.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/services.dart'; 4 | import 'package:rxdart/rxdart.dart'; 5 | 6 | import 'bluetooth_device.dart'; 7 | 8 | /// A BluetoothManager. 9 | class BluetoothManager { 10 | static const String NAMESPACE = 'flutter_bluetooth_basic'; 11 | static const int CONNECTED = 1; 12 | static const int DISCONNECTED = 0; 13 | 14 | static const MethodChannel _channel = 15 | const MethodChannel('$NAMESPACE/methods'); 16 | static const EventChannel _stateChannel = 17 | const EventChannel('$NAMESPACE/state'); 18 | Stream get _methodStream => _methodStreamController.stream; 19 | final StreamController _methodStreamController = 20 | StreamController.broadcast(); 21 | 22 | BluetoothManager._() { 23 | _channel.setMethodCallHandler((MethodCall call) { 24 | _methodStreamController.add(call); 25 | return Future(() => null); 26 | }); 27 | } 28 | 29 | static BluetoothManager _instance = BluetoothManager._(); 30 | 31 | static BluetoothManager get instance => _instance; 32 | 33 | // Future get isAvailable async => 34 | // await _channel.invokeMethod('isAvailable').then((d) => d); 35 | 36 | // Future get isOn async => 37 | // await _channel.invokeMethod('isOn').then((d) => d); 38 | 39 | Future get isConnected async => 40 | await _channel.invokeMethod('isConnected'); 41 | 42 | BehaviorSubject _isScanning = BehaviorSubject.seeded(false); 43 | Stream get isScanning => _isScanning.stream; 44 | 45 | BehaviorSubject> _scanResults = 46 | BehaviorSubject.seeded([]); 47 | Stream> get scanResults => _scanResults.stream; 48 | 49 | PublishSubject _stopScanPill = new PublishSubject(); 50 | 51 | /// Gets the current state of the Bluetooth module 52 | Stream get state async* { 53 | yield await _channel.invokeMethod('state').then((s) => s); 54 | 55 | yield* _stateChannel.receiveBroadcastStream().map((s) => s); 56 | } 57 | 58 | /// Starts a scan for Bluetooth Low Energy devices 59 | /// Timeout closes the stream after a specified [Duration] 60 | Stream scan({ 61 | Duration? timeout, 62 | }) async* { 63 | if (_isScanning.value == true) { 64 | throw Exception('Another scan is already in progress.'); 65 | } 66 | 67 | // Emit to isScanning 68 | _isScanning.add(true); 69 | 70 | final killStreams = []; 71 | killStreams.add(_stopScanPill); 72 | if (timeout != null) { 73 | killStreams.add(Rx.timer(null, timeout)); 74 | } 75 | 76 | // Clear scan results list 77 | _scanResults.add([]); 78 | 79 | try { 80 | await _channel.invokeMethod('startScan'); 81 | } catch (e) { 82 | print('Error starting scan.'); 83 | _stopScanPill.add(null); 84 | _isScanning.add(false); 85 | throw e; 86 | } 87 | 88 | yield* BluetoothManager.instance._methodStream 89 | .where((m) => m.method == "ScanResult") 90 | .map((m) => m.arguments) 91 | .takeUntil(Rx.merge(killStreams)) 92 | .doOnDone(stopScan) 93 | .map((map) { 94 | final device = BluetoothDevice.fromJson(Map.from(map)); 95 | final List? list = _scanResults.value; 96 | int newIndex = -1; 97 | list!.asMap().forEach((index, e) { 98 | if (e.address == device.address) { 99 | newIndex = index; 100 | } 101 | }); 102 | 103 | if (newIndex != -1) { 104 | list[newIndex] = device; 105 | } else { 106 | list.add(device); 107 | } 108 | _scanResults.add(list); 109 | return device; 110 | }); 111 | } 112 | 113 | Future startScan({ 114 | Duration? timeout, 115 | }) async { 116 | await scan(timeout: timeout).drain(); 117 | return _scanResults.value; 118 | } 119 | 120 | /// Stops a scan for Bluetooth Low Energy devices 121 | Future stopScan() async { 122 | await _channel.invokeMethod('stopScan'); 123 | _stopScanPill.add(null); 124 | _isScanning.add(false); 125 | } 126 | 127 | Future connect(BluetoothDevice device) => 128 | _channel.invokeMethod('connect', device.toJson()); 129 | 130 | Future disconnect() => _channel.invokeMethod('disconnect'); 131 | 132 | Future destroy() => _channel.invokeMethod('destroy'); 133 | 134 | Future writeData(List bytes) { 135 | Map args = Map(); 136 | args['bytes'] = bytes; 137 | args['length'] = bytes.length; 138 | 139 | _channel.invokeMethod('writeData', args); 140 | 141 | return Future.value(true); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | _fe_analyzer_shared: 5 | dependency: transitive 6 | description: 7 | name: _fe_analyzer_shared 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "14.0.0" 11 | analyzer: 12 | dependency: transitive 13 | description: 14 | name: analyzer 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "0.41.2" 18 | args: 19 | dependency: transitive 20 | description: 21 | name: args 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.3.0" 25 | async: 26 | dependency: transitive 27 | description: 28 | name: async 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "2.8.2" 32 | boolean_selector: 33 | dependency: transitive 34 | description: 35 | name: boolean_selector 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "2.1.0" 39 | build: 40 | dependency: transitive 41 | description: 42 | name: build 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.6.2" 46 | build_config: 47 | dependency: transitive 48 | description: 49 | name: build_config 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "0.4.6" 53 | build_daemon: 54 | dependency: transitive 55 | description: 56 | name: build_daemon 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "2.1.10" 60 | build_resolvers: 61 | dependency: transitive 62 | description: 63 | name: build_resolvers 64 | url: "https://pub.dartlang.org" 65 | source: hosted 66 | version: "1.5.3" 67 | build_runner: 68 | dependency: "direct dev" 69 | description: 70 | name: build_runner 71 | url: "https://pub.dartlang.org" 72 | source: hosted 73 | version: "1.11.5" 74 | build_runner_core: 75 | dependency: transitive 76 | description: 77 | name: build_runner_core 78 | url: "https://pub.dartlang.org" 79 | source: hosted 80 | version: "6.1.10" 81 | built_collection: 82 | dependency: transitive 83 | description: 84 | name: built_collection 85 | url: "https://pub.dartlang.org" 86 | source: hosted 87 | version: "5.1.1" 88 | built_value: 89 | dependency: transitive 90 | description: 91 | name: built_value 92 | url: "https://pub.dartlang.org" 93 | source: hosted 94 | version: "8.1.2" 95 | characters: 96 | dependency: transitive 97 | description: 98 | name: characters 99 | url: "https://pub.dartlang.org" 100 | source: hosted 101 | version: "1.2.0" 102 | charcode: 103 | dependency: transitive 104 | description: 105 | name: charcode 106 | url: "https://pub.dartlang.org" 107 | source: hosted 108 | version: "1.3.1" 109 | checked_yaml: 110 | dependency: transitive 111 | description: 112 | name: checked_yaml 113 | url: "https://pub.dartlang.org" 114 | source: hosted 115 | version: "1.0.4" 116 | cli_util: 117 | dependency: transitive 118 | description: 119 | name: cli_util 120 | url: "https://pub.dartlang.org" 121 | source: hosted 122 | version: "0.3.3" 123 | clock: 124 | dependency: transitive 125 | description: 126 | name: clock 127 | url: "https://pub.dartlang.org" 128 | source: hosted 129 | version: "1.1.0" 130 | code_builder: 131 | dependency: transitive 132 | description: 133 | name: code_builder 134 | url: "https://pub.dartlang.org" 135 | source: hosted 136 | version: "3.7.0" 137 | collection: 138 | dependency: transitive 139 | description: 140 | name: collection 141 | url: "https://pub.dartlang.org" 142 | source: hosted 143 | version: "1.15.0" 144 | convert: 145 | dependency: transitive 146 | description: 147 | name: convert 148 | url: "https://pub.dartlang.org" 149 | source: hosted 150 | version: "3.0.1" 151 | crypto: 152 | dependency: transitive 153 | description: 154 | name: crypto 155 | url: "https://pub.dartlang.org" 156 | source: hosted 157 | version: "3.0.1" 158 | dart_style: 159 | dependency: transitive 160 | description: 161 | name: dart_style 162 | url: "https://pub.dartlang.org" 163 | source: hosted 164 | version: "1.3.12" 165 | fake_async: 166 | dependency: transitive 167 | description: 168 | name: fake_async 169 | url: "https://pub.dartlang.org" 170 | source: hosted 171 | version: "1.2.0" 172 | file: 173 | dependency: transitive 174 | description: 175 | name: file 176 | url: "https://pub.dartlang.org" 177 | source: hosted 178 | version: "6.1.2" 179 | fixnum: 180 | dependency: transitive 181 | description: 182 | name: fixnum 183 | url: "https://pub.dartlang.org" 184 | source: hosted 185 | version: "1.0.0" 186 | flutter: 187 | dependency: "direct main" 188 | description: flutter 189 | source: sdk 190 | version: "0.0.0" 191 | flutter_test: 192 | dependency: "direct dev" 193 | description: flutter 194 | source: sdk 195 | version: "0.0.0" 196 | glob: 197 | dependency: transitive 198 | description: 199 | name: glob 200 | url: "https://pub.dartlang.org" 201 | source: hosted 202 | version: "2.0.1" 203 | graphs: 204 | dependency: transitive 205 | description: 206 | name: graphs 207 | url: "https://pub.dartlang.org" 208 | source: hosted 209 | version: "0.2.0" 210 | http_multi_server: 211 | dependency: transitive 212 | description: 213 | name: http_multi_server 214 | url: "https://pub.dartlang.org" 215 | source: hosted 216 | version: "2.2.0" 217 | http_parser: 218 | dependency: transitive 219 | description: 220 | name: http_parser 221 | url: "https://pub.dartlang.org" 222 | source: hosted 223 | version: "4.0.0" 224 | io: 225 | dependency: transitive 226 | description: 227 | name: io 228 | url: "https://pub.dartlang.org" 229 | source: hosted 230 | version: "0.3.5" 231 | js: 232 | dependency: transitive 233 | description: 234 | name: js 235 | url: "https://pub.dartlang.org" 236 | source: hosted 237 | version: "0.6.3" 238 | json_annotation: 239 | dependency: "direct main" 240 | description: 241 | name: json_annotation 242 | url: "https://pub.dartlang.org" 243 | source: hosted 244 | version: "3.1.1" 245 | json_serializable: 246 | dependency: "direct dev" 247 | description: 248 | name: json_serializable 249 | url: "https://pub.dartlang.org" 250 | source: hosted 251 | version: "3.5.1" 252 | logging: 253 | dependency: transitive 254 | description: 255 | name: logging 256 | url: "https://pub.dartlang.org" 257 | source: hosted 258 | version: "1.0.2" 259 | matcher: 260 | dependency: transitive 261 | description: 262 | name: matcher 263 | url: "https://pub.dartlang.org" 264 | source: hosted 265 | version: "0.12.11" 266 | meta: 267 | dependency: transitive 268 | description: 269 | name: meta 270 | url: "https://pub.dartlang.org" 271 | source: hosted 272 | version: "1.7.0" 273 | mime: 274 | dependency: transitive 275 | description: 276 | name: mime 277 | url: "https://pub.dartlang.org" 278 | source: hosted 279 | version: "1.0.0" 280 | package_config: 281 | dependency: transitive 282 | description: 283 | name: package_config 284 | url: "https://pub.dartlang.org" 285 | source: hosted 286 | version: "1.9.3" 287 | path: 288 | dependency: transitive 289 | description: 290 | name: path 291 | url: "https://pub.dartlang.org" 292 | source: hosted 293 | version: "1.8.0" 294 | pedantic: 295 | dependency: transitive 296 | description: 297 | name: pedantic 298 | url: "https://pub.dartlang.org" 299 | source: hosted 300 | version: "1.11.1" 301 | pool: 302 | dependency: transitive 303 | description: 304 | name: pool 305 | url: "https://pub.dartlang.org" 306 | source: hosted 307 | version: "1.5.0" 308 | pub_semver: 309 | dependency: transitive 310 | description: 311 | name: pub_semver 312 | url: "https://pub.dartlang.org" 313 | source: hosted 314 | version: "2.1.0" 315 | pubspec_parse: 316 | dependency: transitive 317 | description: 318 | name: pubspec_parse 319 | url: "https://pub.dartlang.org" 320 | source: hosted 321 | version: "0.1.8" 322 | rxdart: 323 | dependency: "direct main" 324 | description: 325 | name: rxdart 326 | url: "https://pub.dartlang.org" 327 | source: hosted 328 | version: "0.26.0" 329 | shelf: 330 | dependency: transitive 331 | description: 332 | name: shelf 333 | url: "https://pub.dartlang.org" 334 | source: hosted 335 | version: "1.2.0" 336 | shelf_web_socket: 337 | dependency: transitive 338 | description: 339 | name: shelf_web_socket 340 | url: "https://pub.dartlang.org" 341 | source: hosted 342 | version: "0.2.4+1" 343 | sky_engine: 344 | dependency: transitive 345 | description: flutter 346 | source: sdk 347 | version: "0.0.99" 348 | source_gen: 349 | dependency: transitive 350 | description: 351 | name: source_gen 352 | url: "https://pub.dartlang.org" 353 | source: hosted 354 | version: "0.9.10+3" 355 | source_span: 356 | dependency: transitive 357 | description: 358 | name: source_span 359 | url: "https://pub.dartlang.org" 360 | source: hosted 361 | version: "1.8.1" 362 | stack_trace: 363 | dependency: transitive 364 | description: 365 | name: stack_trace 366 | url: "https://pub.dartlang.org" 367 | source: hosted 368 | version: "1.10.0" 369 | stream_channel: 370 | dependency: transitive 371 | description: 372 | name: stream_channel 373 | url: "https://pub.dartlang.org" 374 | source: hosted 375 | version: "2.1.0" 376 | stream_transform: 377 | dependency: transitive 378 | description: 379 | name: stream_transform 380 | url: "https://pub.dartlang.org" 381 | source: hosted 382 | version: "2.0.0" 383 | string_scanner: 384 | dependency: transitive 385 | description: 386 | name: string_scanner 387 | url: "https://pub.dartlang.org" 388 | source: hosted 389 | version: "1.1.0" 390 | term_glyph: 391 | dependency: transitive 392 | description: 393 | name: term_glyph 394 | url: "https://pub.dartlang.org" 395 | source: hosted 396 | version: "1.2.0" 397 | test_api: 398 | dependency: transitive 399 | description: 400 | name: test_api 401 | url: "https://pub.dartlang.org" 402 | source: hosted 403 | version: "0.4.3" 404 | timing: 405 | dependency: transitive 406 | description: 407 | name: timing 408 | url: "https://pub.dartlang.org" 409 | source: hosted 410 | version: "0.1.1+3" 411 | typed_data: 412 | dependency: transitive 413 | description: 414 | name: typed_data 415 | url: "https://pub.dartlang.org" 416 | source: hosted 417 | version: "1.3.0" 418 | vector_math: 419 | dependency: transitive 420 | description: 421 | name: vector_math 422 | url: "https://pub.dartlang.org" 423 | source: hosted 424 | version: "2.1.0" 425 | watcher: 426 | dependency: transitive 427 | description: 428 | name: watcher 429 | url: "https://pub.dartlang.org" 430 | source: hosted 431 | version: "1.0.0" 432 | web_socket_channel: 433 | dependency: transitive 434 | description: 435 | name: web_socket_channel 436 | url: "https://pub.dartlang.org" 437 | source: hosted 438 | version: "1.2.0" 439 | yaml: 440 | dependency: transitive 441 | description: 442 | name: yaml 443 | url: "https://pub.dartlang.org" 444 | source: hosted 445 | version: "3.1.0" 446 | sdks: 447 | dart: ">=2.12.0 <3.0.0" 448 | flutter: ">=1.12.0" 449 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_bluetooth_basic 2 | description: Flutter plugin that allows to find bluetooth devices & send raw bytes data 3 | version: 0.1.7 4 | homepage: https://github.com/andrey-ushakov/flutter_bluetooth_basic 5 | 6 | environment: 7 | sdk: ">=2.12.0 <3.0.0" 8 | flutter: ">=1.12.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | json_annotation: ^4.1.0 14 | rxdart: ^0.26.0 15 | 16 | dev_dependencies: 17 | flutter_test: 18 | sdk: flutter 19 | build_runner: ^1.0.0 20 | json_serializable: ^3.2.2 21 | 22 | flutter: 23 | plugin: 24 | platforms: 25 | android: 26 | package: com.tablemi.flutter_bluetooth_basic 27 | pluginClass: FlutterBluetoothBasicPlugin 28 | ios: 29 | pluginClass: FlutterBluetoothBasicPlugin 30 | -------------------------------------------------------------------------------- /test/flutter_bluetooth_basic_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/services.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_bluetooth_basic/flutter_bluetooth_basic.dart'; 4 | 5 | void main() { 6 | const MethodChannel channel = MethodChannel('flutter_bluetooth_basic'); 7 | 8 | TestWidgetsFlutterBinding.ensureInitialized(); 9 | 10 | setUp(() { 11 | channel.setMockMethodCallHandler((MethodCall methodCall) async { 12 | return '42'; 13 | }); 14 | }); 15 | 16 | tearDown(() { 17 | channel.setMockMethodCallHandler(null); 18 | }); 19 | } 20 | --------------------------------------------------------------------------------