From 91f3cdfa3b3e714b46a443628720d32ca3a642d1 Mon Sep 17 00:00:00 2001 From: diffwireauto <330573775+diffwireauto@users.noreply.github.com> Date: Thu, 1 Oct 2026 00:32:36 -0400 Subject: [PATCH] fix(#717): report the negotiated MTU on Linux so the composer is usable Upstream flutter_blue_plus_linux returns `Stream.empty()` from onMtuChanged, so no MTU ever reaches Dart on Linux. FlutterBluePlus._mtuValues stays empty, mtuNow falls back to its 23-byte ATT default forever, effectiveMaxFrameSize returns the 20-byte floor, and maxChannelMessageBytes clamps to 0. Every keystroke is then rejected by the length limiter while the field still focuses and blinks: the #592 symptom, reported on Linux as locked entry fields. BlueZ does expose the negotiated MTU, as a property on org.bluez.GattCharacteristic1, surfaced by the bluez package this plugin already depends on (BlueZGattCharacteristic.mtu). The value was one layer down the whole time and simply never read. The patch watches characteristic property changes for 'MTU' and emits a BmMtuChangedResponse carrying the largest value across the device's characteristics. They describe one ATT link so they should agree; the max stops a characteristic that has not been exercised yet, and so reports nothing, from dragging the figure down. Zero is filtered out, because FlutterBluePlus would cache it and hand callers something worse than its own default, and identical consecutive values are suppressed. Nothing downstream needed changing: the device.mtu subscription added for Windows in #686 is platform-agnostic, so Linux now gets the same live budget recovery through the same path. Also points dependency_overrides at the vendored copy. Third vendored BLE backend, alongside android (#694) and winrt (#686). Verified: analyze clean, format clean, 962 tests pass. NOT verified on Linux hardware; nobody here runs Linux BLE, which is why the gap survived this long. #717's acceptance requires a real Linux BLE connect showing a non-default `MTU now:` in the app log. Co-Authored-By: Claude Opus 5 --- .../lib/flutter_blue_plus_linux.dart | 61 ++++++++++++++++++- pubspec.lock | 11 ++-- pubspec.yaml | 5 ++ 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/packages/flutter_blue_plus_linux/lib/flutter_blue_plus_linux.dart b/packages/flutter_blue_plus_linux/lib/flutter_blue_plus_linux.dart index a8bbba1a..76012985 100644 --- a/packages/flutter_blue_plus_linux/lib/flutter_blue_plus_linux.dart +++ b/packages/flutter_blue_plus_linux/lib/flutter_blue_plus_linux.dart @@ -193,9 +193,68 @@ final class FlutterBluePlusLinux extends FlutterBluePlusPlatform { return _onDiscoveredServicesController.stream; } + // OFFBAND PATCH (#717). Upstream returns Stream.empty() here, so no MTU ever + // reaches the Dart layer on Linux, FlutterBluePlus._mtuValues is never + // populated, and mtuNow stays on its 23-byte ATT default for the whole + // session. Anything sizing a write off the MTU is then permanently capped at + // the minimum, which locked this app's message composer at 0 bytes (#592). + // + // BlueZ does expose the negotiated ATT MTU: it is a property on + // org.bluez.GattCharacteristic1, surfaced by the bluez package this plugin + // already depends on as BlueZGattCharacteristic.mtu. The value was always one + // layer down, just never read. + // + // Emits the largest MTU reported across a device's characteristics. They + // describe one ATT link so they should agree; taking the max stops a + // characteristic that has not been exercised yet, and so reports nothing, + // from dragging the figure back down. @override Stream get onMtuChanged { - return Stream.empty(); + return _client.devicesChanged + .switchMap((devices) { + final streams = >[]; + + for (final device in devices) { + for (final service in device.gattServices) { + for (final characteristic in service.characteristics) { + streams.add( + characteristic.propertiesChanged + .where((properties) => properties.contains('MTU')) + .map((properties) => device), + ); + } + } + } + + return MergeStream(streams); + }) + .map((device) { + var best = 0; + + for (final service in device.gattServices) { + for (final characteristic in service.characteristics) { + final mtu = characteristic.mtu; + if (mtu != null && mtu > best) { + best = mtu; + } + } + } + + return BmMtuChangedResponse( + remoteId: device.remoteId, + mtu: best, + success: true, + errorCode: 0, + errorString: '', + ); + }) + // Never report 0: FlutterBluePlus would cache it and mtuNow would then + // hand callers a worse answer than its own 23-byte default. + .where((response) => response.mtu > 0) + .distinct( + (previous, next) => + previous.remoteId == next.remoteId && previous.mtu == next.mtu, + ); } @override diff --git a/pubspec.lock b/pubspec.lock index f1b387ed..92592aae 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -445,7 +445,7 @@ packages: path: "packages/flutter_blue_plus_android" relative: true source: path - version: "8.2.2" + version: "8.2.2+offband.1" flutter_blue_plus_darwin: dependency: transitive description: @@ -455,12 +455,11 @@ packages: source: hosted version: "8.2.2" flutter_blue_plus_linux: - dependency: transitive + dependency: "direct overridden" description: - name: flutter_blue_plus_linux - sha256: c08563ccef620be5a06dd6b895ee51ecd986d1fcab1edd2dbc3fa125518abb21 - url: "https://pub.dev" - source: hosted + path: "packages/flutter_blue_plus_linux" + relative: true + source: path version: "8.2.2" flutter_blue_plus_platform_interface: dependency: "direct main" diff --git a/pubspec.yaml b/pubspec.yaml index 7a3cb044..27c9fecb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -106,9 +106,14 @@ hooks: # negotiated MTU. No published version does, which left the Dart cache # at the 23-byte default and capped the composer at 0-4 bytes, reading # as a dead keyboard (#592, fix tracked in #686). +# linux: patched to report the negotiated MTU from BlueZ. Upstream returns an +# empty stream, so the MTU never reached Dart and the composer was +# capped at 0 bytes, the same end state as Windows (#717). dependency_overrides: flutter_blue_plus_android: path: packages/flutter_blue_plus_android + flutter_blue_plus_linux: + path: packages/flutter_blue_plus_linux flutter_blue_plus_winrt: path: packages/flutter_blue_plus_winrt