mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-23 10:54:33 +10:00
add platforminfo helper
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
/// Utility class to safely check the current platform across web and native.
|
||||
///
|
||||
/// Using `Platform` from `dart:io` directly on Web causes a crash.
|
||||
/// This class handles the `kIsWeb` check first to avoid those crashes.
|
||||
class PlatformInfo {
|
||||
/// Whether the app is running in a web browser.
|
||||
static bool get isWeb => kIsWeb;
|
||||
|
||||
/// Whether the app is running on Android.
|
||||
static bool get isAndroid => !kIsWeb && Platform.isAndroid;
|
||||
|
||||
/// Whether the app is running on iOS.
|
||||
static bool get isIOS => !kIsWeb && Platform.isIOS;
|
||||
|
||||
/// Whether the app is running on macOS.
|
||||
static bool get isMacOS => !kIsWeb && Platform.isMacOS;
|
||||
|
||||
/// Whether the app is running on Windows.
|
||||
static bool get isWindows => !kIsWeb && Platform.isWindows;
|
||||
|
||||
/// Whether the app is running on Linux.
|
||||
static bool get isLinux => !kIsWeb && Platform.isLinux;
|
||||
|
||||
/// Whether the app is running on a mobile platform (Android or iOS).
|
||||
static bool get isMobile => isAndroid || isIOS;
|
||||
|
||||
/// Whether the app is running on a desktop platform (macOS, Windows, or Linux).
|
||||
static bool get isDesktop => isMacOS || isWindows || isLinux;
|
||||
}
|
||||
Reference in New Issue
Block a user