@@ -4,62 +4,113 @@ import 'package:device_info_plus/device_info_plus.dart';
44import 'package:flutter/foundation.dart'
55 show kIsWeb, TargetPlatform, defaultTargetPlatform;
66
7- bool isWeb () {
8- return kIsWeb;
7+ /// If you want to override the [kIsWeb] use [overrideIsWeb]
8+ bool isWeb ({bool ? overrideIsWeb}) {
9+ return overrideIsWeb ?? kIsWeb;
910}
1011
11- bool isMobile ([TargetPlatform ? targetPlatform]) {
12- if (isWeb ()) return false ;
13- targetPlatform ?? = defaultTargetPlatform;
14- return {TargetPlatform .iOS, TargetPlatform .android}.contains (targetPlatform);
12+ /// [supportWeb] is a parameter that ask you if we should care about web support
13+ /// if the value is true then we will return the result no matter if we are
14+ /// on web or using a native app to run the flutter app
15+ bool isMobile ({
16+ required bool supportWeb,
17+ TargetPlatform ? platform,
18+ bool ? overrideIsWeb,
19+ }) {
20+ if (isWeb (overrideIsWeb: overrideIsWeb) && ! supportWeb) return false ;
21+ platform ?? = defaultTargetPlatform;
22+ return {TargetPlatform .iOS, TargetPlatform .android}.contains (platform);
1523}
1624
17- bool isDesktop ([TargetPlatform ? targetPlatform]) {
18- if (isWeb ()) return false ;
19- targetPlatform ?? = defaultTargetPlatform;
25+ /// [supportWeb] is a parameter that ask you if we should care about web support
26+ /// if the value is true then we will return the result no matter if we are
27+ /// on web or using a native app to run the flutter app
28+ bool isDesktop ({
29+ required bool supportWeb,
30+ TargetPlatform ? platform,
31+ bool ? overrideIsWeb,
32+ }) {
33+ if (isWeb (overrideIsWeb: overrideIsWeb) && ! supportWeb) return false ;
34+ platform ?? = defaultTargetPlatform;
2035 return {TargetPlatform .macOS, TargetPlatform .linux, TargetPlatform .windows}
21- .contains (targetPlatform );
36+ .contains (platform );
2237}
2338
24- bool isKeyboardOS ([TargetPlatform ? targetPlatform]) {
25- targetPlatform ?? = defaultTargetPlatform;
26- return isDesktop (targetPlatform) || targetPlatform == TargetPlatform .fuchsia;
39+ /// [supportWeb] is a parameter that ask you if we should care about web support
40+ /// if the value is true then we will return the result no matter if we are
41+ /// on web or using a native app to run the flutter app
42+ bool isKeyboardOS ({
43+ required bool supportWeb,
44+ TargetPlatform ? platform,
45+ bool ? overrideIsWeb,
46+ }) {
47+ platform ?? = defaultTargetPlatform;
48+ return isDesktop (
49+ platform: platform,
50+ supportWeb: supportWeb,
51+ overrideIsWeb: overrideIsWeb) ||
52+ platform == TargetPlatform .fuchsia;
2753}
2854
29- bool isAppleOS ([TargetPlatform ? targetPlatform]) {
30- if (isWeb ()) return false ;
31- targetPlatform ?? = defaultTargetPlatform;
55+ /// [supportWeb] is a parameter that ask you if we should care about web support
56+ /// if the value is true then we will return the result no matter if we are
57+ /// on web or using a native app to run the flutter app
58+ bool isAppleOS ({
59+ required bool supportWeb,
60+ TargetPlatform ? platform,
61+ bool ? overrideIsWeb,
62+ }) {
63+ if (isWeb (overrideIsWeb: overrideIsWeb) && ! supportWeb) return false ;
64+ platform ?? = defaultTargetPlatform;
3265 return {
3366 TargetPlatform .macOS,
3467 TargetPlatform .iOS,
35- }.contains (targetPlatform );
68+ }.contains (platform );
3669}
3770
38- bool isMacOS ([TargetPlatform ? targetPlatform]) {
39- if (isWeb ()) return false ;
40- targetPlatform ?? = defaultTargetPlatform;
41- return TargetPlatform .macOS == targetPlatform;
71+ /// [supportWeb] is a parameter that ask you if we should care about web support
72+ /// if the value is true then we will return the result no matter if we are
73+ /// on web or using a native app to run the flutter app
74+ bool isMacOS ({
75+ required bool supportWeb,
76+ TargetPlatform ? platform,
77+ bool ? overrideIsWeb,
78+ }) {
79+ if (isWeb (overrideIsWeb: overrideIsWeb) && ! supportWeb) return false ;
80+ platform ?? = defaultTargetPlatform;
81+ return TargetPlatform .macOS == platform;
4282}
4383
44- bool isIOS ([TargetPlatform ? targetPlatform]) {
45- if (isWeb ()) return false ;
46- targetPlatform ?? = defaultTargetPlatform;
47- return TargetPlatform .iOS == targetPlatform;
84+ /// [supportWeb] is a parameter that ask you if we should care about web support
85+ /// if the value is true then we will return the result no matter if we are
86+ /// on web or using a native app to run the flutter app
87+ bool isIOS ({
88+ required bool supportWeb,
89+ TargetPlatform ? platform,
90+ bool ? overrideIsWeb,
91+ }) {
92+ if (isWeb (overrideIsWeb: overrideIsWeb) && ! supportWeb) return false ;
93+ platform ?? = defaultTargetPlatform;
94+ return TargetPlatform .iOS == platform;
4895}
4996
50- bool isAndroid ([TargetPlatform ? targetPlatform]) {
51- if (isWeb ()) return false ;
52- targetPlatform ?? = defaultTargetPlatform;
53- return TargetPlatform .android == targetPlatform;
97+ /// [supportWeb] is a parameter that ask you if we should care about web support
98+ /// if the value is true then we will return the result no matter if we are
99+ /// on web or using a native app to run the flutter app
100+ bool isAndroid ({
101+ required bool supportWeb,
102+ TargetPlatform ? platform,
103+ bool ? overrideIsWeb,
104+ }) {
105+ if (isWeb (overrideIsWeb: overrideIsWeb) && ! supportWeb) return false ;
106+ platform ?? = defaultTargetPlatform;
107+ return TargetPlatform .android == platform;
54108}
55109
56- bool isFlutterTest () {
57- if (isWeb ()) return false ;
58- return Platform .environment.containsKey ('FLUTTER_TEST' );
59- }
60-
61- Future <bool > isIOSSimulator () async {
62- if (! isAppleOS ()) {
110+ Future <bool > isIOSSimulator ({
111+ bool ? overrideIsWeb,
112+ }) async {
113+ if (! isAppleOS (supportWeb: false , overrideIsWeb: overrideIsWeb)) {
63114 return false ;
64115 }
65116
@@ -73,3 +124,10 @@ Future<bool> isIOSSimulator() async {
73124 }
74125 return false ;
75126}
127+
128+ bool isFlutterTest ({
129+ bool ? overrideIsWeb,
130+ }) {
131+ if (isWeb (overrideIsWeb: overrideIsWeb)) return false ;
132+ return Platform .environment.containsKey ('FLUTTER_TEST' );
133+ }
0 commit comments