{"id":13551904,"url":"https://github.com/pauldemarco/flutter_blue","last_synced_at":"2025-04-09T02:16:12.678Z","repository":{"id":37549849,"uuid":"93369312","full_name":"pauldemarco/flutter_blue","owner":"pauldemarco","description":"Bluetooth plugin for Flutter","archived":false,"fork":false,"pushed_at":"2024-08-05T06:45:46.000Z","size":17397,"stargazers_count":2413,"open_issues_count":671,"forks_count":1247,"subscribers_count":68,"default_branch":"master","last_synced_at":"2025-04-02T01:14:08.655Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pauldemarco.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-05T05:47:02.000Z","updated_at":"2025-03-30T07:56:38.000Z","dependencies_parsed_at":"2023-02-10T14:25:18.883Z","dependency_job_id":"720862ac-20b4-4033-b282-fcaaf95cd8ee","html_url":"https://github.com/pauldemarco/flutter_blue","commit_stats":{"total_commits":253,"total_committers":24,"mean_commits":"10.541666666666666","dds":"0.18577075098814233","last_synced_commit":"7c7a86c95a3a2537bfb7e3c368716cdb26cf66b0"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauldemarco%2Fflutter_blue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauldemarco%2Fflutter_blue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauldemarco%2Fflutter_blue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauldemarco%2Fflutter_blue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pauldemarco","download_url":"https://codeload.github.com/pauldemarco/flutter_blue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247962605,"owners_count":21024871,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:01:55.510Z","updated_at":"2025-04-09T02:16:12.658Z","avatar_url":"https://github.com/pauldemarco.png","language":"Dart","readme":"[![pub package](https://img.shields.io/pub/v/flutter_blue.svg)](https://pub.dartlang.org/packages/flutter_blue)\n[![Chat](https://img.shields.io/discord/634853295160033301.svg?style=flat-square\u0026colorB=758ED3)](https://discord.gg/Yk5Efra)\n\n\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg alt=\"FlutterBlue\" src=\"https://github.com/pauldemarco/flutter_blue/blob/master/site/flutterblue.png?raw=true\" /\u003e\n\u003c/p\u003e\n\u003cbr\u003e\u003cbr\u003e\n\n## Introduction\n\nFlutterBlue is a bluetooth plugin for [Flutter](https://flutter.dev), a new app SDK to help developers build modern multi-platform apps.\n\n## Alpha version\n\nThis library is actively developed alongside production apps, and the API will evolve as we continue our way to version 1.0.\n\n**Please be fully prepared to deal with breaking changes.**\n**This package must be tested on a real device.**\n\nHaving trouble adapting to the latest API?   I'd love to hear your use-case, please contact me.\n\n## Cross-Platform Bluetooth LE\nFlutterBlue aims to offer the most from both platforms (iOS and Android).\n\nUsing the FlutterBlue instance, you can scan for and connect to nearby devices ([BluetoothDevice](#bluetoothdevice-api)).\nOnce connected to a device, the BluetoothDevice object can discover services ([BluetoothService](lib/src/bluetooth_service.dart)), characteristics ([BluetoothCharacteristic](lib/src/bluetooth_characteristic.dart)), and descriptors ([BluetoothDescriptor](lib/src/bluetooth_descriptor.dart)).\nThe BluetoothDevice object is then used to directly interact with characteristics and descriptors.\n\n## Usage\n### Obtain an instance\n```dart\nFlutterBlue flutterBlue = FlutterBlue.instance;\n```\n\n### Scan for devices\n```dart\n// Start scanning\nflutterBlue.startScan(timeout: Duration(seconds: 4));\n\n// Listen to scan results\nvar subscription = flutterBlue.scanResults.listen((results) {\n    // do something with scan results\n    for (ScanResult r in results) {\n        print('${r.device.name} found! rssi: ${r.rssi}');\n    }\n});\n\n// Stop scanning\nflutterBlue.stopScan();\n```\n\n### Connect to a device\n```dart\n// Connect to the device\nawait device.connect();\n\n// Disconnect from device\ndevice.disconnect();\n```\n\n### Discover services\n```dart\nList\u003cBluetoothService\u003e services = await device.discoverServices();\nservices.forEach((service) {\n    // do something with service\n});\n```\n\n### Read and write characteristics\n```dart\n// Reads all characteristics\nvar characteristics = service.characteristics;\nfor(BluetoothCharacteristic c in characteristics) {\n    List\u003cint\u003e value = await c.read();\n    print(value);\n}\n\n// Writes to a characteristic\nawait c.write([0x12, 0x34])\n```\n\n### Read and write descriptors\n```dart\n// Reads all descriptors\nvar descriptors = characteristic.descriptors;\nfor(BluetoothDescriptor d in descriptors) {\n    List\u003cint\u003e value = await d.read();\n    print(value);\n}\n\n// Writes to a descriptor\nawait d.write([0x12, 0x34])\n```\n\n### Set notifications and listen to changes\n```dart\nawait characteristic.setNotifyValue(true);\ncharacteristic.value.listen((value) {\n    // do something with new value\n});\n```\n\n### Read the MTU and request larger size\n```dart\nfinal mtu = await device.mtu.first;\nawait device.requestMtu(512);\n```\nNote that iOS will not allow requests of MTU size, and will always try to negotiate the highest possible MTU (iOS supports up to MTU size 185)\n\n## Getting Started\n### Change the minSdkVersion for Android\n\nFlutter_blue is compatible only from version 19 of Android SDK so you should change this in **android/app/build.gradle**:\n```dart\nAndroid {\n  defaultConfig {\n     minSdkVersion: 19\n```\n### Add permissions for Bluetooth\nWe need to add the permission to use Bluetooth and access location:\n\n#### **Android**\nIn the **android/app/src/main/AndroidManifest.xml** let’s add:\n\n```xml \n\t \u003cuses-permission android:name=\"android.permission.BLUETOOTH\" /\u003e  \n\t \u003cuses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\" /\u003e  \n\t \u003cuses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/\u003e  \n \u003capplication\n```\n#### **IOS**\nIn the **ios/Runner/Info.plist** let’s add:\n\n```dart \n\t\u003cdict\u003e  \n\t    \u003ckey\u003eNSBluetoothAlwaysUsageDescription\u003c/key\u003e  \n\t    \u003cstring\u003eNeed BLE permission\u003c/string\u003e  \n\t    \u003ckey\u003eNSBluetoothPeripheralUsageDescription\u003c/key\u003e  \n\t    \u003cstring\u003eNeed BLE permission\u003c/string\u003e  \n\t    \u003ckey\u003eNSLocationAlwaysAndWhenInUseUsageDescription\u003c/key\u003e  \n\t    \u003cstring\u003eNeed Location permission\u003c/string\u003e  \n\t    \u003ckey\u003eNSLocationAlwaysUsageDescription\u003c/key\u003e  \n\t    \u003cstring\u003eNeed Location permission\u003c/string\u003e  \n\t    \u003ckey\u003eNSLocationWhenInUseUsageDescription\u003c/key\u003e  \n\t    \u003cstring\u003eNeed Location permission\u003c/string\u003e\n```\n\nFor location permissions on iOS see more at: [https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services](https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services)\n\n\n## Reference\n### FlutterBlue API\n|                  |      Android       |         iOS          |             Description            |\n| :--------------- | :----------------: | :------------------: |  :-------------------------------- |\n| scan             | :white_check_mark: |  :white_check_mark:  | Starts a scan for Bluetooth Low Energy devices. |\n| state            | :white_check_mark: |  :white_check_mark:  | Stream of state changes for the Bluetooth Adapter. |\n| isAvailable      | :white_check_mark: |  :white_check_mark:  | Checks whether the device supports Bluetooth. |\n| isOn             | :white_check_mark: |  :white_check_mark:  | Checks if Bluetooth functionality is turned on. |\n\n### BluetoothDevice API\n|                             |       Android        |         iOS          |             Description            |\n| :-------------------------- | :------------------: | :------------------: |  :-------------------------------- |\n| connect                     |  :white_check_mark:  |  :white_check_mark:  | Establishes a connection to the device. |\n| disconnect                  |  :white_check_mark:  |  :white_check_mark:  | Cancels an active or pending connection to the device. |\n| discoverServices            |  :white_check_mark:  |  :white_check_mark:  | Discovers services offered by the remote device as well as their characteristics and descriptors. |\n| services                    |  :white_check_mark:  |  :white_check_mark:  | Gets a list of services. Requires that discoverServices() has completed. |\n| state                       |  :white_check_mark:  |  :white_check_mark:  | Stream of state changes for the Bluetooth Device. |\n| mtu                         |  :white_check_mark:  |  :white_check_mark:  | Stream of mtu size changes. |\n| requestMtu                  |  :white_check_mark:  |                      | Request to change the MTU for the device. |\n\n### BluetoothCharacteristic API\n|                             |       Android        |         iOS          |             Description            |\n| :-------------------------- | :------------------: | :------------------: |  :-------------------------------- |\n| read                        |  :white_check_mark:  |  :white_check_mark:  | Retrieves the value of the characteristic.  |\n| write                       |  :white_check_mark:  |  :white_check_mark:  | Writes the value of the characteristic. |\n| setNotifyValue              |  :white_check_mark:  |  :white_check_mark:  | Sets notifications or indications on the characteristic. |\n| value                       |  :white_check_mark:  |  :white_check_mark:  | Stream of characteristic's value when changed. |\n\n### BluetoothDescriptor API\n|                             |       Android        |         iOS          |             Description            |\n| :-------------------------- | :------------------: | :------------------: |  :-------------------------------- |\n| read                        |  :white_check_mark:  |  :white_check_mark:  | Retrieves the value of the descriptor.  |\n| write                       |  :white_check_mark:  |  :white_check_mark:  | Writes the value of the descriptor. |\n\n## Troubleshooting\n### When I scan using a service UUID filter, it doesn't find any devices.\nMake sure the device is advertising which service UUID's it supports.  This is found in the advertisement\npacket as **UUID 16 bit complete list** or **UUID 128 bit complete list**.\n","funding_links":[],"categories":["插件","Dart","Plugins","Device [🔝](#readme)"],"sub_categories":["蓝牙 / NFC / 信号灯","设备","Bluetooth / NFC / Beacon","Device"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpauldemarco%2Fflutter_blue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpauldemarco%2Fflutter_blue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpauldemarco%2Fflutter_blue/lists"}