import method

void import()

Implementation

void import() => UFile.showFilePicker(
  allowedExtensions: const <String>["xlsx"],
  action: (List<UFileData> i) {
    if (i.length != 1 || i.first.bytes == null || !(i.first.extension ?? "").toLowerCase().contains("xlsx")) return;
    ULoading.show();
    UServices.terminal.import(
      p: UTerminalImportParams(file: i.first.bytes!.toBase64()),
      onOk: (UResponse<UTerminalImportResponse> response) {
        ULoading.dismiss();
        read();
        if (response.result != null) _showImportResult(response.result!);
      },
      onError: (UEmptyResponse response) {
        ULoading.dismiss();
        UToast.error(message: response.message);
      },
      onException: (String response) {
        ULoading.dismiss();
        UToast.error(message: response);
      },
    );
  },
);