Skip to content

Commit

Permalink
migrate to Federated plugin structure (#338)
Browse files Browse the repository at this point in the history
* move current code one folder deeper in order to prepare the federated plugin structure

* create platform interface package

* move model and plugincontroller to platform interface

* remove moved code from main library

* create platform interface and integrate it in the reactive ble package

* remove debuglogging

* move protobuf related stuff out of the interface package

* change codemagic pipeline to support federated plugin structure

* make platform interface ready for publishing

* add docs for platform interface

* restructure project to best practice

* rename package flutter_reactive_ble_platform_interface to reactive_ble_platform_interface

* move mobile specific code into new reactive ble mobile package

* setup CI and melos

* update docs and prepare release

* fix dependencies after publishing
  • Loading branch information
remonh87 authored Aug 17, 2021
1 parent ea29bd2 commit e9b16c4
Show file tree
Hide file tree
Showing 170 changed files with 3,432 additions and 1,934 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ The Android OS maintains a table per device of the discovered service in cache.
await flutterReactiveBle.clearGattCache(foundDeviceId);
```

### Contributing
Feel free to open an new issue or a pull request to make this project better

#### Setup

This project uses melos to manage all the packages inside this repo.

Install melos: `dart pub global activate melos`
Setup melos to point to the dependencies in your local folder: `melos bootstrap`


### FAQ

#### How to handle the BLE undeliverable exception
Expand Down
4 changes: 3 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ analyzer:
implicit-casts: false
implicit-dynamic: false
exclude:
- "bin/cache/**"
- "**/*.freezed.dart"
- "**/*.g.dart"
- "**/*.mocks.dart"
- "**/generated/bledata.pb.dart"
- "**/generated/**"

linter:
rules:
Expand Down
10 changes: 10 additions & 0 deletions bin/quality_checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -ex
flutter pub global activate melos
#workaround for codemagic CI since melos is not in bash
echo 'export PATH="$PATH":"$FLUTTER_ROOT/.pub-cache/bin"' >>~/.bashrc
echo 'export PATH="$PATH":"$FLUTTER_ROOT/bin"' >>~/.bashrc
source ~/.bashrc

melos bootstrap
melos run analyze
melos run unittest
38 changes: 17 additions & 21 deletions codemagic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,24 @@ workflows:
-keyalg 'RSA' \
-keysize 2048 \
-validity 10000
- |
# set up local properties
echo "flutter.sdk=$HOME/programs/flutter" > "$FCI_BUILD_DIR/android/local.properties"
- name: Pub get
script: cd . && flutter pub get
- name: Flutter analyze
script: cd . && flutter analyze
- name: Flutter test
script: cd . && flutter test
- name: Dry run publish
script: cd . && flutter pub publish --dry-run
- |
#!/bin/bash -ex
cd example/android && ls && ./gradlew detekt && ./gradlew testDebugUnitTest
- name: setup local properties
script: |
# set up local properties
echo "flutter.sdk=$HOME/programs/flutter" > "$FCI_BUILD_DIR/example/android/local.properties"
- name: Quality checks monorepo
script: |
./bin/quality_checks.sh
- name: Android native tests
script: |
#!/bin/bash -ex
cd example/android && ls && ./gradlew detekt && ./gradlew testDebugUnitTest
- name: Build android app
script: cd example && flutter build apk --debug
- name: Build iOS app
script: find . -name "Podfile" -execdir pod install \;
- cd example && flutter build ios --debug --no-codesign
script: |
find . -name "Podfile" -execdir pod install \;
cd example && flutter build ios --debug --no-codesign
artifacts:
- build/**/outputs/**/*.apk
- build/**/outputs/**/mapping.txt
- build/ios/ipa/*.ipa
- /tmp/xcodebuild_logs/*.log
- flutter_drive.log
- example/build/**/outputs/**/*.apk
- example/build/**/outputs/**/mapping.txt
- example/build/ios/ipa/*.ipa
20 changes: 10 additions & 10 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
PODS:
- Flutter (1.0.0)
- flutter_reactive_ble (0.0.1):
- Protobuf (3.17.0)
- reactive_ble_mobile (0.0.1):
- Flutter
- Protobuf (~> 3.5)
- SwiftProtobuf (~> 1.0)
- Protobuf (3.13.0)
- SwiftProtobuf (1.12.0)
- SwiftProtobuf (1.17.0)

DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_reactive_ble (from `.symlinks/plugins/flutter_reactive_ble/ios`)
- reactive_ble_mobile (from `.symlinks/plugins/reactive_ble_mobile/ios`)

SPEC REPOS:
trunk:
Expand All @@ -19,15 +19,15 @@ SPEC REPOS:
EXTERNAL SOURCES:
Flutter:
:path: Flutter
flutter_reactive_ble:
:path: ".symlinks/plugins/flutter_reactive_ble/ios"
reactive_ble_mobile:
:path: ".symlinks/plugins/reactive_ble_mobile/ios"

SPEC CHECKSUMS:
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
flutter_reactive_ble: ac0ccac596f481b221549cad2abe16987e1f411b
Protobuf: 3dac39b34a08151c6d949560efe3f86134a3f748
SwiftProtobuf: 4ef85479c18ca85b5482b343df9c319c62bda699
Protobuf: 7327d4444215b5f18e560a97f879ff5503c4581c
reactive_ble_mobile: 9ce6723d37ccf701dbffd202d487f23f5de03b4c
SwiftProtobuf: 9c85136c6ba74b0a1b84279dbf0f6db8efb714e0

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c

COCOAPODS: 1.10.0
COCOAPODS: 1.10.1
4 changes: 2 additions & 2 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,13 @@
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Protobuf/Protobuf.framework",
"${BUILT_PRODUCTS_DIR}/SwiftProtobuf/SwiftProtobuf.framework",
"${BUILT_PRODUCTS_DIR}/flutter_reactive_ble/flutter_reactive_ble.framework",
"${BUILT_PRODUCTS_DIR}/reactive_ble_mobile/reactive_ble_mobile.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Protobuf.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftProtobuf.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_reactive_ble.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/reactive_ble_mobile.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down
8 changes: 6 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,22 @@ void main() {
title: 'Flutter Reactive BLE example',
color: _themeColor,
theme: ThemeData(primarySwatch: _themeColor),
home: HomeScreen(),
home: const HomeScreen(),
),
),
);
}

class HomeScreen extends StatelessWidget {
const HomeScreen({
Key? key,
}) : super(key: key);

@override
Widget build(BuildContext context) => Consumer<BleStatus?>(
builder: (_, status, __) {
if (status == BleStatus.ready) {
return DeviceListScreen();
return const DeviceListScreen();
} else {
return BleStatusScreen(status: status ?? BleStatus.unknown);
}
Expand Down
3 changes: 3 additions & 0 deletions example/lib/src/ble/ble_device_interactor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class BleDeviceInteractor {
_logMessage(
'Error occured when reading ${characteristic.characteristicId} : $e',
);
// ignore: avoid_print
print(s);
rethrow;
}
Expand All @@ -79,6 +80,7 @@ class BleDeviceInteractor {
_logMessage(
'Error occured when writing ${characteristic.characteristicId} : $e',
);
// ignore: avoid_print
print(s);
rethrow;
}
Expand All @@ -94,6 +96,7 @@ class BleDeviceInteractor {
_logMessage(
'Error occured when writing ${characteristic.characteristicId} : $e',
);
// ignore: avoid_print
print(s);
rethrow;
}
Expand Down
2 changes: 1 addition & 1 deletion example/lib/src/ui/device_detail/device_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class _DeviceDetail extends StatelessWidget {
DeviceInteractionTab(
device: device,
),
DeviceLogTab(),
const DeviceLogTab(),
],
),
),
Expand Down
2 changes: 2 additions & 0 deletions example/lib/src/ui/device_detail/device_log_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:flutter_reactive_ble_example/src/ble/ble_logger.dart';
import 'package:provider/provider.dart';

class DeviceLogTab extends StatelessWidget {
const DeviceLogTab({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) => Consumer<BleLogger>(
builder: (context, logger, _) => _DeviceLogTab(
Expand Down
2 changes: 2 additions & 0 deletions example/lib/src/ui/device_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import '../widgets.dart';
import 'device_detail/device_detail_screen.dart';

class DeviceListScreen extends StatelessWidget {
const DeviceListScreen({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) => Consumer2<BleScanner, BleScannerState?>(
builder: (_, bleScanner, bleScannerState, __) => _DeviceList(
Expand Down
1 change: 1 addition & 0 deletions example/lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// ignore: avoid_print
void log(String text) => print("[FlutterReactiveBLEApp] $text");
7 changes: 5 additions & 2 deletions example/lib/src/widgets.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';

class BluetoothIcon extends StatelessWidget {
const BluetoothIcon();
const BluetoothIcon({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) => const SizedBox(
Expand All @@ -12,7 +12,10 @@ class BluetoothIcon extends StatelessWidget {
}

class StatusMessage extends StatelessWidget {
const StatusMessage(this.text);
const StatusMessage({
required this.text,
Key? key,
}) : super(key: key);

final String text;

Expand Down
Loading

0 comments on commit e9b16c4

Please sign in to comment.