Rodrigo Lopez Peker

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)
import 'dart:math';
import 'dart:ui' show lerpDouble;
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
... ... @@ -7,6 +8,7 @@ import 'package:get/route_manager.dart';
import 'package:get/src/core/get_main.dart';
import 'package:get/src/instance/get_instance.dart';
import 'package:get/utils.dart';
import 'bindings_interface.dart';
import 'custom_transition.dart';
import 'default_transitions.dart';
... ... @@ -41,7 +43,7 @@ class GetPageRoute<T> extends PageRoute<T> {
@override
final Duration transitionDuration;
final GetPageBuilder page;
final WidgetCallback page;
final String routeName;
... ...
import 'package:flutter/widgets.dart';
import 'package:get/src/navigation/routes/bindings_interface.dart';
import 'custom_transition.dart';
import 'transitions_type.dart';
class GetPage {
final String name;
final GetPageBuilder page;
final WidgetCallback page;
final bool popGesture;
final Map<String, String> parameter;
final String title;
... ...
... ... @@ -18,4 +18,4 @@ enum Transition {
native
}
typedef GetPageBuilder = Widget Function();
typedef WidgetCallback = Widget Function();
... ...
import 'dart:async';
import 'package:flutter/widgets.dart';
import 'package:get/src/navigation/routes/transitions_type.dart';
import 'package:get/src/state_manager/rx/rx_interface.dart';
import 'rx_impl.dart';
import 'rx_impl.dart';
/// The simplest reactive widget in GetX.
///
... ... @@ -13,7 +14,7 @@ import 'rx_impl.dart';
/// final _name = "GetX".obs;
/// Obx(() => Text( _name.value )),... ;
class Obx extends StatefulWidget {
final Widget Function() builder;
final WidgetCallback builder;
const Obx(this.builder);
_ObxState createState() => _ObxState();
... ...
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
extension ContextExtensionss on BuildContext {
/// The same of [MediaQuery.of(context).size]
... ... @@ -117,8 +117,7 @@ extension ContextExtensionss on BuildContext {
T watch,
}) {
double deviceWidth = mediaQuerySize.shortestSide;
if (kIsWeb) {
if (GetPlatform.isDesktop) {
deviceWidth = mediaQuerySize.width;
}
if (deviceWidth >= 1200 && desktop != null) return desktop;
... ...
... ... @@ -3,6 +3,12 @@ import '../regex/get_utils.dart';
extension GetDynamicUtils on dynamic {
/// It's This is overloading the IDE's options. Only the most useful and popular options will stay here.
/// In dart2js (in flutter v1.17) a var by default is undefined.
/// *Use this only if you are in version <- 1.17*.
/// So we assure the null type in json convertions to avoid the "value":value==null?null:value;
/// someVar.nil will force the null type if the var is null or undefined.
/// `nil` taken from ObjC just to have a shorter sintax.
dynamic get nil => GetUtils.nil(this);
bool get isNull => GetUtils.isNull(this);
bool get isNullOrBlank => GetUtils.isNullOrBlank(this);
... ...
... ... @@ -8,4 +8,7 @@ class GetPlatform {
static bool get isAndroid => GeneralPlatform.isAndroid;
static bool get isIOS => GeneralPlatform.isIOS;
static bool get isFuchsia => GeneralPlatform.isFuchsia;
static bool get isMobile => GetPlatform.isIOS || GetPlatform.isAndroid;
static bool get isDesktop =>
GetPlatform.isMacOS || GetPlatform.isWindows || GetPlatform.isLinux;
}
... ...
... ... @@ -8,4 +8,6 @@ class GeneralPlatform {
static bool get isAndroid => Platform.isAndroid;
static bool get isIOS => Platform.isIOS;
static bool get isFuchsia => Platform.isFuchsia;
static bool get isDesktop =>
Platform.isMacOS || Platform.isWindows || Platform.isLinux;
}
... ...
// TODO: resolve platform/desktop by JS browser agent.
// ignore: avoid_web_libraries_in_flutter
import 'dart:html' as html;
import 'package:get/utils.dart';
html.Navigator _navigator = html.window.navigator;
class GeneralPlatform {
static bool get isWeb => true;
static bool get isMacOS => false;
static bool get isWindows => false;
static bool get isLinux => false;
static bool get isAndroid => false;
static bool get isIOS => false;
static bool get isMacOS =>
_navigator.appVersion.contains('Mac OS') && !GeneralPlatform.isIOS;
static bool get isWindows => _navigator.appVersion.contains('Win');
static bool get isLinux =>
(_navigator.appVersion.contains('Linux') ||
_navigator.appVersion.contains('x11')) &&
!isAndroid;
// @check https://developer.chrome.com/multidevice/user-agent
static bool get isAndroid => _navigator.appVersion.contains('Android ');
static bool get isIOS {
// maxTouchPoints is needed to separate iPad iOS13 vs new MacOS
return GetUtils.hasMatch(_navigator.platform, r'/iPad|iPhone|iPod/') ||
(_navigator.platform == 'MacIntel' && _navigator.maxTouchPoints > 1);
}
static bool get isFuchsia => false;
static bool get isDesktop => isMacOS || isWindows || isLinux;
}
... ...
... ... @@ -2,6 +2,13 @@ class GetUtils {
/// Checks if data is null.
static bool isNull(dynamic s) => s == null;
/// In dart2js (in flutter v1.17) a var by default is undefined.
/// *Use this only if you are in version <- 1.17*.
/// So we assure the null type in json convertions to avoid the "value":value==null?null:value;
/// someVar.nil will force the null type if the var is null or undefined.
/// `nil` taken from ObjC just to have a shorter sintax.
static dynamic nil(dynamic s) => s == null ? null : s;
/// Checks if data is null or blank (empty or only contains whitespace).
static bool isNullOrBlank(dynamic s) {
if (isNull(s)) return true;
... ... @@ -475,4 +482,6 @@ class GetUtils {
static bool hasMatch(String s, Pattern p) =>
(s == null) ? false : RegExp(p).hasMatch(s);
}
... ...