Reputation: 2041
Is there a call to determine if flutter is running within a simulator or a physical device?
I am scanning QR codes, and want to bypass, since the camera is unavailable.
I expected to find this in platform.dart
[1] but it's not there.
[1]https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/foundation/platform.dart
I imagine I can create a plugin if I really need, I'm hoping it already exists.
Upvotes: 26
Views: 18918
Reputation: 727
It‘s now part of Flutter Community Plus (https://plus.fluttercommunity.dev/)
Device Info Plus Docu: https://plus.fluttercommunity.dev/docs/device_info_plus/overview
e.g.:
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
if(Platform.isIOS){
var iosInfo = await deviceInfo.iosInfo;
if(iosInfo.isPhysicalDevice){...}
}
Upvotes: 21
Reputation: 40433
Using the device info plus plugin you can get various information about the device you're running on, including 'isPhysicalDevice' for both Android
and iOS
(although you'll have to read them independently).
Upvotes: 27
Reputation: 824
I Know I'm A Bit Late, But If Anyone Else Comes Here, This Can Help Them. You Can Just Use This Package: https://pub.dev/packages/safe_device
Add The Latest Version In Your Pubspec.yaml
File
Then import it:
import 'package:safe_device/safe_device.dart';
Then You Can Check If Device Is An Emulator:
bool isRealDevice = await SafeDevice.isRealDevice;
Upvotes: 8
Reputation: 2291
I'm using https://pub.dev/packages/flutter_is_emulator
import 'package:flutter_is_emulator/flutter_is_emulator.dart';
....
bool isAnEmulator = await FlutterIsEmulator.isDeviceAnEmulatorOrASimulator;
Upvotes: 0
Reputation: 277067
No. But what you can do instead is use different configurations (such as a dev configuration).
For this you can use a different main.dart
such as main.dev.dart
and then run it with flutter run -t lib/main.dev.dart
Upvotes: 0