Skip to content

Commit 0cf9892

Browse files
committed
feat: return empty tag stream on non-Android device
Signed-off-by: Harry Chen <[email protected]>
1 parent 4e58f7c commit 0cf9892

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/flutter_nfc_kit.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:ndef/ndef.dart' as ndef;
77
import 'package:ndef/ndef.dart' show TypeNameFormat; // for generated file
88
import 'package:ndef/utilities.dart';
99
import 'package:json_annotation/json_annotation.dart';
10+
import 'package:universal_platform/universal_platform.dart';
1011

1112
part 'flutter_nfc_kit.g.dart';
1213

@@ -277,14 +278,17 @@ class FlutterNfcKit {
277278

278279
static const MethodChannel _channel = MethodChannel('flutter_nfc_kit/method');
279280

280-
static const EventChannel _tagEventChannel =
281+
static final EventChannel _tagEventChannel =
281282
EventChannel('flutter_nfc_kit/event');
282283

283284
/// Stream of NFC tag events. Each event is a [NFCTag] object.
284285
///
285286
/// This is only supported on Android.
286287
/// On other platforms, this stream will always be empty.
287288
static Stream<NFCTag> get tagStream {
289+
if (!UniversalPlatform.isAndroid) {
290+
return const Stream<NFCTag>.empty();
291+
}
288292
return _tagEventChannel.receiveBroadcastStream().map((dynamic event) {
289293
final Map<String, dynamic> json = jsonDecode(event as String);
290294
return NFCTag.fromJson(json);

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_nfc_kit
22
description: Provide NFC functionality on Android, iOS & Web, including reading metadata, read & write NDEF records, and transceive layer 3 & 4 data with NFC tags / cards
3-
version: 3.6.0
3+
version: 3.6.1
44
homepage: "https://github.com/nfcim/flutter_nfc_kit"
55

66
environment:
@@ -17,6 +17,7 @@ dependencies:
1717
convert: ^3.1.1
1818
logging: ^1.2.0
1919
web: ^1.1.1
20+
universal_platform: ^1.1.0
2021

2122
dev_dependencies:
2223
flutter_test:

0 commit comments

Comments
 (0)