A comprehensive Flutter application for Bluetooth Low Energy (BLE) device scanning, connection, and interaction with Material 3 design principles.
- Flutter SDK (3.0.0 or later)
- Dart SDK (2.19.0 or later)
- Android Studio / Xcode for device deployment
- Physical device with Bluetooth capabilities (BLE scanning requires hardware)
-
Clone the Repository
git clone https://github.com/ogaroh/smart-ble.git cd smart_ble -
Install Dependencies
flutter pub get
-
Configure Flavors The app supports multiple build flavors:
dev- Development environmentstag- Staging environmentprod- Production environment
-
Run the Application
Development Mode:
flutter run --flavor dev --target lib/main_dev.dart
Production Mode:
flutter run --flavor prod --target lib/main_prod.dart
Build APK:
flutter build apk --flavor prod --release --target lib/main_prod.dart
Build Appbundle (Play Store Release):
flutter build appbundle --flavor prod --release --target lib/main_prod.dart
- Minimum SDK: 21 (Android 5.0)
- Target SDK: 34
- Permissions automatically handled:
BLUETOOTH,BLUETOOTH_ADMIN,ACCESS_FINE_LOCATION
- iOS 12.0 or later
- Bluetooth permissions handled via Info.plist
- Physical Device Required: BLE functionality requires a physical device with Bluetooth capabilities
- Location Permission: Android requires location permission for BLE scanning
- Bluetooth Must Be Enabled: Ensure Bluetooth is enabled on the device before running
Why BLoC was chosen:
- Separation of Concerns: Clear separation between UI, business logic, and data layers
- Testability: Easy to unit test business logic independent of UI
- Scalability: Excellent for complex applications with multiple screens and states
- Reactive Programming: Stream-based use-case perfect for BLE connection state management
- Ecosystem: Excellent support from the community in general
βββ Core Layer
β βββ Models (BLE data structures)
β βββ Theme (Material 3 styling)
β βββ Repository (BLE operations)
βββ Feature Layer
β βββ Device Scanner (BlocProvider + BlocBuilder)
β βββ Device Details (BlocProvider + BlocConsumer)
β βββ Settings (BlocProvider + BlocConsumer)
βββ Presentation Layer
βββ Screens (StatelessWidgets)
βββ Widgets (Reusable components)
Key BLoC Components:
- DeviceScannerBloc: Manages BLE scanning, device discovery, and filtering
- DeviceDetailBloc: Handles device connection, service discovery, and characteristic operations
- SettingsBloc: Theme changes, Bluetooth timeout settings, Scanning preferences & other advanced settings (granular) that might be implemented later
- Events: User actions (scan, connect, read characteristics)
- States: UI states (loading, loaded, error, connecting, etc.)
State Flow Example:
User clicks "Connect" β ConnectToDeviceEvent β
DeviceDetailConnecting (immediate UI feedback) β
BLE Connection β DeviceDetailConnected β
Auto Service Discovery β DeviceDetailDiscoveringServices β
Services Found β DeviceDetailConnected (with services)
- Challenge: BLE connection states can change rapidly and unpredictably
- Solution: Implemented immediate UI feedback with state-specific classes (DeviceDetailConnecting, DeviceDetailConnected, etc.)
- Challenge: BLE scanning can be inconsistent, especially on different devices
- Solution: Added robust error handling, scan timeouts, and user feedback for scanning issues
- Challenge: Not all devices expose manufacturer information via standard characteristics
- Solution: Graceful fallback with proper error states (unavailable, loading, error, available)
- Challenge: Ensuring consistent theming across complex UI components
- Solution: Custom theme system with AppColors class and comprehensive styling
- Challenge: Supporting dev/staging/production environments
- Solution: Implemented flavorizr configuration with separate main entry points
- Assumed target devices have Bluetooth 4.0+ BLE support
- Assumed users will grant necessary permissions when prompted
- Assumed physical device testing (emulator limitations acknowledged)
- Users prefer immediate visual feedback over waiting for actual BLE responses
- Device connection attempts should have reasonable timeouts
- Error messages should be user-friendly rather than technical
- Standard BLE service UUIDs (Device Information: 180A, Battery: 180F)
- Common characteristic UUIDs for manufacturer name (2A29), model number (2A24)
- UTF-8 encoding for readable characteristic values
- Device lists under 50 items perform adequately without any lag
- Service discovery is fast enough for auto-triggering on connection
- Memory usage acceptable for typical BLE device discovery & communication sessions
- Implementation: Full Material 3 design system with dynamic theming & custom settings
- Features:
- Added an extra Settings module
- Custom color schemes and typography
- Smooth animations and transitions
- Consistent iconography and spacing
- Responsive layout design
- full localization support for 4 languages (English, Swahili, French & Spanish). The language conforms to the system language
- Implementation: Automatic manufacturer name detection via the Device Information Service (0x180A)
- Features:
- Auto-discovery of manufacturer name characteristic (0x2A29)
- Loading states with progress indicators
- Error handling for unsupported devices
- Graceful fallback for unavailable information
- Dev, Staging, and Production flavors
- Environment-specific configurations
- Separate app icons and names per flavor
- Network-aware error messages
- User-friendly error states
- Recovery suggestions and actions
- Service and characteristic discovery
- Real-time connection state monitoring
- RSSI signal strength display
- Characteristic property analysis (Read, Write, Notify, etc.)
- Comprehensive code documentation
- Error boundary implementations
- Proper resource cleanup (connection disposal)
- Memory leak prevention etc.
Download Smart BLE APK Production build with release optimizations
Watch Application Demo Complete walkthrough of BLE scanning, connection, and service discovery
-
Flutter Version: 3.24.5
-
Dart Version: 3.5.4
-
Key Dependencies:
flutter_blue_plus: ^1.36.8(BLE functionality)flutter_bloc: ^8.1.6(State management)permission_handler: ^11.4.0(Runtime permissions)equatable: ^2.0.5(Value equality)
-
Supported Platforms: Android (API 21+), iOS (12.0+)
-
Architecture: Clean Architecture with BLoC pattern
-
Design System: Material 3 with custom theming
This Smart BLE application demonstrates a production-ready Flutter implementation with modern architecture patterns, comprehensive error handling, and user-centric design. The BLoC pattern provides excellent separation of concerns and maintainability, while the Material 3 design ensures a polished user experience across different devices and screen sizes.
The implementation successfully addresses all core requirements while adding significant value through bonus features and robust engineering practices.