From e668f4c3f266a77cd0761b374690e1bc57e89747 Mon Sep 17 00:00:00 2001 From: John Nicholson Date: Fri, 5 Jun 2020 18:03:44 +0100 Subject: [PATCH 1/9] NfcInFlutterPlugin - added adapter.ignore to prevent a double tag reads by the system NfcInFlutterPlugin - read "read_for_write" to set writeIgnore property when to prevent ignoring of tags during read phase of writing api - added "read_for_write" property when calling NfcInFlutterPlugin to prevent ignoring of tags during read phase of writing --- .../nfc_in_flutter/NfcInFlutterPlugin.java | 25 ++++++++- lib/src/api.dart | 53 ++++++++++--------- 2 files changed, 51 insertions(+), 27 deletions(-) diff --git a/android/src/main/java/me/andisemler/nfc_in_flutter/NfcInFlutterPlugin.java b/android/src/main/java/me/andisemler/nfc_in_flutter/NfcInFlutterPlugin.java index 10f7a2b..0ed6458 100644 --- a/android/src/main/java/me/andisemler/nfc_in_flutter/NfcInFlutterPlugin.java +++ b/android/src/main/java/me/andisemler/nfc_in_flutter/NfcInFlutterPlugin.java @@ -42,10 +42,12 @@ public class NfcInFlutterPlugin implements MethodCallHandler, EventChannel.StreamHandler, PluginRegistry.NewIntentListener, - NfcAdapter.ReaderCallback { + NfcAdapter.ReaderCallback, + NfcAdapter.OnTagRemovedListener { private static final String NORMAL_READER_MODE = "normal"; private static final String DISPATCH_READER_MODE = "dispatch"; + private static final int ONE_SECOND = 1000; private final int DEFAULT_READER_FLAGS = NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_NFC_B | NfcAdapter.FLAG_READER_NFC_F | NfcAdapter.FLAG_READER_NFC_V; private static final String LOG_TAG = "NfcInFlutterPlugin"; @@ -55,6 +57,11 @@ public class NfcInFlutterPlugin implements MethodCallHandler, private String currentReaderMode = null; private Tag lastTag = null; + private boolean writeIgnore = false; + + @Override + public void onTagRemoved() { + } /** * Plugin registration. @@ -84,6 +91,13 @@ public void onMethodCall(MethodCall call, Result result) { return; } HashMap args = (HashMap) call.arguments; + Boolean readForWrite = (Boolean) args.get("read_for_write"); + if (readForWrite != null && readForWrite) { + writeIgnore = true; + } else { + writeIgnore = false; + } + String readerMode = (String) args.get("reader_mode"); if (readerMode == null) { result.error("MissingReaderMode", "startNDEFReading was called without a reader mode", ""); @@ -205,6 +219,9 @@ public void onTagDiscovered(Tag tag) { Log.e(LOG_TAG, "close NDEF tag error: " + e.getMessage()); } eventSuccess(formatNDEFMessageToResult(ndef, message)); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N && !writeIgnore) { + adapter.ignore(tag, ONE_SECOND, this, null); + } } catch (IOException e) { Map details = new HashMap<>(); details.put("fatal", true); @@ -620,6 +637,12 @@ private void writeNDEF(NdefMessage message) throws NfcInFlutterException { } finally { try { ndef.close(); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N && writeIgnore) { + adapter = NfcAdapter.getDefaultAdapter(activity); + if (adapter != null) { + adapter.ignore(lastTag, ONE_SECOND, this, null); + } + } } catch (IOException e) { Log.e(LOG_TAG, "close NDEF tag error: " + e.getMessage()); } diff --git a/lib/src/api.dart b/lib/src/api.dart index 21c66c6..285d010 100644 --- a/lib/src/api.dart +++ b/lib/src/api.dart @@ -8,7 +8,7 @@ import './exceptions.dart'; class NFC { static MethodChannel _channel = MethodChannel("nfc_in_flutter"); static const EventChannel _eventChannel = - const EventChannel("nfc_in_flutter/tags"); + const EventChannel("nfc_in_flutter/tags"); static Stream _tagStream; @@ -61,10 +61,11 @@ class NFC { } static void _startReadingNDEF( - bool once, String alertMessage, NFCReaderMode readerMode) { + bool once, bool readForWrite, String alertMessage, NFCReaderMode readerMode) { // Start reading Map arguments = { "scan_once": once, + "read_for_write": readForWrite, "alert_message": alertMessage, "reader_mode": readerMode.name, }..addAll(readerMode._options); @@ -76,22 +77,22 @@ class NFC { static Stream readNDEF( { - /// once will stop reading after the first tag has been read. - bool once = false, + /// once will stop reading after the first tag has been read. + bool once = false, - /// throwOnUserCancel decides if a [NFCUserCanceledSessionException] error - /// should be thrown on iOS when the user clicks Cancel/Done. - bool throwOnUserCancel = true, + /// throwOnUserCancel decides if a [NFCUserCanceledSessionException] error + /// should be thrown on iOS when the user clicks Cancel/Done. + bool throwOnUserCancel = true, - /// alertMessage sets the message on the iOS NFC modal. - String alertMessage = "", + /// alertMessage sets the message on the iOS NFC modal. + String alertMessage = "", - /// readerMode specifies which mode the reader should use. By default it - /// will use the normal mode, which scans for tags normally without - /// support for peer-to-peer operations, such as emulated host cards. - /// - /// This is ignored on iOS as it only has one reading mode. - NFCReaderMode readerMode = const NFCNormalReaderMode()}) { + /// readerMode specifies which mode the reader should use. By default it + /// will use the normal mode, which scans for tags normally without + /// support for peer-to-peer operations, such as emulated host cards. + /// + /// This is ignored on iOS as it only has one reading mode. + NFCReaderMode readerMode = const NFCNormalReaderMode()}) { if (_tagStream == null) { _createTagStream(); } @@ -150,7 +151,7 @@ class NFC { }; try { - _startReadingNDEF(once, alertMessage, const NFCNormalReaderMode()); + _startReadingNDEF(once, false, alertMessage, const NFCNormalReaderMode()); } on PlatformException catch (err) { if (err.code == "NFCMultipleReaderModes") { throw NFCMultipleReaderModesException(); @@ -168,17 +169,17 @@ class NFC { static Stream writeNDEF(NDEFMessage newMessage, { - /// once will stop reading after the first tag has been read. - bool once = false, + /// once will stop reading after the first tag has been read. + bool once = false, - /// message specify the message shown to the user when the NFC modal is - /// open - /// - /// This is ignored on Android as it does not have NFC modal - String message = "", + /// message specify the message shown to the user when the NFC modal is + /// open + /// + /// This is ignored on Android as it does not have NFC modal + String message = "", - /// readerMode specifies which mode the reader should use. - NFCReaderMode readerMode = const NFCNormalReaderMode()}) { + /// readerMode specifies which mode the reader should use. + NFCReaderMode readerMode = const NFCNormalReaderMode()}) { if (_tagStream == null) { _createTagStream(); } @@ -211,7 +212,7 @@ class NFC { }; try { - _startReadingNDEF(once, message, readerMode); + _startReadingNDEF(once, true, message, readerMode); } on PlatformException catch (err) { if (err.code == "NFCMultipleReaderModes") { throw NFCMultipleReaderModesException(); From 7920da18bdb2e3e9949d37892cd87502a89a8eee Mon Sep 17 00:00:00 2001 From: vilvic Date: Thu, 21 Jan 2021 13:27:18 +0000 Subject: [PATCH 2/9] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 880d583..1dbc279 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +# versions +I will endeavour to keep this up to date but it's not guaranteed + # nfc_in_flutter NFC in Flutter is a plugin for reading and writing NFC tags in Flutter. It works on both Android and iOS with a simple stream interface. From eadabcde9c0c8b8390a9dea6f5fe41f63b516239 Mon Sep 17 00:00:00 2001 From: Alex Nicholson Date: Sun, 28 Mar 2021 11:28:38 +0100 Subject: [PATCH 3/9] Updated to run on iOS --- example/ios/Podfile.lock | 2 +- example/ios/Runner.xcodeproj/project.pbxproj | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index fd241f9..cd213ee 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -19,4 +19,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 3dbe063e9c90a5d7c9e4e76e70a821b9e2c1d271 -COCOAPODS: 1.9.1 +COCOAPODS: 1.10.1 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 860a563..20d8b62 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -318,7 +318,6 @@ /* Begin XCBuildConfiguration section */ 249021D3217E4FDB00AE95B9 /* Profile */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -409,7 +408,6 @@ }; 97C147031CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -472,7 +470,6 @@ }; 97C147041CF9000F007C117D /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; From 1ec9770f879d306ab689d393ba6a8d426d20552a Mon Sep 17 00:00:00 2001 From: John Nicholson Date: Sat, 10 Apr 2021 16:07:56 +0100 Subject: [PATCH 4/9] Merged 2.0.5 from https://github.com/semlette/nfc_in_flutter --- CHANGELOG.md | 3 + README.md | 2 +- android/gradle.properties | 3 + example/android/build.gradle | 2 +- example/android/gradle.properties | 2 + .../gradle/wrapper/gradle-wrapper.properties | 4 +- example/pubspec.lock | 41 ++++--- lib/src/api.dart | 101 ++++++++-------- pubspec.lock | 109 +----------------- pubspec.yaml | 9 +- 10 files changed, 90 insertions(+), 186 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2256be5..b70e96e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.0.6 +- Flutter 2.0 null safety. This is the first update for null safety so may not fully function. + ## 2.0.5 - Better reading reliability on iOS diff --git a/README.md b/README.md index 1dbc279..9b70738 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ Add `nfc_in_flutter` to your `pubspec.yaml` ```yaml dependencies: - nfc_in_flutter: 2.0.5 + nfc_in_flutter: 2.0.6 ``` ### iOS diff --git a/android/gradle.properties b/android/gradle.properties index 8bd86f6..38c8d45 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1 +1,4 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true +android.useAndroidX=true +android.enableJetifier=true diff --git a/example/android/build.gradle b/example/android/build.gradle index bb8a303..041ce01 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:4.1.2' } } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 7be3d8b..38c8d45 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,2 +1,4 @@ org.gradle.jvmargs=-Xmx1536M android.enableR8=true +android.useAndroidX=true +android.enableJetifier=true diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 2819f02..6a229eb 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Jun 23 08:50:38 CEST 2017 +#Thu Mar 04 20:57:51 GMT 2021 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip diff --git a/example/pubspec.lock b/example/pubspec.lock index 0260854..d4b4754 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,42 +7,42 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: @@ -56,7 +56,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -73,28 +73,28 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" nfc_in_flutter: dependency: "direct dev" description: path: ".." relative: true source: path - version: "2.0.5" + version: "2.0.6" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -106,56 +106,55 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.10.0" + dart: ">=2.12.0-0.0 <3.0.0" diff --git a/lib/src/api.dart b/lib/src/api.dart index 65c773b..77cb23d 100644 --- a/lib/src/api.dart +++ b/lib/src/api.dart @@ -3,22 +3,21 @@ import 'dart:core'; import 'dart:typed_data'; import 'package:flutter/services.dart'; - -import './exceptions.dart'; +import 'package:nfc_in_flutter/nfc_in_flutter.dart'; class NFC { static MethodChannel _channel = MethodChannel("nfc_in_flutter"); static const EventChannel _eventChannel = const EventChannel("nfc_in_flutter/tags"); - static Stream _tagStream; + static Stream? _tagStream; static void _createTagStream() { _tagStream = _eventChannel.receiveBroadcastStream().where((tag) { // In the future when more tag types are supported, this must be changed. assert(tag is Map); return tag["message_type"] == "ndef"; - }).map((tag) { + }).map((tag) { assert(tag is Map); List records = []; @@ -62,15 +61,15 @@ class NFC { }); } - static void _startReadingNDEF( - bool once, bool readForWrite, String alertMessage, NFCReaderMode readerMode) { + static void _startReadingNDEF(bool once, bool readForWrite, String alertMessage, NFCReaderMode readerMode) { // Start reading Map arguments = { "scan_once": once, "read_for_write": readForWrite, "alert_message": alertMessage, "reader_mode": readerMode.name, - }..addAll(readerMode._options); + } + ..addAll(readerMode._options); _channel.invokeMethod("startNDEFReading", arguments); } @@ -101,10 +100,10 @@ class NFC { // converted to their matching exception classes. The controller stream will // be closed if the errors are fatal. StreamController controller = StreamController(); - final stream = once ? _tagStream.take(1) : _tagStream; + final stream = once ? _tagStream?.take(1) : _tagStream; // Listen for tag reads. - final subscription = stream.listen( - (message) => controller.add(message), + final subscription = stream?.listen( + (message) => controller.add(message), onError: (error) { error = _mapException(error); if (!throwOnUserCancel && error is NFCUserCanceledSessionException) { @@ -115,14 +114,14 @@ class NFC { }, onDone: () { _tagStream = null; - return controller.close(); + controller.close(); }, // cancelOnError: false // cancelOnError cannot be used as the stream would cancel BEFORE the error // was sent to the controller stream ); controller.onCancel = () { - subscription.cancel(); + subscription?.cancel(); }; try { @@ -136,7 +135,7 @@ class NFC { if (err.code == "NFCMultipleReaderModes") { throw NFCMultipleReaderModesException(); } else if (err.code == "SystemIsBusyError") { - throw NFCSystemIsBusyException(err.message); + throw NFCSystemIsBusyException(err.message!); } throw err; } catch (error) { @@ -150,8 +149,7 @@ class NFC { /// the stream is active. /// If you only want to write to the first tag, you can set the [once] /// argument to `true` and use the `.first` method on the returned `Stream`. - static Stream writeNDEF( - NDEFMessage newMessage, { + static Stream writeNDEF(NDEFMessage newMessage, { /// once will stop reading after the first tag has been read. bool once = false, @@ -172,8 +170,8 @@ class NFC { StreamController controller = StreamController(); int writes = 0; - StreamSubscription stream = _tagStream.listen( - (msg) async { + StreamSubscription? stream = _tagStream?.listen( + (msg) async { NDEFMessage message = msg; if (message.tag.writable) { try { @@ -198,14 +196,14 @@ class NFC { }, onDone: () { _tagStream = null; - return controller.close(); + controller.close(); }, // cancelOnError: false // cancelOnError cannot be used as the stream would cancel BEFORE the error // was sent to the controller stream ); controller.onCancel = () { - stream.cancel(); + stream?.cancel(); }; try { @@ -276,19 +274,21 @@ enum MessageType { abstract class NFCMessage { MessageType get messageType; - String get id; + + String? get id; NFCTag get tag; } abstract class NFCTag { - String get id; + String? get id; + bool get writable; } class NDEFMessage implements NFCMessage { - final String id; - String type; + final String? id; + String? type; final List records; NDEFMessage.withRecords(this.records, {this.id}); @@ -299,7 +299,7 @@ class NDEFMessage implements NFCMessage { // payload returns the payload of the first non-empty record. If all records // are empty it will return null. - String get payload { + String? get payload { for (var record in records) { if (record.payload != "") { return record.payload; @@ -320,7 +320,7 @@ class NDEFMessage implements NFCMessage { // data returns the contents of the first non-empty record. If all records // are empty it will return null. - String get data { + String? get data { for (var record in records) { if (record.data != "") { return record.data; @@ -357,20 +357,20 @@ enum NFCTypeNameFormat { } class NDEFRecord { - final String id; - final String payload; - final String type; - final String data; - final NFCTypeNameFormat tnf; + final String? id; + final String? payload; + final String? type; + final String? data; + final NFCTypeNameFormat? tnf; /// languageCode will be the language code of a well known text record. If the /// record is not created with the well known TNF and Text RTD, this will be /// null. - final String languageCode; + final String? languageCode; /// rawPayload contains the raw payload provided by the reader. /// It will only be set when reading NDEF tags. Otherwise it will be null. - final Uint8List rawPayload; + final Uint8List? rawPayload; NDEFRecord.empty() : id = null, @@ -439,18 +439,17 @@ class NDEFRecord { this.type = "", this.tnf = NFCTypeNameFormat.unknown, this.languageCode, - }) : data = payload, + }) + : data = payload, rawPayload = null; - NDEFRecord._internal( - this.id, - this.payload, - this.type, - this.tnf, - this.data, - this.languageCode, - this.rawPayload, - ); + NDEFRecord._internal(this.id, + this.payload, + this.type, + this.tnf, + this.data, + this.languageCode, + this.rawPayload,); Map _toMap() { String tnf; @@ -481,14 +480,14 @@ class NDEFRecord { "id": id ?? "", "payload": payload ?? "", "type": type ?? "", - "tnf": tnf ?? "unknown", + "tnf": tnf, "languageCode": languageCode, }; } } class NDEFTag implements NFCTag { - final String id; + final String? id; final bool writable; NDEFTag._internal(this.id, this.writable); @@ -511,15 +510,15 @@ class NDEFTag implements NFCTag { } on PlatformException catch (e) { switch (e.code) { case "NFCUnexpectedError": - throw Exception("nfc: unexpected error: " + e.message); + throw Exception("nfc: unexpected error: " + e.message!); case "IOError": - throw NFCIOException(e.message); + throw NFCIOException(e.message!); case "NFCTagUnavailable": throw NFCTagUnavailableException(); case "NDEFUnsupported": throw NDEFUnsupportedException(); case "NDEFBadFormatError": - throw NDEFBadFormatException(e.message); + throw NDEFBadFormatException(e.message!); case "NFCTagNotWritableError": throw NFCTagNotWritableException(); case "NFCTagSizeTooSmallError": @@ -548,16 +547,16 @@ Exception _mapException(dynamic error) { error = NFCSessionTimeoutException(); break; case "SessionTerminatedUnexpectedlyErorr": - error = NFCSessionTerminatedUnexpectedlyException(error.message); + error = NFCSessionTerminatedUnexpectedlyException(error.message!); break; case "SystemIsBusyError": - error = NFCSystemIsBusyException(error.message); + error = NFCSystemIsBusyException(error.message!); break; case "IOError": - error = NFCIOException(error.message); + error = NFCIOException(error.message!); break; case "NDEFBadFormatError": - error = NDEFBadFormatException(error.message); + error = NDEFBadFormatException(error.message!); break; } } diff --git a/pubspec.lock b/pubspec.lock index 706519b..5e5273e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,147 +1,50 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - async: - dependency: transitive - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "2.5.0-nullsafety.1" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.1" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.1" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.1" + version: "1.15.0" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - matcher: - dependency: transitive - description: - name: matcher - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.10-nullsafety.1" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0-nullsafety.1" + version: "1.3.0" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0-nullsafety.2" - stack_trace: - dependency: transitive - description: - name: stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "1.10.0-nullsafety.1" - stream_channel: - dependency: transitive - description: - name: stream_channel - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0-nullsafety.1" - string_scanner: - dependency: transitive - description: - name: string_scanner - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0-nullsafety.1" - term_glyph: - dependency: transitive - description: - name: term_glyph - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety.1" - test_api: - dependency: transitive - description: - name: test_api - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.19-nullsafety.2" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.10.0" + dart: ">=2.12.0-0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 41dd857..96e87a2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,21 +1,16 @@ name: nfc_in_flutter description: Flutter plugin to read and write NFC tags on both Android and iOS. Currently it only supports reading NDEF formatted tags. -version: 2.0.5 +version: 2.0.6 homepage: https://github.com/semlette/nfc_in_flutter repository: https://github.com/semlette/nfc_in_flutter environment: - sdk: ">=2.1.0 <3.0.0" - flutter: ">=1.10.0" + sdk: ">=2.12.0-0 <3.0.0" dependencies: flutter: sdk: flutter -dev_dependencies: - flutter_test: - sdk: flutter - flutter: plugin: platforms: From 0b7d84410581359f5cfb7c763e9b7321775a2381 Mon Sep 17 00:00:00 2001 From: John Nicholson Date: Sat, 10 Apr 2021 16:12:14 +0100 Subject: [PATCH 5/9] Merged 2.0.5 from https://github.com/semlette/nfc_in_flutter --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9b70738..c89330c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # versions I will endeavour to keep this up to date but it's not guaranteed +Updated to use flutter 2.0 null safety # nfc_in_flutter From 8944a21a2c4e632e43a33aa895cfa57872d58d41 Mon Sep 17 00:00:00 2001 From: John Nicholson Date: Sat, 10 Apr 2021 16:12:36 +0100 Subject: [PATCH 6/9] Merged 2.0.5 from https://github.com/semlette/nfc_in_flutter --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c89330c..fdaac17 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # versions -I will endeavour to keep this up to date but it's not guaranteed +I will endeavour to keep this up to date but it's not guaranteed. + Updated to use flutter 2.0 null safety # nfc_in_flutter From 821412a6e71adc6f2b3a853986f77837f753003a Mon Sep 17 00:00:00 2001 From: Alex Nicholson Date: Sun, 18 Apr 2021 21:31:49 +0100 Subject: [PATCH 7/9] ios updates --- example/ios/Podfile | 2 +- example/ios/Runner.xcodeproj/project.pbxproj | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/example/ios/Podfile b/example/ios/Podfile index 98a90b8..35719ac 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -# platform :ios, '9.0' +# platform :ios, '10.12' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 20d8b62..dd98582 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -355,7 +355,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; OTHER_LDFLAGS = ( "$(inherited)", @@ -451,7 +451,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = ( @@ -507,7 +507,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; OTHER_LDFLAGS = ( "$(inherited)", From 53c4c7515670ddd987d437f8cd4b03de51e10774 Mon Sep 17 00:00:00 2001 From: Alex Nicholson Date: Tue, 20 Apr 2021 22:26:05 +0100 Subject: [PATCH 8/9] Added check for error code 403 which ignores the "NDEF tag does not contain any NDEF message" error --- ios/Classes/NfcInFlutterPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Classes/NfcInFlutterPlugin.m b/ios/Classes/NfcInFlutterPlugin.m index 128d96d..968f5e2 100644 --- a/ios/Classes/NfcInFlutterPlugin.m +++ b/ios/Classes/NfcInFlutterPlugin.m @@ -490,7 +490,7 @@ - (void)readerSession:(NFCNDEFReaderSession *)session } [tag readNDEFWithCompletionHandler:^(NFCNDEFMessage * _Nullable message, NSError * _Nullable error) { - if (error != nil) { + if (error != nil && error.code != 403) { NSLog(@"ERROR: %@", error.localizedDescription); return; } From d92ac79fc3c1831118f7ce3cd925c0291cd16eaa Mon Sep 17 00:00:00 2001 From: John Nicholson Date: Wed, 21 Apr 2021 19:42:10 +0100 Subject: [PATCH 9/9] Added option to view if NFC is supported in example app --- example/lib/main.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/example/lib/main.dart b/example/lib/main.dart index 9d8037f..bd550d7 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -19,6 +19,13 @@ class ExampleApp extends StatelessWidget { body: Builder(builder: (context) { return ListView( children: [ + ListTile( + title: const Text("NFC Supported"), + onTap: () async { + bool supported = await NFC.isNDEFSupported; + ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('NFC supported = ${supported}'))); + }, + ), ListTile( title: const Text("Read NFC"), onTap: () {