platform_detail
現在のプラットフォームに関する情報を、より包括的かつ簡単な方法で取得するための軽量ライブラリです。
シンプルで最適化された方法でプラットフォームの詳細を取得するための軽量なDartパッケージです。モバイル、デスクトップ、Webをサポートしています。
>=12.3.0 <14.0.0^5.9.2>=9.0.0 <11.0.0{"sdk":"flutter"}{"sdk":"flutter"}^6.0.0^1.0.4以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。
Pub Version CI Status CD Status Code Coverage
Platform Detail is a lightweight and developer-friendly Flutter package that makes platform detection easier, more complete, and cross-platform.
It provides a unified and consistent API for checking the platform your app is running on — including web, something that native Flutter classes like TargetPlatform and Platform from dart:io don't currently support.
⚠️ Flutter’s native
PlatformandTargetPlatformdo not provide support for detecting web, which can be a limitation in universal apps.
✅platform_detailaddresses this limitation by introducing a simple and intuitive API that includes web detection out of the box.
PlatformDetail.kIsWeb or rely on partial solutions.platform, deviceModel, locale, platformType).The recommended way to use the library is to call the static members of the PlatformDetail class.
The example app now shows device info, network info and EnvironmentDetails on screen.
If you use VS Code, you can launch it with the Flutter Example debug configuration (cwd: example, program: lib/main.dart).
import 'package:platform_detail/platform_detail.dart';
void main() {
PlatformType platform = PlatformDetail.currentPlatform;
print('This platform is: $platform'); // e.g., PlatformType.android
}
PlatformType?If you only rely on TargetPlatform, you’ll miss web support.
void main() {
// Native TargetPlatform doesn't detect web:
if (defaultTargetPlatform == TargetPlatform.android) {
// OK for Android
} else if (kIsWeb) {
// Web has to be checked manually
}
}
With PlatformDetail, the check is unified:
void main() {
if (PlatformDetail.isWeb) {
print('Web detected ✔️');
}
}
Check whether the current platform belongs to a broader category:
void main() {
if (PlatformDetail.isMobile) {
print('Mobile platform');
}
if (PlatformDetail.isDesktop) {
print('Desktop platform');
}
if (PlatformDetail.isDesktopOrWeb) {
print('Desktop or Web platform');
}
}
Or use the PlatformGroup enum directly:
void main() {
switch (PlatformDetail.currentGroupPlatform) {
case PlatformGroup.mobile:
print('Mobile');
break;
case PlatformGroup.web:
print('Web');
break;
case PlatformGroup.desktop:
print('Desktop');
break;
}
}
void main() {
if (PlatformDetail.isIOS) print('iOS');
if (PlatformDetail.isAndroid) print('Android');
if (PlatformDetail.isFuchsia) print('Fuchsia');
if (PlatformDetail.isWindows) print('Windows');
if (PlatformDetail.isLinux) print('Linux');
if (PlatformDetail.isMacOS) print('macOS');
if (PlatformDetail.isWeb) print('Web');
}
Or create different cases through the enum with a switch:
void main() {
switch (PlatformDetail.currentPlatform) {
case PlatformType.android:
print('Android');
case PlatformType.iOS:
print('iOS');
case PlatformType.isFuchsia:
print('Fuchsia');
case PlatformType.Windows:
print('Windows');
case PlatformType.Linux:
print('Linux');
case PlatformType.macOS:
print('macOS');
case PlatformType.Web:
print('Web');
}
}
You can detect the private IP of the device:
void main() async {
final List<String> privateIps = await PlatformDetail.getPrivateIp;
}
You can also detect the public IP of the device:
void main() async {
final String publicIp = await PlatformDetail.getPublicIp;
}
ℹ️ No configuration is required for most platforms.
For macOS, you must add the following entry to bothDebugProfile.entitlementsandReleaseProfile.entitlementsfiles:
<key>com.apple.security.network.client</key>
<true/>
If you need more detailed information about the device and operating system it is running on.
void main() async {
final descriptionDevice = await PlatformDetail.deviceInfo();
}
Or maybe you need an information string about the device info:
void main() async {
final descriptionDevice = await PlatformDetail.deviceInfoDetails();
}
This will return something like this:
If you need a typed and lightweight payload with platform, model and locale, use environmentDetails():
void main() async {
final details = await PlatformDetail.environmentDetails();
print(details.platformType); // PlatformType.android
print(details.platform); // android 14
print(details.deviceModel); // Google Pixel 8
print(details.locale); // en-US
}
This returns an EnvironmentDetails object with these fields:
platformType: PlatformTypeplatform: StringdeviceModel: Stringlocale: Stringexample app includes a section that renders these values on screen.If you need app package metadata, you can use versionDetails():
void main() async {
final details = await PlatformDetail.versionDetails();
print(details.appName); // My App
print(details.packageName); // com.example.my_app
print(details.version); // 5.4.0
print(details.buildNumber); // 12
}
This returns a VersionDetails object with these fields:
appName: StringpackageName: Stringversion: StringbuildNumber: StringYou can detect too if the device is configured in light or dark mode:
void main() {
if (PlatformDetail.isLightMode) {
print('The current platform is configured with light mode');
}
if (PlatformDetail.isDarkMode) {
print('The current platform is configured with dark mode');
}
}
Also, you can use the DeviceTheme enum for this:
void main() {
if (PlatformDetail.theme == DeviceTheme.light) {
print('The current device is configured in light mode');
}
if (PlatformDetail.theme == DeviceTheme.dark) {
print('The current device is configured in dark mode');
}
}