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 (#307)
  • Loading branch information
mohitrajsinha authored Oct 7, 2024
1 parent 8137fba commit 5855b3a
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 5855b3a

Please sign in to comment.