This commit is contained in:
Salvatore Giordano
2021-02-26 17:12:03 +01:00
parent b8e29cd88c
commit a65df26626
5 changed files with 34 additions and 3 deletions
@@ -2,26 +2,56 @@ import 'platform_detector_stub.dart'
if (dart.library.html) 'platform_detector_web.dart' if (dart.library.html) 'platform_detector_web.dart'
if (dart.library.io) 'platform_detector_io.dart'; if (dart.library.io) 'platform_detector_io.dart';
/// Possible platforms
enum PlatformType { enum PlatformType {
///
Android, Android,
///
Ios, Ios,
///
Web, Web,
///
MacOS, MacOS,
///
Windows, Windows,
///
Linux, Linux,
///
Fuchsia, Fuchsia,
} }
/// Utility class that provides information on the current platform
class CurrentPlatform { class CurrentPlatform {
CurrentPlatform._(); CurrentPlatform._();
/// True if the app is running on android
static bool get isAndroid => type == PlatformType.Android; static bool get isAndroid => type == PlatformType.Android;
/// True if the app is running on ios
static bool get isIos => type == PlatformType.Ios; static bool get isIos => type == PlatformType.Ios;
/// True if the app is running on web
static bool get isWeb => type == PlatformType.Web; static bool get isWeb => type == PlatformType.Web;
/// True if the app is running on macos
static bool get isMacOS => type == PlatformType.MacOS; static bool get isMacOS => type == PlatformType.MacOS;
/// True if the app is running on windows
static bool get isWindows => type == PlatformType.Windows; static bool get isWindows => type == PlatformType.Windows;
/// True if the app is running on linux
static bool get isLinux => type == PlatformType.Linux; static bool get isLinux => type == PlatformType.Linux;
/// True if the app is running on fuchsia
static bool get isFuchsia => type == PlatformType.Fuchsia; static bool get isFuchsia => type == PlatformType.Fuchsia;
/// Returns a string version of the platform
static String get name { static String get name {
switch (type) { switch (type) {
case PlatformType.Android: case PlatformType.Android:
@@ -43,5 +73,6 @@ class CurrentPlatform {
} }
} }
/// Get current platform type
static PlatformType get type => currentPlatform; static PlatformType get type => currentPlatform;
} }
@@ -1,6 +1,7 @@
import 'dart:io'; import 'dart:io';
import 'platform_detector.dart'; import 'platform_detector.dart';
/// Version running on native systems
PlatformType get currentPlatform { PlatformType get currentPlatform {
if (Platform.isWindows) return PlatformType.Windows; if (Platform.isWindows) return PlatformType.Windows;
if (Platform.isFuchsia) return PlatformType.Fuchsia; if (Platform.isFuchsia) return PlatformType.Fuchsia;
@@ -1,5 +1,6 @@
import 'platform_detector.dart'; import 'platform_detector.dart';
/// Stub implementation
PlatformType get currentPlatform { PlatformType get currentPlatform {
throw UnimplementedError(); throw UnimplementedError();
} }
@@ -1,3 +1,4 @@
import 'platform_detector.dart'; import 'platform_detector.dart';
/// Version running on web
PlatformType get currentPlatform => PlatformType.Web; PlatformType get currentPlatform => PlatformType.Web;
@@ -1,6 +1,3 @@
import 'dart:async';
import 'dart:convert';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:flutter_slidable/flutter_slidable.dart';