Fix Flutter web build compilation errors#2
Conversation
Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This pull request fixes compilation errors in the Flutter web build caused by type conflicts between platform-specific Bluetooth packages and API changes in geolocator v11.x.
Changes:
- Added import aliases to resolve
BluetoothServiceclass name collisions betweenflutter_blue_plusandflutter_web_bluetoothpackages - Updated web Bluetooth characteristics to use
dynamictype and added type-safe data conversion handling forByteData/Uint8List - Replaced deprecated
locationSettingsparameter with directdesiredAccuracyandtimeLimitparameters ingetCurrentPosition()calls for geolocator v11.x compatibility
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/services/bluetooth/mobile_bluetooth.dart | Added as fbp import alias to resolve type conflicts with flutter_blue_plus |
| lib/services/bluetooth/web_bluetooth.dart | Added as fwb import alias, used dynamic for characteristics, and implemented type-safe ByteData/Uint8List conversion |
| lib/services/gps_service.dart | Updated getCurrentPosition() calls to use direct parameters instead of deprecated locationSettings |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| dynamic _rxCharacteristic; // Using dynamic to handle WebBluetoothRemoteGATTCharacteristic | ||
| dynamic _txCharacteristic; // Using dynamic to handle WebBluetoothRemoteGATTCharacteristic |
There was a problem hiding this comment.
Using dynamic types for characteristics bypasses type safety. Consider declaring the actual type from the flutter_web_bluetooth package (e.g., fwb.BluetoothCharacteristic) to maintain compile-time type checking and enable IDE autocomplete. If the actual type isn't exported, consider adding a type alias or filing an issue with the package maintainers.
| dynamic _rxCharacteristic; // Using dynamic to handle WebBluetoothRemoteGATTCharacteristic | |
| dynamic _txCharacteristic; // Using dynamic to handle WebBluetoothRemoteGATTCharacteristic | |
| fwb.BluetoothCharacteristic? _rxCharacteristic; | |
| fwb.BluetoothCharacteristic? _txCharacteristic; |
| } catch (e) { | ||
| // Silently ignore conversion errors | ||
| } |
There was a problem hiding this comment.
Silently ignoring conversion errors could hide bugs and make debugging difficult in production. Consider logging the error or at minimum logging to debug console in debug mode, e.g., if (kDebugMode) { print('Bluetooth data conversion error: $e'); }.
The Flutter web build was failing due to type conflicts between platform-specific Bluetooth packages and API incompatibilities with geolocator v11.x.
Changes
Bluetooth service type conflicts
as fbp,as fwb) to resolveBluetoothServiceclass name collisions betweenflutter_blue_plus,flutter_web_bluetooth, and local implementationdynamictypes for web Bluetooth characteristics to handleWebBluetoothRemoteGATTCharacteristicfrom flutter_web_bluetoothGeolocator API update
locationSettingsparameter ingetCurrentPosition()with directdesiredAccuracyandtimeLimitparameters for web platform compatibilitygetPositionStream()continues usingLocationSettings(still supported API)Files Modified
lib/services/bluetooth/mobile_bluetooth.dart- Import aliasinglib/services/bluetooth/web_bluetooth.dart- Type handling and data conversionlib/services/gps_service.dart- API parameter updatesOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.