Skip to main content

Flutter Native BLE

This page is based on "Underlying transport plug-in" and the message protocol. Read the interface and 64-byte frame format first.

If the Flutter application wants to directly connect to UKey Wallet through mobile phone Bluetooth, it can package the JS SDK and put it into WebView or JS engine to run, and then use Dart/native plug-in to forward the BLE data to the underlying adapter of the SDK.

Part 1: Pick Runtime

  • WebView: The best compatibility, and the bridge interface is closer to the Android/iOS native shell.
  • JS engine: such as flutter_js, suitable for scenarios where you do not want to introduce a complete WebView, but need to verify runtime compatibility by yourself.

Part 2: Build JS

Building web resources in hardware-js-sdk's native examples will typically generate web_dist/ from the web/ directory. This product contains SDK calling logic and code to communicate with the native bridge.

Part 3: Load JS

Enter web_dist/ as a Flutter resource into the application and load it in WebView or JS engine. After the initialization is completed, the Flutter layer passes the device list, connection status and BLE notification to JS.

Part 4: Bridge Messages

Expose underlying methods such as enumerate, connect, disconnect, send, receive to JS, and keep method signatures consistent. BLE notifications are usually returned in 64-byte fragments. The Flutter/native layer is responsible for forwarding, and the JS side reorganizes the hexadecimal payload according to the protocol.

Part 5: Handle UI

PIN, Passphrase, and device confirmation should all have clear native popups displayed by Flutter pages. After the user inputs or confirms, pass the result back to the SDK instance with ukeySdk.uiResponse.

BLE IDs

  • primaryServiceUUIDString = ["00000001", "0000", "1000", "8000", "00805f9b34fb"].join("-")
  • txCharacteristicUUIDString = ["00000002", "0000", "1000", "8000", "00805f9b34fb"].join("-")
  • rxCharacteristicUUIDString = ["00000003", "0000", "1000", "8000", "00805f9b34fb"].join("-")

After the connection is established, the calling method of the chain-related API is consistent with WebUSB: pass in connectId, and then pass in deviceId if necessary.