meshcore-open/lib/utils/platform_info.dart

48 lines
1.8 KiB
Dart
Raw Permalink Normal View History

2026-02-22 06:54:27 -08:00
import 'package:flutter/foundation.dart';
import 'dart:io' show Platform;
2026-02-22 07:40:40 -08:00
import 'browser_detection.dart';
2026-02-22 06:54:27 -08:00
/// 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;
2026-02-22 07:40:40 -08:00
/// Whether the app is running in the Chrome browser (only relevant if [isWeb] is true).
static bool get isChrome => isWeb && BrowserDetection.isChrome;
2026-02-22 06:54:27 -08:00
/// 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;
/// Whether the current platform supports a native USB serial backend.
2026-03-02 19:21:06 -08:00
static bool get supportsNativeUsbSerial =>
isAndroid || isWindows || isLinux || isMacOS;
/// Whether the current browser supports the Web Serial backend.
static bool get supportsWebSerial => isWeb && isChrome;
/// Whether USB serial is expected to be available on the current platform.
static bool get supportsUsbSerial =>
supportsNativeUsbSerial || supportsWebSerial;
2026-02-22 06:54:27 -08:00
}