Skip to content

Commit

Permalink
fix(web): prevent unsupported operation error in isPhysicalDevice() o…
Browse files Browse the repository at this point in the history
…n 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.
  • Loading branch information
mohitrajsinha committed Oct 3, 2024
1 parent 8137fba commit 8a11c57
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/features/device/device_info_service.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
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());

class DeviceInfoService {
final _deviceInfo = DeviceInfoPlugin();

Future<bool> isPhysicalDevice() async => Platform.isIOS
? (await _deviceInfo.iosInfo).isPhysicalDevice
: Platform.isAndroid && (await _deviceInfo.androidInfo).isPhysicalDevice;
Future<bool> 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;
}
}

0 comments on commit 8a11c57

Please sign in to comment.