mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-17 16:06:28 +10:00
add platforminfo helper
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'dart:io';
|
||||
import '../utils/platform_info.dart';
|
||||
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
@@ -109,6 +110,10 @@ class GpxExport {
|
||||
String shareText,
|
||||
String subject,
|
||||
) async {
|
||||
if (PlatformInfo.isWeb) {
|
||||
debugPrint("GPX export is not supported on Web.");
|
||||
return gpxExportNotAvailable;
|
||||
}
|
||||
if (_contacts.isEmpty) {
|
||||
debugPrint("No repeaters to export – nothing to share.");
|
||||
return gpxExportNoContacts;
|
||||
|
||||
@@ -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