mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Adding the demo app from my I/O talk. Because AI. ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] All existing and new tests are passing. --------- Co-authored-by: Brett Morgan <brett.morgan@gmail.com>
40 lines
1.1 KiB
Dart
40 lines
1.1 KiB
Dart
import 'package:device_info_plus/device_info_plus.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
class DeviceInfo {
|
|
static Future<BaseDeviceInfo> initialize(DeviceInfoPlugin plugin) async {
|
|
if (kIsWeb) {
|
|
return await plugin.webBrowserInfo;
|
|
}
|
|
switch (defaultTargetPlatform) {
|
|
case TargetPlatform.android:
|
|
return await plugin.androidInfo;
|
|
case TargetPlatform.iOS:
|
|
return await plugin.iosInfo;
|
|
case TargetPlatform.macOS:
|
|
return plugin.macOsInfo;
|
|
case TargetPlatform.windows:
|
|
return await plugin.windowsInfo;
|
|
case TargetPlatform.linux:
|
|
return await plugin.linuxInfo;
|
|
default:
|
|
throw UnsupportedError(
|
|
'Device info not supported for this platform',
|
|
);
|
|
}
|
|
}
|
|
|
|
static bool isPhysicalDeviceWithCamera(BaseDeviceInfo deviceInfo) {
|
|
if (deviceInfo is! IosDeviceInfo && deviceInfo is! AndroidDeviceInfo) {
|
|
return false;
|
|
}
|
|
if (deviceInfo is IosDeviceInfo && deviceInfo.isPhysicalDevice) {
|
|
return true;
|
|
}
|
|
if (deviceInfo is AndroidDeviceInfo && deviceInfo.isPhysicalDevice) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|