Skip to content

Commit

Permalink
imp: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
juliansteenbakker committed May 31, 2021
1 parent 5dc25e8 commit 71f6ede
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 85 deletions.
70 changes: 35 additions & 35 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class _MyAppState extends State<MyApp> {
'assets/file.zip',
fileInAsset: true,
progressListener:
DefaultDfuProgressListenerAdapter(onProgressChangedHandle: (
deviceAddress,
percent,
speed,
avgSpeed,
currentPart,
partsTotal,
) {
DefaultDfuProgressListenerAdapter(onProgressChangedHandle: (
deviceAddress,
percent,
speed,
avgSpeed,
currentPart,
partsTotal,
) {
print('deviceAddress: $deviceAddress, percent: $percent');
}),
);
Expand All @@ -57,7 +57,7 @@ class _MyAppState extends State<MyApp> {
setState(() {
scanResults.clear();
scanSubscription = flutterBlue.scan().listen(
(scanResult) {
(scanResult) {
if (scanResults.firstWhereOrNull(
(ele) => ele.device.id == scanResult.device.id) !=
null) {
Expand Down Expand Up @@ -91,25 +91,25 @@ class _MyAppState extends State<MyApp> {
actions: <Widget>[
isScanning
? IconButton(
icon: Icon(Icons.pause_circle_filled),
onPressed: dfuRunning ? null : stopScan,
)
icon: Icon(Icons.pause_circle_filled),
onPressed: dfuRunning ? null : stopScan,
)
: IconButton(
icon: Icon(Icons.play_arrow),
onPressed: dfuRunning ? null : startScan,
)
icon: Icon(Icons.play_arrow),
onPressed: dfuRunning ? null : startScan,
)
],
),
body: !hasDevice
? const Center(
child: Text('No device'),
)
child: Text('No device'),
)
: ListView.separated(
padding: const EdgeInsets.all(8),
itemBuilder: _deviceItemBuilder,
separatorBuilder: (context, index) => const SizedBox(height: 5),
itemCount: scanResults.length,
),
padding: const EdgeInsets.all(8),
itemBuilder: _deviceItemBuilder,
separatorBuilder: (context, index) => const SizedBox(height: 5),
itemCount: scanResults.length,
),
),
);
}
Expand All @@ -121,20 +121,20 @@ class _MyAppState extends State<MyApp> {
scanResult: result,
onPress: dfuRunning
? () async {
await NordicDfu.abortDfu();
setState(() {
dfuRunningInx = null;
});
}
await NordicDfu.abortDfu();
setState(() {
dfuRunningInx = null;
});
}
: () async {
setState(() {
dfuRunningInx = index;
});
await doDfu(result.device.id.id);
setState(() {
dfuRunningInx = null;
});
},
setState(() {
dfuRunningInx = index;
});
await doDfu(result.device.id.id);
setState(() {
dfuRunningInx = null;
});
},
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void main() {
// Verify that platform version is retrieved.
expect(
find.byWidgetPredicate(
(Widget widget) =>
widget is Text && widget.data!.startsWith('Running on:'),
(Widget widget) =>
widget is Text && widget.data!.startsWith('Running on:'),
),
findsOneWidget,
);
Expand Down
99 changes: 51 additions & 48 deletions lib/nordic_dfu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter/services.dart';
/// Some parameter just use in Android
/// All this parameters can see in <a href="https://github.com/NordicSemiconductor/Android-DFU-Library">
class AndroidSpecialParameter {

///Sets whether the progress notification in the status bar should be disabled.
///Defaults to false.
final bool? disableNotification;
Expand Down Expand Up @@ -70,8 +69,7 @@ class IosSpecialParameter {
class NordicDfu {
static const String NAMESPACE = 'dev.steenbakker.nordic_dfu';

static const MethodChannel _channel =
MethodChannel('$NAMESPACE/method');
static const MethodChannel _channel = MethodChannel('$NAMESPACE/method');

/// Start dfu handle
/// [address] android: mac address iOS: device uuid
Expand All @@ -84,20 +82,19 @@ class NordicDfu {
/// [androidSpecialParameter] this parameters is only used by android lib
/// [iosSpecialParameter] this parameters is only used by ios lib
static Future<String?> startDfu(
String address,
String filePath, {
String? name,
DfuProgressListenerAdapter? progressListener,
bool? fileInAsset,
bool? forceDfu,
bool? enablePRNs,
int? numberOfPackets,
bool? enableUnsafeExperimentalButtonlessServiceInSecureDfu,
AndroidSpecialParameter androidSpecialParameter =
String address,
String filePath, {
String? name,
DfuProgressListenerAdapter? progressListener,
bool? fileInAsset,
bool? forceDfu,
bool? enablePRNs,
int? numberOfPackets,
bool? enableUnsafeExperimentalButtonlessServiceInSecureDfu,
AndroidSpecialParameter androidSpecialParameter =
const AndroidSpecialParameter(),
IosSpecialParameter iosSpecialParameter = const IosSpecialParameter(),
}) async {

IosSpecialParameter iosSpecialParameter = const IosSpecialParameter(),
}) async {
_channel.setMethodCallHandler((MethodCall call) {
switch (call.method) {
case 'onDeviceConnected':
Expand Down Expand Up @@ -163,16 +160,16 @@ class NordicDfu {
'enablePRNs': enablePRNs,
'numberOfPackets': numberOfPackets,
'enableUnsafeExperimentalButtonlessServiceInSecureDfu':
enableUnsafeExperimentalButtonlessServiceInSecureDfu,
enableUnsafeExperimentalButtonlessServiceInSecureDfu,
'disableNotification': androidSpecialParameter.disableNotification,
'keepBond': androidSpecialParameter.keepBond,
'restoreBond': androidSpecialParameter.restoreBond,
'packetReceiptNotificationsEnabled':
androidSpecialParameter.packetReceiptNotificationsEnabled,
androidSpecialParameter.packetReceiptNotificationsEnabled,
'startAsForegroundService':
androidSpecialParameter.startAsForegroundService,
androidSpecialParameter.startAsForegroundService,
'alternativeAdvertisingNameEnabled':
iosSpecialParameter.alternativeAdvertisingNameEnabled,
iosSpecialParameter.alternativeAdvertisingNameEnabled,
});
}

Expand Down Expand Up @@ -203,20 +200,20 @@ abstract class DfuProgressListenerAdapter {
void onFirmwareValidating(String? deviceAddress) {}

void onError(
String? deviceAddress,
int? error,
int? errorType,
String? message,
) {}
String? deviceAddress,
int? error,
int? errorType,
String? message,
) {}

void onProgressChanged(
String? deviceAddress,
int? percent,
double? speed,
double? avgSpeed,
int? currentPart,
int? partsTotal,
) {}
String? deviceAddress,
int? percent,
double? speed,
double? avgSpeed,
int? currentPart,
int? partsTotal,
) {}
}

class DefaultDfuProgressListenerAdapter extends DfuProgressListenerAdapter {
Expand All @@ -240,11 +237,17 @@ class DefaultDfuProgressListenerAdapter extends DfuProgressListenerAdapter {

void Function(String? deviceAddress)? onFirmwareValidatingHandle;

void Function(String? deviceAddress, int? error, int? errorType, String? message)?
onErrorHandle;
void Function(
String? deviceAddress, int? error, int? errorType, String? message)?
onErrorHandle;

void Function(String? deviceAddress, int? percent, double? speed,
double? avgSpeed, int? currentPart, int? partsTotal)? onProgressChangedHandle;
void Function(
String? deviceAddress,
int? percent,
double? speed,
double? avgSpeed,
int? currentPart,
int? partsTotal)? onProgressChangedHandle;

DefaultDfuProgressListenerAdapter({
this.onDeviceConnectedHandle,
Expand Down Expand Up @@ -343,11 +346,11 @@ class DefaultDfuProgressListenerAdapter extends DfuProgressListenerAdapter {

@override
void onError(
String? deviceAddress,
int? error,
int? errorType,
String? message,
) {
String? deviceAddress,
int? error,
int? errorType,
String? message,
) {
super.onError(
deviceAddress,
error,
Expand All @@ -366,13 +369,13 @@ class DefaultDfuProgressListenerAdapter extends DfuProgressListenerAdapter {

@override
void onProgressChanged(
String? deviceAddress,
int? percent,
double? speed,
double? avgSpeed,
int? currentPart,
int? partsTotal,
) {
String? deviceAddress,
int? percent,
double? speed,
double? avgSpeed,
int? currentPart,
int? partsTotal,
) {
super.onProgressChanged(
deviceAddress,
percent,
Expand Down

0 comments on commit 71f6ede

Please sign in to comment.