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