getDevices method

Future<List> getDevices(
  1. String host, [
  2. int? scannerType
])

Fetches the list of available scanners from Dynamsoft Service.

host - The host server URL.

Returns a List<dynamic> containing information about available scanners.

Implementation

Future<List<dynamic>> getDevices(String host, [int? scannerType]) async {
  List<dynamic> devices = [];
  String url = '$host/DWTAPI/Scanners';
  if (scannerType != null) {
    url += '?type=$scannerType';
  }

  try {
    final response = await http.get(Uri.parse(url));
    if (response.statusCode == 200 && response.body.isNotEmpty) {
      devices = json.decode(response.body);
      return devices;
    }
  } catch (error) {}
  return [];
}