-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: simplified NFC Read/Write Operations
- Loading branch information
1 parent
fba5719
commit f20b1de
Showing
2 changed files
with
95 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
import 'dart:async'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:android_intent/android_intent.dart'; | ||
import 'package:android_intent/flag.dart'; | ||
// import 'dart:async'; | ||
// import 'package:flutter/services.dart'; | ||
// import 'package:android_intent/android_intent.dart'; | ||
// import 'package:android_intent/flag.dart'; | ||
|
||
class NfcBroadcastReceiver { | ||
final MethodChannel _channel = const MethodChannel('nfc_broadcast_receiver'); | ||
final StreamController<dynamic> _eventController = | ||
StreamController.broadcast(); | ||
// class NfcBroadcastReceiver { | ||
// final MethodChannel _channel = const MethodChannel('nfc_broadcast_receiver'); | ||
// final StreamController<dynamic> _eventController = | ||
// StreamController.broadcast(); | ||
|
||
NfcBroadcastReceiver() { | ||
_channel.setMethodCallHandler(_handleMethodCall); | ||
} | ||
// NfcBroadcastReceiver() { | ||
// _channel.setMethodCallHandler(_handleMethodCall); | ||
// } | ||
|
||
Future<dynamic> _handleMethodCall(MethodCall call) async { | ||
switch (call.method) { | ||
case 'onNfcDiscovered': | ||
// Prevent default action by sending a broadcast | ||
final AndroidIntent intent = AndroidIntent( | ||
action: 'android.intent.action.VIEW', | ||
data: Uri.parse('http://www.example.com').toString(), | ||
package: 'com.example.nfc_app', | ||
componentName: 'com.example.nfc_app/.MainActivity', | ||
flags: <int>[Flag.FLAG_ACTIVITY_NEW_TASK], | ||
); | ||
await intent.launch(); | ||
_eventController.add(call.arguments); | ||
break; | ||
default: | ||
throw UnimplementedError('Method ${call.method} not implemented'); | ||
} | ||
return null; | ||
} | ||
// Future<dynamic> _handleMethodCall(MethodCall call) async { | ||
// switch (call.method) { | ||
// case 'onNfcDiscovered': | ||
// // Prevent default action by sending a broadcast | ||
// final AndroidIntent intent = AndroidIntent( | ||
// action: 'android.intent.action.VIEW', | ||
// data: Uri.parse('http://www.example.com').toString(), | ||
// package: 'com.example.nfc_app', | ||
// componentName: 'com.example.nfc_app/.MainActivity', | ||
// flags: <int>[Flag.FLAG_ACTIVITY_NEW_TASK], | ||
// ); | ||
// await intent.launch(); | ||
// _eventController.add(call.arguments); | ||
// break; | ||
// default: | ||
// throw UnimplementedError('Method ${call.method} not implemented'); | ||
// } | ||
// return null; | ||
// } | ||
|
||
Stream<dynamic> get events => _eventController.stream; | ||
// Stream<dynamic> get events => _eventController.stream; | ||
|
||
void listen() { | ||
_channel.setMethodCallHandler(_handleMethodCall); | ||
} | ||
// void listen() { | ||
// _channel.setMethodCallHandler(_handleMethodCall); | ||
// } | ||
|
||
void dispose() { | ||
_eventController.close(); | ||
} | ||
} | ||
// void dispose() { | ||
// _eventController.close(); | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters