Flutter BLE app with clean architecture, BLoC pattern, real-time data streaming, and OTA firmware updates
A professional-grade Flutter application for managing Bluetooth Low Energy (BLE) devices with real-time sensor monitoring, over-the-air firmware updates, and comprehensive device control capabilities.
- Smart Scanning: Automatic BLE device discovery with RSSI indication
- Secure Pairing: Robust device connection with timeout handling
- Connection Management: Real-time connection status monitoring
- Live Sensor Data: Temperature, humidity, pressure, and battery monitoring
- Data Visualization: Real-time charts and historical data tracking
- Configurable Buffering: Adjustable data history with memory management
- Wireless Updates: Over-the-air firmware deployment
- Progress Tracking: Real-time update progress with status indicators
- Error Handling: Robust error recovery and retry mechanisms
- Clean Architecture: Separation of concerns with layered design
- SOLID Principles: Maintainable and extensible codebase
- BLoC Pattern: Reactive state management with event-driven architecture
- Dependency Injection: Modular design with GetIt
โโโ ๐ฑ Presentation Layer
โ โโโ BLoC (State Management)
โ โโโ Pages (UI Screens)
โ โโโ Widgets (Reusable Components)
โ
โโโ ๐ง Domain Layer
โ โโโ Entities (Business Models)
โ โโโ Use Cases (Business Logic)
โ โโโ Repository Interfaces
โ
โโโ ๐พ Data Layer
โโโ Data Sources (BLE Implementation)
โโโ Models (Data Transfer Objects)
โโโ Repository Implementation
- Single Responsibility: Each class has one clear purpose
- Open/Closed: Easy to extend without modifying existing code
- Liskov Substitution: Interfaces are properly abstracted
- Interface Segregation: Small, focused interfaces
- Dependency Inversion: High-level modules independent of low-level details
- Flutter 3.0 or higher
- Android SDK 21+ or iOS 12+
- Physical device (BLE not supported on simulators)
-
Clone the repository
git clone https://github.com/sohailmahmud/ConnectFlow.git cd connectflow -
Install dependencies
flutter pub get
-
Generate code (if using build_runner)
flutter packages pub run build_runner build
-
Run the app
flutter run
Add these permissions to android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />Add to ios/Runner/Info.plist:
<key>NSBluetoothAlwaysUsageDescription</key>
<string>This app needs Bluetooth access to connect to BLE devices</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>This app needs Bluetooth access to connect to BLE devices</string>dependencies:
flutter_blue_plus: ^1.14.3 # Modern BLE library
flutter_bloc: ^8.1.3 # State management
equatable: ^2.0.5 # Value equality
injectable: ^2.3.2 # Dependency injection annotations
get_it: ^7.6.4 # Service locator
permission_handler: ^11.0.1 # Runtime permissions
rxdart: ^0.27.7 # Reactive extensions
dartz: ^0.10.1 # Functional programming
dev_dependencies:
build_runner: ^2.4.7 # Code generation
freezed: ^2.4.6 # Immutable classes
injectable_generator: ^2.4.1 # DI code generation
json_serializable: ^6.7.1 # JSON serialization-
Scan for Devices
context.read<BleBloc>().add(StartScanningEvent());
-
Connect to Device
context.read<BleBloc>().add(ConnectToDeviceEvent(deviceId));
-
Start Data Streaming
context.read<BleBloc>().add(StartDataStreamEvent(deviceId));
-
Firmware Update
context.read<BleBloc>().add( StartFirmwareUpdateEvent(deviceId, firmwareData) );
BlocBuilder<BleBloc, BleState>(
builder: (context, state) {
if (state is BleDataStreaming) {
return DataVisualizationWidget(
device: state.device,
dataHistory: state.dataHistory,
);
}
return CircularProgressIndicator();
},
)# Domain layer tests
flutter test test/domain/
# Data layer tests
flutter test test/data/
# Presentation layer tests
flutter test test/presentation/
# All unit tests
flutter test
# Integration tests
flutter test integration_test/
# With coverage
flutter test --coveragetest/
โโโ core/
โ โโโ errors/failures_test.dart
โโโ domain/
โ โโโ entities/
โ โโโ usecases/
โโโ data/
โ โโโ models/
โ โโโ repositories/
โโโ presentation/
โ โโโ bloc/
โ โโโ widgets/
โโโ mocks/
โโโ test_helpers/
โโโ integration_test/
Update these constants in ble_datasource.dart:
static const String serviceUuid = "12345678-1234-1234-1234-123456789abc";
static const String dataCharacteristicUuid = "87654321-4321-4321-4321-cba987654321";
static const String otaCharacteristicUuid = "11111111-2222-3333-4444-555555555555";Customize sensor data parsing in _parseFloat() method based on your device's data format.
- Memory Management: Automatic cleanup of streams and subscriptions
- Battery Optimization: Efficient BLE scanning with timeouts
- Data Buffering: Configurable history size to prevent memory leaks
- Connection Pooling: Proper device connection lifecycle management
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Follow the existing code style and architecture patterns
- Write tests for new functionality
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow Effective Dart guidelines
- Use meaningful variable and function names
- Add documentation for public APIs
- Maintain separation of concerns
BLE Not Working on Emulator
- BLE requires physical device - emulators don't support Bluetooth hardware
Permission Denied Errors
- Ensure all required permissions are added to platform-specific files
- Check that location services are enabled (required for BLE scanning)
Connection Timeouts
- Verify device is in pairing mode
- Check signal strength (RSSI)
- Ensure device is not connected to another app
OTA Update Failures
- Verify firmware file format
- Check MTU size limitations
- Ensure stable connection during update
This project includes comprehensive GitHub Actions workflows for automated testing, building, and deployment:
- Automated Testing: Runs on every push and pull request
- Multi-platform Support: Tests on Ubuntu, macOS, and Windows
- Comprehensive Coverage: Unit, widget, and integration tests
- Code Quality: Static analysis, formatting checks, and security scanning
- Coverage Reporting: Automatic test coverage analysis
- Weekly Dependency Updates: Automated dependency management
- Security Audits: Regular vulnerability scanning
- Automated PRs: Creates pull requests for updates
- Production Builds: Automated APK and App Bundle generation
- GitHub Releases: Automatic release creation with changelogs
- Artifact Management: Binary distribution and versioning
- Multi-format Support: Both stable and pre-release versions
Add these badges to track your CI/CD status:
[](https://github.com/yourusername/connectflow/actions/workflows/ci.yml)
[](https://github.com/yourusername/connectflow/actions/workflows/maintenance.yml)
[](https://github.com/yourusername/connectflow/actions/workflows/release.yml)This project is licensed under the MIT License - see the LICENSE file for details.
- Flutter Blue Plus - Excellent BLE library
- BLoC Library - Reactive state management
- GetIt - Dependency injection
- Clean Architecture principles by Robert C. Martin
- ๐ง Email: sohailmahmud@yahoo.com
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
Made with โค๏ธ using Flutter