Fixes and features
- Change GetPageBuilder to WidgetCallback typedef, so we can use it outside Get and the name makes more sense. - Added isDesktop/isMobile - Added GetPlatform (web) getters to detect the OS it runs (using navigator UA) - Added nil extension (can be useless now), to enforce the null type safety in JS for old dart2js versions (was undefined)
Showing
10 changed files
with
61 additions
and
14 deletions
1 | import 'dart:math'; | 1 | import 'dart:math'; |
2 | import 'dart:ui' show lerpDouble; | 2 | import 'dart:ui' show lerpDouble; |
3 | + | ||
3 | import 'package:flutter/cupertino.dart'; | 4 | import 'package:flutter/cupertino.dart'; |
4 | import 'package:flutter/gestures.dart'; | 5 | import 'package:flutter/gestures.dart'; |
5 | import 'package:flutter/material.dart'; | 6 | import 'package:flutter/material.dart'; |
@@ -7,6 +8,7 @@ import 'package:get/route_manager.dart'; | @@ -7,6 +8,7 @@ import 'package:get/route_manager.dart'; | ||
7 | import 'package:get/src/core/get_main.dart'; | 8 | import 'package:get/src/core/get_main.dart'; |
8 | import 'package:get/src/instance/get_instance.dart'; | 9 | import 'package:get/src/instance/get_instance.dart'; |
9 | import 'package:get/utils.dart'; | 10 | import 'package:get/utils.dart'; |
11 | + | ||
10 | import 'bindings_interface.dart'; | 12 | import 'bindings_interface.dart'; |
11 | import 'custom_transition.dart'; | 13 | import 'custom_transition.dart'; |
12 | import 'default_transitions.dart'; | 14 | import 'default_transitions.dart'; |
@@ -41,7 +43,7 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -41,7 +43,7 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
41 | @override | 43 | @override |
42 | final Duration transitionDuration; | 44 | final Duration transitionDuration; |
43 | 45 | ||
44 | - final GetPageBuilder page; | 46 | + final WidgetCallback page; |
45 | 47 | ||
46 | final String routeName; | 48 | final String routeName; |
47 | 49 |
1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
2 | import 'package:get/src/navigation/routes/bindings_interface.dart'; | 2 | import 'package:get/src/navigation/routes/bindings_interface.dart'; |
3 | + | ||
3 | import 'custom_transition.dart'; | 4 | import 'custom_transition.dart'; |
4 | import 'transitions_type.dart'; | 5 | import 'transitions_type.dart'; |
5 | 6 | ||
6 | class GetPage { | 7 | class GetPage { |
7 | final String name; | 8 | final String name; |
8 | - final GetPageBuilder page; | 9 | + final WidgetCallback page; |
9 | final bool popGesture; | 10 | final bool popGesture; |
10 | final Map<String, String> parameter; | 11 | final Map<String, String> parameter; |
11 | final String title; | 12 | final String title; |
1 | import 'dart:async'; | 1 | import 'dart:async'; |
2 | + | ||
2 | import 'package:flutter/widgets.dart'; | 3 | import 'package:flutter/widgets.dart'; |
4 | +import 'package:get/src/navigation/routes/transitions_type.dart'; | ||
3 | import 'package:get/src/state_manager/rx/rx_interface.dart'; | 5 | import 'package:get/src/state_manager/rx/rx_interface.dart'; |
4 | -import 'rx_impl.dart'; | ||
5 | - | ||
6 | 6 | ||
7 | +import 'rx_impl.dart'; | ||
7 | 8 | ||
8 | /// The simplest reactive widget in GetX. | 9 | /// The simplest reactive widget in GetX. |
9 | /// | 10 | /// |
@@ -13,7 +14,7 @@ import 'rx_impl.dart'; | @@ -13,7 +14,7 @@ import 'rx_impl.dart'; | ||
13 | /// final _name = "GetX".obs; | 14 | /// final _name = "GetX".obs; |
14 | /// Obx(() => Text( _name.value )),... ; | 15 | /// Obx(() => Text( _name.value )),... ; |
15 | class Obx extends StatefulWidget { | 16 | class Obx extends StatefulWidget { |
16 | - final Widget Function() builder; | 17 | + final WidgetCallback builder; |
17 | 18 | ||
18 | const Obx(this.builder); | 19 | const Obx(this.builder); |
19 | _ObxState createState() => _ObxState(); | 20 | _ObxState createState() => _ObxState(); |
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 | } |
-
Please register or login to post a comment