Skip to content
This repository was archived by the owner on Jun 23, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 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

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.
Expand Down Expand Up @@ -150,7 +155,7 @@ Add `nfc_in_flutter` to your `pubspec.yaml`

```yaml
dependencies:
nfc_in_flutter: 2.0.5
nfc_in_flutter: 2.0.6
```

### iOS
Expand Down
3 changes: 3 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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.
Expand Down Expand Up @@ -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", "");
Expand Down Expand Up @@ -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<String, Object> details = new HashMap<>();
details.put("fatal", true);
Expand Down Expand Up @@ -621,6 +638,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());
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:4.1.2'
}
}

Expand Down
2 changes: 2 additions & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
4 changes: 2 additions & 2 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 3dbe063e9c90a5d7c9e4e76e70a821b9e2c1d271

COCOAPODS: 1.9.1
COCOAPODS: 1.10.1
9 changes: 3 additions & 6 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -356,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)",
Expand Down Expand Up @@ -409,7 +408,6 @@
};
97C147031CF9000F007C117D /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -453,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 = (
Expand All @@ -472,7 +470,6 @@
};
97C147041CF9000F007C117D /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -510,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)",
Expand Down
7 changes: 7 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class ExampleApp extends StatelessWidget {
body: Builder(builder: (context) {
return ListView(
children: <Widget>[
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: () {
Expand Down
Loading