getDevice method

Future<void> getDevice(
  1. String key
)

Fetches the device details based on the key. key is the device key.

Implementation

Future<void> getDevice(String key) async {
  try {
    final result = await databases.listDocuments(
      databaseId: AppConstants.appwriteDatabaseId,
      collectionId: AppConstants.userCollectionId,
      queries: [Query.equal('deviceCode', key)],
    );

    if (result.documents.isNotEmpty) {
      final deviceData = result.documents.first.data;
      _enterMPIDBottomSheet(deviceData['organizationId'], deviceData['hospitalName']);
      setState(() {
        code = deviceData['deviceCode'];
      });
    }
  } catch (e) {
    debugPrint("getDevice error: $e");
  }
}