fetchTabletSerialNumber method

Future<void> fetchTabletSerialNumber()

Fetches the tablet serial number for the current device from Appwrite.

Queries the device collection using the documentId and updates the tabletSerialNumberController with the fetched value if available. Emits DeviceEditLoaded on success or DeviceEditError on failure.

Implementation

Future<void> fetchTabletSerialNumber() async {
  emit(DeviceEditLoading());
  try {
    final result = await db.listDocuments(
      databaseId: AppConstants.appwriteDatabaseId,
      collectionId: AppConstants.userCollectionId,
      queries: [Query.equal('type', 'device'), Query.equal('documentId', documentId)],
    );

    if (result.documents.isNotEmpty) {
      tabletSerialNumberController.text =
          result.documents.first.data['tabletSerialNumber'] ?? '';
    }

    emit(DeviceEditLoaded());
  } catch (e) {
    emit(DeviceEditError("Failed to fetch tablet serial number"));
  }
}