processItems method

Future<void> processItems(
  1. List<String>? items
)

Implementation

Future<void> processItems(
  List<String>? items,
) async {
  Navigator.pop(context!);

  try {
    if ((items ?? []).isEmpty) {
      showDialog(
          context: context!,
          builder: ((context) {
            return CredioDialogScaffold(
              showClose: true,
              padded: true,
              child: DialogMessage(
                message: 'You have no reader available',
                messageType: MessageType.Info,
              ),
            );
          }));
    } else if (items?.length == 1) {
      await connectToDevice(items!.first, context!);
    } else {
      showSelectionSheet(
        context!,
        onSelect: (data) async {
          await connectToDevice((data.selection)!, context!);
        },
        title: "Select device",
        data: (items ?? []).map((item) {
          var name = item.split("//")[0].replaceAll(regexPattern, '');

          return SelectionData(
            selection: item,
            title: name,
          );
        }).toList(),
      );
    }
  } catch (e) {
    log("an error occurred -- $e");
  }

  scanFinish = 1;
  notifyListeners();
}