-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to directly call Platform.is and make .isWeb constant
- Loading branch information
Showing
14 changed files
with
119 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/pubspec.lock | ||
/build/ | ||
|
||
# Web related | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export 'universal_platform_none.dart' | ||
if (dart.library.io) 'universal_platform_io.dart' | ||
if (dart.library.html) 'universal_platform_html.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'universal_platform_type.dart'; | ||
|
||
abstract class UniversalPlatform { | ||
static UniversalPlatformType get value => UniversalPlatform.Web; | ||
|
||
static bool get isAndroid => false; | ||
static bool get isFuchsia => false; | ||
static bool get isIOS => false; | ||
static bool get isLinux => false; | ||
static bool get isMacOS => false; | ||
static bool get isWindows => false; | ||
static bool get isOther => false; | ||
|
||
static const bool isWeb = true; | ||
static const bool isNone = false; | ||
|
||
static bool get isDesktop => isLinux || isMacOS || isWindows; | ||
static bool get isDesktopOrWeb => isDesktop || isWeb; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'dart:io' show Platform; | ||
|
||
import 'universal_platform_type.dart'; | ||
|
||
abstract class UniversalPlatform { | ||
static UniversalPlatformType get value { | ||
UniversalPlatformType result; | ||
if (Platform.isAndroid) { | ||
result = UniversalPlatformType.Android; | ||
} else if (Platform.isIOS) { | ||
result = UniversalPlatformType.IOS; | ||
} else if (Platform.isFuchsia) { | ||
result = UniversalPlatformType.Fuchsia; | ||
} else if (Platform.isLinux) { | ||
result = UniversalPlatformType.Linux; | ||
} else if (Platform.isMacOS) { | ||
result = UniversalPlatformType.MacOS; | ||
} else if (Platform.isWindows) { | ||
result = UniversalPlatformType.Windows; | ||
} else { | ||
result = UniversalPlatformType.Other; | ||
} | ||
return result; | ||
} | ||
|
||
static bool get isAndroid => Platform.isAndroid; | ||
static bool get isFuchsia => Platform.isFuchsia; | ||
static bool get isIOS => Platform.isIOS; | ||
static bool get isLinux => Platform.isLinux; | ||
static bool get isMacOS => Platform.isMacOS; | ||
static bool get isWindows => Platform.isWindows; | ||
static bool get isOther => | ||
UniversalPlatform.current == UniversalPlatformType.Other; | ||
|
||
static const bool isWeb = false; | ||
static const bool isNone = false; | ||
|
||
static bool get isDesktop => isLinux || isMacOS || isWindows; | ||
static bool get isDesktopOrWeb => isDesktop || isWeb; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'universal_platform_type.dart'; | ||
|
||
abstract class UniversalPlatform { | ||
static UniversalPlatformType get value => UniversalPlatform.None; | ||
|
||
static bool get isAndroid => false; | ||
static bool get isFuchsia => false; | ||
static bool get isIOS => false; | ||
static bool get isLinux => false; | ||
static bool get isMacOS => false; | ||
static bool get isWindows => false; | ||
static bool get isOther => false; | ||
|
||
static const bool isWeb = false; | ||
static const bool isNone = true; | ||
|
||
static bool get isDesktop => isLinux || isMacOS || isWindows; | ||
static bool get isDesktopOrWeb => isDesktop || isWeb; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
enum UniversalPlatformType { | ||
Web, | ||
Windows, | ||
Linux, | ||
MacOS, | ||
Android, | ||
Fuchsia, | ||
IOS, | ||
Other, | ||
None, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,2 @@ | ||
library universal_platform; | ||
import 'src/universal_platform_locator.dart' if(dart.library.io) 'src/platform_io.dart'; | ||
|
||
export 'src/universal_platform_locator.dart' if(dart.library.io) 'src/platform_io.dart'; | ||
|
||
abstract class UniversalPlatform { | ||
|
||
static UniversalPlatformType get value => currentUniversalPlatform; | ||
|
||
static bool get isWeb => currentUniversalPlatform == UniversalPlatformType.Web; | ||
static bool get isMacOS => currentUniversalPlatform == UniversalPlatformType.MacOS; | ||
static bool get isWindows => currentUniversalPlatform == UniversalPlatformType.Windows; | ||
static bool get isLinux => currentUniversalPlatform == UniversalPlatformType.Linux; | ||
static bool get isAndroid => currentUniversalPlatform == UniversalPlatformType.Android; | ||
static bool get isIOS => currentUniversalPlatform == UniversalPlatformType.IOS; | ||
static bool get isFuchsia => currentUniversalPlatform == UniversalPlatformType.Fuchsia; | ||
|
||
} | ||
|
||
enum UniversalPlatformType { | ||
Web, | ||
Windows, | ||
Linux, | ||
MacOS, | ||
Android, | ||
Fuchsia, | ||
IOS | ||
} | ||
export 'src/universal_platform.dart' show UniversalPlatform; | ||
export 'src/universal_platform_type.dart' show UniversalPlatformType; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
name: universal_platform | ||
description: Replacement for dart.io.Platform class which works on Web as well as Desktop and Mobile. Allows platform checks in your view/model layer easily. | ||
version: 1.0.0-nullsafety | ||
version: 1.1.0 | ||
homepage: https://github.com/gskinnerTeam/flutter-universal-platform | ||
|
||
environment: | ||
sdk: '>=2.12.0-dev <3.0.0' | ||
|
||
dependencies: |