Skip to content

Commit

Permalink
imp: add pedantic and format accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
juliansteenbakker committed Apr 23, 2021
1 parent 03bb3b8 commit 434ea86
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:pedantic/analysis_options.yaml
1 change: 1 addition & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:pedantic/analysis_options.yaml
14 changes: 7 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
final isScanning = scanSubscription != null;
final hasDevice = scanResults.length > 0;
final hasDevice = scanResults.isNotEmpty;

return MaterialApp(
home: Scaffold(
Expand All @@ -101,7 +101,7 @@ class _MyAppState extends State<MyApp> {
),
body: !hasDevice
? const Center(
child: const Text('No device'),
child: Text('No device'),
)
: ListView.separated(
padding: const EdgeInsets.all(8),
Expand Down Expand Up @@ -129,7 +129,7 @@ class _MyAppState extends State<MyApp> {
setState(() {
dfuRunningInx = index;
});
await this.doDfu(result.device.id.id);
await doDfu(result.device.id.id);
setState(() {
dfuRunningInx = null;
});
Expand Down Expand Up @@ -159,8 +159,8 @@ class DeviceItem extends StatelessWidget {

@override
Widget build(BuildContext context) {
var name = "Unknow";
if (scanResult.device.name != null && scanResult.device.name.length > 0) {
var name = 'Unknown';
if (scanResult.device.name != null && scanResult.device.name.isNotEmpty) {
name = scanResult.device.name;
}
return Card(
Expand All @@ -175,13 +175,13 @@ class DeviceItem extends StatelessWidget {
children: <Widget>[
Text(name),
Text(scanResult.device.id.id),
Text("RSSI: ${scanResult.rssi}"),
Text('RSSI: ${scanResult.rssi}'),
],
),
),
TextButton(
onPressed: onPress,
child: isRunningItem ? Text("Abort Dfu") : Text("Start Dfu"))
child: isRunningItem ? Text('Abort Dfu') : Text('Start Dfu'))
],
),
),
Expand Down
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
flutter_blue: ^0.8.0

dev_dependencies:
pedantic: ^1.11.0
flutter_test:
sdk: flutter

Expand Down
36 changes: 19 additions & 17 deletions lib/nordic_dfu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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,16 +71,16 @@ class NordicDfu {
static const String NAMESPACE = 'dev.steenbakker.nordic_dfu';

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

/// Start dfu handle
/// [address] android: mac address iOS: device uuid
/// [filePath] zip file path
/// [name] device name
/// [progressListener] Dfu progress listener, You can use [DefaultDfuProgressListenerAdapter]
/// [fileInAsset] if [filePath] is a asset path like 'asset/file.zip', must set this value to true, else false
/// [forceDfu] Legacy DFU only, see in nordic libarary, default is false
/// [enableUnsafeExperimentalButtonlessServiceInSecureDfu] see in nordic libarary, default is false
/// [forceDfu] Legacy DFU only, see in nordic library, default is false
/// [enableUnsafeExperimentalButtonlessServiceInSecureDfu] see in nordic library, default is false
/// [androidSpecialParameter] this parameters is only used by android lib
/// [iosSpecialParameter] this parameters is only used by ios lib
static Future<String> startDfu(
Expand All @@ -96,50 +97,50 @@ class NordicDfu {
const AndroidSpecialParameter(),
IosSpecialParameter iosSpecialParameter = const IosSpecialParameter(),
}) async {
assert(address != null, "address can not be null");
assert(filePath != null, "file can not be null");
assert(address != null, 'address can not be null');
assert(filePath != null, 'file can not be null');

_channel.setMethodCallHandler((MethodCall call) {
switch (call.method) {
case "onDeviceConnected":
case 'onDeviceConnected':
progressListener?.onDeviceConnected(call.arguments);
break;
case "onDeviceConnecting":
case 'onDeviceConnecting':
progressListener?.onDeviceConnecting(call.arguments);
break;
case "onDeviceDisconnected":
case 'onDeviceDisconnected':
progressListener?.onDeviceDisconnected(call.arguments);
break;
case "onDeviceDisconnecting":
case 'onDeviceDisconnecting':
progressListener?.onDeviceDisconnecting(call.arguments);
break;
case "onDfuAborted":
case 'onDfuAborted':
progressListener?.onDfuAborted(call.arguments);
break;
case "onDfuCompleted":
case 'onDfuCompleted':
progressListener?.onDfuCompleted(call.arguments);
break;
case "onDfuProcessStarted":
case 'onDfuProcessStarted':
progressListener?.onDfuProcessStarted(call.arguments);
break;
case "onDfuProcessStarting":
case 'onDfuProcessStarting':
progressListener?.onDfuProcessStarting(call.arguments);
break;
case "onEnablingDfuMode":
case 'onEnablingDfuMode':
progressListener?.onEnablingDfuMode(call.arguments);
break;
case "onFirmwareValidating":
case 'onFirmwareValidating':
progressListener?.onFirmwareValidating(call.arguments);
break;
case "onError":
case 'onError':
progressListener?.onError(
call.arguments['deviceAddress'],
call.arguments['error'],
call.arguments['errorType'],
call.arguments['message'],
);
break;
case "onProgressChanged":
case 'onProgressChanged':
progressListener?.onProgressChanged(
call.arguments['deviceAddress'],
call.arguments['percent'],
Expand Down Expand Up @@ -365,6 +366,7 @@ class DefaultDfuProgressListenerAdapter extends DfuProgressListenerAdapter {
}
}

@override
void onProgressChanged(
String deviceAddress,
int percent,
Expand Down
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ dependencies:
flutter:
sdk: flutter

dev_dependencies:
pedantic: ^1.11.0

flutter:
plugin:
androidPackage: dev.steenbakker.nordicdfu
Expand Down

0 comments on commit 434ea86

Please sign in to comment.