feat(contacts): обмен контактами NFC→BLE
This commit is contained in:
@@ -3,13 +3,14 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
enum NfcEventType { received, cancelled }
|
||||
enum NfcEventType { received, cancelled, error }
|
||||
|
||||
class NfcEvent {
|
||||
final NfcEventType type;
|
||||
final int? id;
|
||||
final String? reason;
|
||||
|
||||
const NfcEvent(this.type, this.id);
|
||||
const NfcEvent(this.type, this.id, {this.reason});
|
||||
}
|
||||
|
||||
class NfcStatus {
|
||||
@@ -59,9 +60,14 @@ class NfcExchangeService {
|
||||
NfcEvent _decodeEvent(dynamic raw) {
|
||||
final map = raw is Map ? raw : const {};
|
||||
final id = map['id'];
|
||||
final type = map['event'] == 'received'
|
||||
? NfcEventType.received
|
||||
: NfcEventType.cancelled;
|
||||
return NfcEvent(type, id is int ? id : (id is num ? id.toInt() : null));
|
||||
final parsedId = id is int ? id : (id is num ? id.toInt() : null);
|
||||
switch (map['event']) {
|
||||
case 'received':
|
||||
return NfcEvent(NfcEventType.received, parsedId);
|
||||
case 'error':
|
||||
return NfcEvent(NfcEventType.error, null, reason: map['reason'] as String?);
|
||||
default:
|
||||
return const NfcEvent(NfcEventType.cancelled, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user