flutter_ysdk 0.1.0
flutter_ysdk: ^0.1.0 copied to clipboard
A Flutter plugin for integrating with MoreFun POS YSDK (Android). Supports Device Info, Printer, and NFC (Mifare/TypeA, NTAG, CPU).
Flutter YSDK Plugin #
A Flutter plugin for integrating with the MoreFun POS YSDK on Android. This plugin allows you to access native device features such as the printer, NFC card reader (Mifare Classic, NTAG, CPU cards), and device information.
Features #
- Device Binding: Connect to the YSDK service.
- Device Info: Retrieve hardware and software version information.
- Printer: Print text (currently simple string printing).
- NFC Reader:
- Generic CPU/RF: Support for standard ISO 14443 Type A/B cards.
- Mifare Classic (Type A): Optimized polling loop for Mifare Classic detection and UID reading.
- NTAG: Support for NTAG215 (and compatible) cards.
- Real-time Status:
EventChannelstream for UI feedback (scanning, detecting, reading, errors).
Installation #
Add flutter_ysdk to your pubspec.yaml:
dependencies:
flutter_ysdk:
path: ../flutter_ysdk # Adjust path if local or use git/pub dependency
Usage #
1. Initialization & Binding #
You must bind to the device service before calling any other methods.
final _ysdk = FlutterYsdk();
await _ysdk.bind();
2. NFC Scanning #
The plugin provides three modes for NFC scanning. All modes run asynchronously and report status via the nfcStatus stream.
First, listen to the status stream:
_ysdk.nfcStatus.listen((status) {
print("NFC Status: $status");
// Update your UI here
});
Then trigger a scan:
Method 1: Generic CPU/RF (Default) Good for standard CPU cards.
String? uid = await _ysdk.searchCpuRfCard();
Method 2: Mifare Classic / Type A Optimized for Mifare Classic cards which may require specific polling.
String? uid = await _ysdk.searchCpuTypeA();
Method 3: NTAG Specifically for NTAG215 cards, attempts to read the first page of data.
String? data = await _ysdk.searchNtag();
Stop Scanning To cancel any active search:
await _ysdk.stopSearch();
3. Printing #
await _ysdk.printText("Hello, Flutter!");
4. Device Info #
Map<String, dynamic> info = await _ysdk.getDeviceInfo();
print(info);
Platform Specifics #
- Android Only: This plugin is designed for MoreFun Android POS devices with YSDK installed.
- Permissions: Ensure your Android app has necessary permissions if required by the specific device model (usually handled by the YSDK service).
API Reference #
| Method | Description | Returns |
|---|---|---|
bind() |
Binds to the YSDK service. | Future<bool> |
getDeviceInfo() |
Gets device hardware/software info. | Future<Map<Object?, Object?>> |
printText(String text) |
Prints a string on the thermal printer. | Future<void> |
searchCpuRfCard() |
Scans for generic ISO 14443 cards. | Future<String?> (UID) |
searchCpuTypeA() |
Scans for Mifare Classic / Type A cards. | Future<String?> (UID) |
searchNtag() |
Scans for NTAG cards. | Future<String?> (Data) |
stopSearch() |
Stops any active NFC search. | Future<void> |
nfcStatus |
Stream of status messages. | Stream<String> |
License #
MIT