Jonny Borges
Committed by GitHub

Merge pull request #539 from roipeker/master

Fixes and features
1 import 'package:flutter/material.dart'; 1 import 'package:flutter/material.dart';
2 import 'package:flutter/widgets.dart'; 2 import 'package:flutter/widgets.dart';
3 -import 'package:flutter/foundation.dart'; 3 +import 'package:get/get.dart';
4 4
5 extension ContextExtensionss on BuildContext { 5 extension ContextExtensionss on BuildContext {
6 /// The same of [MediaQuery.of(context).size] 6 /// The same of [MediaQuery.of(context).size]
@@ -117,8 +117,7 @@ extension ContextExtensionss on BuildContext { @@ -117,8 +117,7 @@ extension ContextExtensionss on BuildContext {
117 T watch, 117 T watch,
118 }) { 118 }) {
119 double deviceWidth = mediaQuerySize.shortestSide; 119 double deviceWidth = mediaQuerySize.shortestSide;
120 -  
121 - if (kIsWeb) { 120 + if (GetPlatform.isDesktop) {
122 deviceWidth = mediaQuerySize.width; 121 deviceWidth = mediaQuerySize.width;
123 } 122 }
124 if (deviceWidth >= 1200 && desktop != null) return desktop; 123 if (deviceWidth >= 1200 && desktop != null) return desktop;
@@ -3,6 +3,12 @@ import '../regex/get_utils.dart'; @@ -3,6 +3,12 @@ import '../regex/get_utils.dart';
3 extension GetDynamicUtils on dynamic { 3 extension GetDynamicUtils on dynamic {
4 /// It's This is overloading the IDE's options. Only the most useful and popular options will stay here. 4 /// It's This is overloading the IDE's options. Only the most useful and popular options will stay here.
5 5
  6 + /// In dart2js (in flutter v1.17) a var by default is undefined.
  7 + /// *Use this only if you are in version <- 1.17*.
  8 + /// So we assure the null type in json convertions to avoid the "value":value==null?null:value;
  9 + /// someVar.nil will force the null type if the var is null or undefined.
  10 + /// `nil` taken from ObjC just to have a shorter sintax.
  11 + dynamic get nil => GetUtils.nil(this);
6 bool get isNull => GetUtils.isNull(this); 12 bool get isNull => GetUtils.isNull(this);
7 bool get isNullOrBlank => GetUtils.isNullOrBlank(this); 13 bool get isNullOrBlank => GetUtils.isNullOrBlank(this);
8 14
@@ -8,4 +8,7 @@ class GetPlatform { @@ -8,4 +8,7 @@ class GetPlatform {
8 static bool get isAndroid => GeneralPlatform.isAndroid; 8 static bool get isAndroid => GeneralPlatform.isAndroid;
9 static bool get isIOS => GeneralPlatform.isIOS; 9 static bool get isIOS => GeneralPlatform.isIOS;
10 static bool get isFuchsia => GeneralPlatform.isFuchsia; 10 static bool get isFuchsia => GeneralPlatform.isFuchsia;
  11 + static bool get isMobile => GetPlatform.isIOS || GetPlatform.isAndroid;
  12 + static bool get isDesktop =>
  13 + GetPlatform.isMacOS || GetPlatform.isWindows || GetPlatform.isLinux;
11 } 14 }
@@ -8,4 +8,6 @@ class GeneralPlatform { @@ -8,4 +8,6 @@ class GeneralPlatform {
8 static bool get isAndroid => Platform.isAndroid; 8 static bool get isAndroid => Platform.isAndroid;
9 static bool get isIOS => Platform.isIOS; 9 static bool get isIOS => Platform.isIOS;
10 static bool get isFuchsia => Platform.isFuchsia; 10 static bool get isFuchsia => Platform.isFuchsia;
  11 + static bool get isDesktop =>
  12 + Platform.isMacOS || Platform.isWindows || Platform.isLinux;
11 } 13 }
  1 +// TODO: resolve platform/desktop by JS browser agent.
  2 +// ignore: avoid_web_libraries_in_flutter
  3 +import 'dart:html' as html;
  4 +
  5 +import 'package:get/utils.dart';
  6 +
  7 +html.Navigator _navigator = html.window.navigator;
  8 +
1 class GeneralPlatform { 9 class GeneralPlatform {
2 static bool get isWeb => true; 10 static bool get isWeb => true;
3 - static bool get isMacOS => false;  
4 - static bool get isWindows => false;  
5 - static bool get isLinux => false;  
6 - static bool get isAndroid => false;  
7 - static bool get isIOS => false; 11 +
  12 + static bool get isMacOS =>
  13 + _navigator.appVersion.contains('Mac OS') && !GeneralPlatform.isIOS;
  14 +
  15 + static bool get isWindows => _navigator.appVersion.contains('Win');
  16 +
  17 + static bool get isLinux =>
  18 + (_navigator.appVersion.contains('Linux') ||
  19 + _navigator.appVersion.contains('x11')) &&
  20 + !isAndroid;
  21 +
  22 + // @check https://developer.chrome.com/multidevice/user-agent
  23 + static bool get isAndroid => _navigator.appVersion.contains('Android ');
  24 +
  25 + static bool get isIOS {
  26 + // maxTouchPoints is needed to separate iPad iOS13 vs new MacOS
  27 + return GetUtils.hasMatch(_navigator.platform, r'/iPad|iPhone|iPod/') ||
  28 + (_navigator.platform == 'MacIntel' && _navigator.maxTouchPoints > 1);
  29 + }
  30 +
8 static bool get isFuchsia => false; 31 static bool get isFuchsia => false;
  32 + static bool get isDesktop => isMacOS || isWindows || isLinux;
9 } 33 }
@@ -2,6 +2,13 @@ class GetUtils { @@ -2,6 +2,13 @@ class GetUtils {
2 /// Checks if data is null. 2 /// Checks if data is null.
3 static bool isNull(dynamic s) => s == null; 3 static bool isNull(dynamic s) => s == null;
4 4
  5 + /// In dart2js (in flutter v1.17) a var by default is undefined.
  6 + /// *Use this only if you are in version <- 1.17*.
  7 + /// So we assure the null type in json convertions to avoid the "value":value==null?null:value;
  8 + /// someVar.nil will force the null type if the var is null or undefined.
  9 + /// `nil` taken from ObjC just to have a shorter sintax.
  10 + static dynamic nil(dynamic s) => s == null ? null : s;
  11 +
5 /// Checks if data is null or blank (empty or only contains whitespace). 12 /// Checks if data is null or blank (empty or only contains whitespace).
6 static bool isNullOrBlank(dynamic s) { 13 static bool isNullOrBlank(dynamic s) {
7 if (isNull(s)) return true; 14 if (isNull(s)) return true;
@@ -475,4 +482,6 @@ class GetUtils { @@ -475,4 +482,6 @@ class GetUtils {
475 482
476 static bool hasMatch(String s, Pattern p) => 483 static bool hasMatch(String s, Pattern p) =>
477 (s == null) ? false : RegExp(p).hasMatch(s); 484 (s == null) ? false : RegExp(p).hasMatch(s);
  485 +
  486 +
478 } 487 }