check device in flutter
To check the device in Flutter, you can use the DeviceInfoPlugin
package. Here's an example of how to use it:
- First, add the
device_info_plus
package to yourpubspec.yaml
file:
dependencies:
device_info_plus: ^2.1.0
Run
flutter pub get
to fetch the package.Import the package in your Dart file:
import 'package:device_info_plus/device_info_plus.dart';
- Use the
DeviceInfoPlugin
to get the device information:
void getDevice() async {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
if (Platform.isAndroid) {
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
print('Device: ${androidInfo.model}');
print('Android version: ${androidInfo.version.release}');
} else if (Platform.isIOS) {
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
print('Device: ${iosInfo.utsname.machine}');
print('iOS version: ${iosInfo.systemVersion}');
}
}
- Call the
getDevice
function to retrieve the device information.
Please note that the device_info_plus
package provides device information for both Android and iOS platforms. You can access properties like the device model and the operating system version using the androidInfo
and iosInfo
objects, respectively.