From e313d5f07caceb60b2bdc8950f37aa500579e655 Mon Sep 17 00:00:00 2001 From: ThaddeusLim99 Date: Thu, 3 Mar 2022 17:23:07 +0800 Subject: [PATCH 1/4] functional changes to make app workable --- android/build.gradle | 2 +- android/src/main/AndroidManifest.xml | 10 ++++++++-- .../android/app/src/main/AndroidManifest.xml | 1 + example/android/build.gradle | 3 ++- example/pubspec.yaml | 2 ++ lib/assets/file.zip | Bin 0 -> 199395 bytes 6 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 lib/assets/file.zip diff --git a/android/build.gradle b/android/build.gradle index d3348e4..421c32e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -35,5 +35,5 @@ android { dependencies { implementation 'androidx.core:core:1.0.2' - implementation 'no.nordicsemi.android:dfu:1.11.0' + implementation 'no.nordicsemi.android:dfu:1.12.0' } diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 1b701d5..0ed1e72 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,8 +1,14 @@ - - + + + + + + + + diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 8d1465a..12a6468 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -6,6 +6,7 @@ to allow setting breakpoints, to provide hot reload, etc. --> + Localizations.of(context, S); + static S? of(BuildContext context) => Localizations.of(context, S); @override TextDirection get textDirection => TextDirection.ltr; - } class $en extends S { const $en(); } -class GeneratedLocalizationsDelegate extends LocalizationsDelegate { +class GeneratedLocalizationsDelegate extends LocalizationsDelegate { const GeneratedLocalizationsDelegate(); List get supportedLocales { @@ -36,8 +35,9 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate { ]; } - LocaleListResolutionCallback listResolution({Locale fallback, bool withCountry = true}) { - return (List locales, Iterable supported) { + LocaleListResolutionCallback listResolution( + {Locale? fallback, bool withCountry = true}) { + return (List? locales, Iterable supported) { if (locales == null || locales.isEmpty) { return fallback ?? supported.first; } else { @@ -46,26 +46,27 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate { }; } - LocaleResolutionCallback resolution({Locale fallback, bool withCountry = true}) { - return (Locale locale, Iterable supported) { + LocaleResolutionCallback resolution( + {Locale? fallback, bool withCountry = true}) { + return (Locale? locale, Iterable supported) { return _resolve(locale, fallback, supported, withCountry); }; } @override - Future load(Locale locale) { - final String lang = getLang(locale); + Future load(Locale locale) { + final String? lang = getLang(locale); if (lang != null) { switch (lang) { case "en": S.current = const $en(); - return SynchronousFuture(S.current); + return SynchronousFuture(S.current); default: - // NO-OP. + // NO-OP. } } S.current = const S(); - return SynchronousFuture(S.current); + return SynchronousFuture(S.current); } @override @@ -77,7 +78,8 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate { /// /// Internal method to resolve a locale from a list of locales. /// - Locale _resolve(Locale locale, Locale fallback, Iterable supported, bool withCountry) { + Locale _resolve(Locale? locale, Locale? fallback, Iterable supported, + bool withCountry) { if (locale == null || !_isSupported(locale, withCountry)) { return fallback ?? supported.first; } @@ -110,7 +112,9 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate { } // If no country requirement is requested, check if this locale has no country. - if (true != withCountry && (supportedLocale.countryCode == null || supportedLocale.countryCode.isEmpty)) { + if (true != withCountry && + (supportedLocale.countryCode == null || + supportedLocale.countryCode!.isEmpty)) { return true; } } @@ -119,8 +123,11 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate { } } -String getLang(Locale l) => l == null - ? null - : l.countryCode != null && l.countryCode.isEmpty - ? l.languageCode - : l.toString(); +String? getLang(Locale l) { + try { + return l.countryCode != null && l.countryCode!.isEmpty + ? l.languageCode + : l.toString(); + } catch (_) {} + return null; +} diff --git a/example/lib/main.dart b/example/lib/main.dart index cbf8610..97e735e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:collection/collection.dart' show IterableExtension; import 'package:flutter/material.dart'; import 'package:flutter_nordic_dfu/flutter_nordic_dfu.dart'; import 'package:flutter_blue/flutter_blue.dart'; @@ -13,10 +14,10 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { final FlutterBlue flutterBlue = FlutterBlue.instance; - StreamSubscription scanSubscription; + StreamSubscription? scanSubscription; List scanResults = []; bool dfuRunning = false; - int dfuRunningInx; + int? dfuRunningInx; @override void initState() { @@ -59,9 +60,8 @@ class _MyAppState extends State { scanResults.clear(); scanSubscription = flutterBlue.scan().listen( (scanResult) { - if (scanResults.firstWhere( - (ele) => ele.device.id == scanResult.device.id, - orElse: () => null) != + if (scanResults.firstWhereOrNull( + (ele) => ele.device.id == scanResult.device.id) != null) { return; } @@ -151,19 +151,19 @@ class ProgressListenerListener extends DfuProgressListenerAdapter { } class DeviceItem extends StatelessWidget { - final ScanResult scanResult; + final ScanResult? scanResult; - final VoidCallback onPress; + final VoidCallback? onPress; - final bool isRunningItem; + final bool? isRunningItem; DeviceItem({this.scanResult, this.onPress, this.isRunningItem}); @override Widget build(BuildContext context) { var name = "Unknow"; - if (scanResult.device.name != null && scanResult.device.name.length > 0) { - name = scanResult.device.name; + if (scanResult!.device.name != null && scanResult!.device.name.length > 0) { + name = scanResult!.device.name; } return Card( child: Padding( @@ -176,14 +176,14 @@ class DeviceItem extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(name), - Text(scanResult.device.id.id), - Text("RSSI: ${scanResult.rssi}"), + Text(scanResult!.device.id.id), + Text("RSSI: ${scanResult!.rssi}"), ], ), ), TextButton( onPressed: onPress, - child: isRunningItem ? Text("Abort Dfu") : Text("Start Dfu")) + child: isRunningItem! ? Text("Abort Dfu") : Text("Start Dfu")) ], ), ), diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 4a803f4..b9bd266 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,7 +3,7 @@ description: Demonstrates how to use the flutter_nordic_dfu plugin. publish_to: 'none' environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: @@ -11,9 +11,10 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 + cupertino_icons: ^1.0.4 flutter_blue: ^0.8.0 + collection: ^1.15.0 dev_dependencies: flutter_test: diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index 0dbf1cb..e1505f1 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -19,7 +19,7 @@ void main() { expect( find.byWidgetPredicate( (Widget widget) => widget is Text && - widget.data.startsWith('Running on:'), + widget.data!.startsWith('Running on:'), ), findsOneWidget, ); From ccb76d8d48a39099952aa08f1b1257b51b9aa79b Mon Sep 17 00:00:00 2001 From: Darius Roberts Date: Mon, 4 Apr 2022 22:07:39 -0700 Subject: [PATCH 4/4] support bluetooth on android 12, by adding permission_handler dpendency --- .../android/app/src/main/AndroidManifest.xml | 5 +++ example/ios/Runner/Info.plist | 10 +++++ example/lib/main.dart | 42 +++++++++++-------- example/pubspec.yaml | 4 +- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 2d28015..87bc748 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -7,6 +7,11 @@ --> + + + + +