From 8a11c576759960ba30a5fd47fad4cd37a5f2dca8 Mon Sep 17 00:00:00 2001 From: mohitrajsinha Date: Thu, 3 Oct 2024 21:19:09 +0530 Subject: [PATCH] fix(web): prevent unsupported operation error in isPhysicalDevice() on web Added a check for kIsWeb in the DeviceInfoService to bypass the isPhysicalDevice() check on web platforms, since the app doesn't support QR code scanning on web. Now the method will return false when running on web, avoiding the unsupported operation error that occurs when trying to run device checks. - Imported 'kIsWeb' to detect web platform. - Updated isPhysicalDevice() to return false for web platform. - Ensured backward compatibility with iOS and Android platforms. --- lib/features/device/device_info_service.dart | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/features/device/device_info_service.dart b/lib/features/device/device_info_service.dart index 83e00901..9986786e 100644 --- a/lib/features/device/device_info_service.dart +++ b/lib/features/device/device_info_service.dart @@ -1,6 +1,7 @@ -import 'dart:io'; +import 'dart:io' show Platform; import 'package:device_info_plus/device_info_plus.dart'; +import 'package:flutter/foundation.dart' show kIsWeb; import 'package:hooks_riverpod/hooks_riverpod.dart'; final deviceInfoServiceProvider = Provider((ref) => DeviceInfoService()); @@ -8,7 +9,18 @@ final deviceInfoServiceProvider = Provider((ref) => DeviceInfoService()); class DeviceInfoService { final _deviceInfo = DeviceInfoPlugin(); - Future isPhysicalDevice() async => Platform.isIOS - ? (await _deviceInfo.iosInfo).isPhysicalDevice - : Platform.isAndroid && (await _deviceInfo.androidInfo).isPhysicalDevice; + Future isPhysicalDevice() async { + if (kIsWeb) { + // On web, return false as there is no physical device + return false; + } + if (Platform.isIOS) { + return (await _deviceInfo.iosInfo).isPhysicalDevice; + } + if (Platform.isAndroid) { + return (await _deviceInfo.androidInfo).isPhysicalDevice; + } + // Default return for unsupported platforms + return false; + } }