addAid static method
- String aid
Adds an AID to the FlutterPos plugin.
This function returns a Future<void>, which completes when the AID has been added successfully or when an error occurs.
If the AID cannot be added, the function throws a FlutterPosException.
Parameters:
aid(required): The AID to be added.
Example:
await FlutterNewposSdk.addAid('A000000003');
Throws:
FlutterPosExceptionwith the codeADD_AID_TIMEOUTif the AID cannot be added within the timeout period.FlutterPosExceptionwith the codeADD_AID_FAILUREif an unknown error occurs while adding the AID.FlutterPosExceptionwith the codeADD_AID_FAILUREif the AID is already added.
Implementation
static Future<void> addAid(String aid) async {
/// Stream method
final stream = FlutterNewposSdk._methodStream.stream
.where((m) => m.method == 'OnAddAidSuccess')
.map((m) {
return m.arguments as bool;
});
try {
final methodResult = await _invokeMethod(
'addAid',
aid,
);
final result = methodResult as bool;
if (!result) {
throw const FlutterPosException(
code: 'ADD_AID_FAILURE',
message: 'Exception adding AID',
);
}
final streamOutput = await getFirstResultInStream(
stream,
const Duration(seconds: 2),
);
if (streamOutput == false) {
throw const FlutterPosException(
code: 'ADD_AID_FAILURE',
message: 'Exception adding AID',
);
}
} on TimeoutException {
throw const FlutterPosException(
code: 'ADD_AID_TIMEOUT',
message: 'Timeout adding AID',
);
} catch (e) {
throw const FlutterPosException(
code: 'ADD_AID_FAILURE',
message: 'Exception adding AID',
);
}
}