generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web): prevent unsupported operation error in isPhysicalDevice() o…
…n web (#307)
- Loading branch information
1 parent
8137fba
commit 5855b3a
Showing
1 changed file
with
16 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |