Jonny Borges
Committed by GitHub

Merge pull request #2481 from jonataslaw/fix-nav2-example

Add Engine
@@ -12,7 +12,7 @@ class HomeController extends StateController<CasesModel> { @@ -12,7 +12,7 @@ class HomeController extends StateController<CasesModel> {
12 void onInit() { 12 void onInit() {
13 super.onInit(); 13 super.onInit();
14 //Loading, Success, Error handle with 1 line of code 14 //Loading, Success, Error handle with 1 line of code
15 - futurize(() => homeRepository.getCases); 15 + futurize(homeRepository.getCases);
16 } 16 }
17 17
18 Country getCountryById(String id) { 18 Country getCountryById(String id) {
@@ -2,12 +2,13 @@ @@ -2,12 +2,13 @@
2 FLUTTER_ROOT=/Users/jonatasborges/flutter 2 FLUTTER_ROOT=/Users/jonatasborges/flutter
3 FLUTTER_APPLICATION_PATH=/Users/jonatasborges/consertar/getx/example_nav2 3 FLUTTER_APPLICATION_PATH=/Users/jonatasborges/consertar/getx/example_nav2
4 COCOAPODS_PARALLEL_CODE_SIGN=true 4 COCOAPODS_PARALLEL_CODE_SIGN=true
5 -FLUTTER_TARGET=lib/main.dart 5 +FLUTTER_TARGET=/Users/jonatasborges/consertar/getx/example_nav2/lib/main.dart
6 FLUTTER_BUILD_DIR=build 6 FLUTTER_BUILD_DIR=build
7 FLUTTER_BUILD_NAME=1.0.0 7 FLUTTER_BUILD_NAME=1.0.0
8 FLUTTER_BUILD_NUMBER=1 8 FLUTTER_BUILD_NUMBER=1
9 EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386 9 EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386
  10 +DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==
10 DART_OBFUSCATION=false 11 DART_OBFUSCATION=false
11 -TRACK_WIDGET_CREATION=false 12 +TRACK_WIDGET_CREATION=true
12 TREE_SHAKE_ICONS=false 13 TREE_SHAKE_ICONS=false
13 -PACKAGE_CONFIG=.dart_tool/package_config.json 14 +PACKAGE_CONFIG=/Users/jonatasborges/consertar/getx/example_nav2/.dart_tool/package_config.json
@@ -3,11 +3,12 @@ @@ -3,11 +3,12 @@
3 export "FLUTTER_ROOT=/Users/jonatasborges/flutter" 3 export "FLUTTER_ROOT=/Users/jonatasborges/flutter"
4 export "FLUTTER_APPLICATION_PATH=/Users/jonatasborges/consertar/getx/example_nav2" 4 export "FLUTTER_APPLICATION_PATH=/Users/jonatasborges/consertar/getx/example_nav2"
5 export "COCOAPODS_PARALLEL_CODE_SIGN=true" 5 export "COCOAPODS_PARALLEL_CODE_SIGN=true"
6 -export "FLUTTER_TARGET=lib/main.dart" 6 +export "FLUTTER_TARGET=/Users/jonatasborges/consertar/getx/example_nav2/lib/main.dart"
7 export "FLUTTER_BUILD_DIR=build" 7 export "FLUTTER_BUILD_DIR=build"
8 export "FLUTTER_BUILD_NAME=1.0.0" 8 export "FLUTTER_BUILD_NAME=1.0.0"
9 export "FLUTTER_BUILD_NUMBER=1" 9 export "FLUTTER_BUILD_NUMBER=1"
  10 +export "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
10 export "DART_OBFUSCATION=false" 11 export "DART_OBFUSCATION=false"
11 -export "TRACK_WIDGET_CREATION=false" 12 +export "TRACK_WIDGET_CREATION=true"
12 export "TREE_SHAKE_ICONS=false" 13 export "TREE_SHAKE_ICONS=false"
13 -export "PACKAGE_CONFIG=.dart_tool/package_config.json" 14 +export "PACKAGE_CONFIG=/Users/jonatasborges/consertar/getx/example_nav2/.dart_tool/package_config.json"
@@ -41,5 +41,7 @@ @@ -41,5 +41,7 @@
41 </array> 41 </array>
42 <key>UIViewControllerBasedStatusBarAppearance</key> 42 <key>UIViewControllerBasedStatusBarAppearance</key>
43 <false/> 43 <false/>
  44 + <key>CADisableMinimumFrameDurationOnPhone</key>
  45 + <true/>
44 </dict> 46 </dict>
45 </plist> 47 </plist>
@@ -14,11 +14,12 @@ class HomeView extends GetView<HomeController> { @@ -14,11 +14,12 @@ class HomeView extends GetView<HomeController> {
14 final delegate = context.navigation; 14 final delegate = context.navigation;
15 //This router outlet handles the appbar and the bottom navigation bar 15 //This router outlet handles the appbar and the bottom navigation bar
16 final currentLocation = context.location; 16 final currentLocation = context.location;
  17 + print(currentLocation);
17 var currentIndex = 0; 18 var currentIndex = 0;
18 if (currentLocation.startsWith(Routes.products) == true) { 19 if (currentLocation.startsWith(Routes.products) == true) {
19 currentIndex = 2; 20 currentIndex = 2;
20 } 21 }
21 - if (currentLocation.startsWith(Routes.products) == true) { 22 + if (currentLocation.startsWith(Routes.profile) == true) {
22 currentIndex = 1; 23 currentIndex = 1;
23 } 24 }
24 return Scaffold( 25 return Scaffold(
@@ -73,12 +73,15 @@ class AppPages { @@ -73,12 +73,15 @@ class AppPages {
73 name: _Paths.products, 73 name: _Paths.products,
74 page: () => const ProductsView(), 74 page: () => const ProductsView(),
75 title: 'Products', 75 title: 'Products',
76 - transition: Transition.zoom, 76 + transition: Transition.cupertino,
  77 + showCupertinoParallax: true,
77 participatesInRootNavigator: false, 78 participatesInRootNavigator: false,
78 bindings: [ProductsBinding()], 79 bindings: [ProductsBinding()],
79 children: [ 80 children: [
80 GetPage( 81 GetPage(
81 name: _Paths.productDetails, 82 name: _Paths.productDetails,
  83 + transition: Transition.cupertino,
  84 + showCupertinoParallax: true,
82 page: () => ProductDetailsView(), 85 page: () => ProductDetailsView(),
83 bindings: [ProductDetailsBinding()], 86 bindings: [ProductDetailsBinding()],
84 middlewares: [ 87 middlewares: [
@@ -3,7 +3,7 @@ version: 1.0.0+1 @@ -3,7 +3,7 @@ version: 1.0.0+1
3 publish_to: none 3 publish_to: none
4 description: A new Flutter project. 4 description: A new Flutter project.
5 environment: 5 environment:
6 - sdk: ">=2.12.0 <3.0.0" 6 + sdk: ">=2.17.0 <3.0.0"
7 7
8 dependencies: 8 dependencies:
9 cupertino_icons: ^1.0.2 9 cupertino_icons: ^1.0.2
1 library get_core; 1 library get_core;
2 2
  3 +export 'src/flutter_engine.dart';
3 export 'src/get_interface.dart'; 4 export 'src/get_interface.dart';
4 export 'src/get_main.dart'; 5 export 'src/get_main.dart';
5 export 'src/log.dart'; 6 export 'src/log.dart';
6 -  
7 export 'src/smart_management.dart'; 7 export 'src/smart_management.dart';
8 -  
9 export 'src/typedefs.dart'; 8 export 'src/typedefs.dart';
  1 +import 'package:flutter/widgets.dart';
  2 +
  3 +class Engine{
  4 + static WidgetsBinding get instance {
  5 + return WidgetsFlutterBinding.ensureInitialized();
  6 + }
  7 +}
1 import 'package:flutter/foundation.dart'; 1 import 'package:flutter/foundation.dart';
2 -import 'package:flutter/scheduler.dart';  
3 2
4 import '../../get.dart'; 3 import '../../get.dart';
5 4
@@ -18,7 +17,8 @@ mixin GetLifeCycleMixin { @@ -18,7 +17,8 @@ mixin GetLifeCycleMixin {
18 @protected 17 @protected
19 @mustCallSuper 18 @mustCallSuper
20 void onInit() { 19 void onInit() {
21 - ambiguate(SchedulerBinding.instance) 20 +
  21 + ambiguate(Engine.instance)
22 ?.addPostFrameCallback((_) => onReady()); 22 ?.addPostFrameCallback((_) => onReady());
23 } 23 }
24 24
1 import 'dart:ui' as ui; 1 import 'dart:ui' as ui;
2 2
3 import 'package:flutter/material.dart'; 3 import 'package:flutter/material.dart';
4 -import 'package:flutter/scheduler.dart';  
5 4
6 import '../../get_core/get_core.dart'; 5 import '../../get_core/get_core.dart';
7 import '../../get_instance/src/bindings_interface.dart'; 6 import '../../get_instance/src/bindings_interface.dart';
@@ -358,7 +357,7 @@ extension ExtensionSnackbar on GetInterface { @@ -358,7 +357,7 @@ extension ExtensionSnackbar on GetInterface {
358 if (instantInit) { 357 if (instantInit) {
359 controller.show(); 358 controller.show();
360 } else { 359 } else {
361 - ambiguate(SchedulerBinding.instance)!.addPostFrameCallback((_) { 360 + ambiguate(Engine.instance)!.addPostFrameCallback((_) {
362 controller.show(); 361 controller.show();
363 }); 362 });
364 } 363 }
@@ -469,7 +468,7 @@ extension ExtensionSnackbar on GetInterface { @@ -469,7 +468,7 @@ extension ExtensionSnackbar on GetInterface {
469 controller.show(); 468 controller.show();
470 } else { 469 } else {
471 //routing.isSnackbar = true; 470 //routing.isSnackbar = true;
472 - ambiguate(SchedulerBinding.instance)!.addPostFrameCallback((_) { 471 + ambiguate(Engine.instance)!.addPostFrameCallback((_) {
473 controller.show(); 472 controller.show();
474 }); 473 });
475 } 474 }
@@ -1170,14 +1169,14 @@ extension GetNavigationExt on GetInterface { @@ -1170,14 +1169,14 @@ extension GetNavigationExt on GetInterface {
1170 } 1169 }
1171 1170
1172 /// The window to which this binding is bound. 1171 /// The window to which this binding is bound.
1173 - ui.SingletonFlutterWindow get window => ui.window; 1172 + ui.SingletonFlutterWindow get window => engine.window;
1174 1173
1175 - Locale? get deviceLocale => ui.window.locale; 1174 + Locale? get deviceLocale => engine.window.locale;
1176 1175
1177 ///The number of device pixels for each logical pixel. 1176 ///The number of device pixels for each logical pixel.
1178 - double get pixelRatio => ui.window.devicePixelRatio; 1177 + double get pixelRatio => engine.window.devicePixelRatio;
1179 1178
1180 - Size get size => ui.window.physicalSize / pixelRatio; 1179 + Size get size => engine.window.physicalSize / pixelRatio;
1181 1180
1182 ///The horizontal extent of this size. 1181 ///The horizontal extent of this size.
1183 double get width => size.width; 1182 double get width => size.width;
@@ -1187,14 +1186,14 @@ extension GetNavigationExt on GetInterface { @@ -1187,14 +1186,14 @@ extension GetNavigationExt on GetInterface {
1187 1186
1188 ///The distance from the top edge to the first unpadded pixel, 1187 ///The distance from the top edge to the first unpadded pixel,
1189 ///in physical pixels. 1188 ///in physical pixels.
1190 - double get statusBarHeight => ui.window.padding.top; 1189 + double get statusBarHeight => engine.window.padding.top;
1191 1190
1192 ///The distance from the bottom edge to the first unpadded pixel, 1191 ///The distance from the bottom edge to the first unpadded pixel,
1193 ///in physical pixels. 1192 ///in physical pixels.
1194 - double get bottomBarHeight => ui.window.padding.bottom; 1193 + double get bottomBarHeight => engine.window.padding.bottom;
1195 1194
1196 ///The system-reported text scale. 1195 ///The system-reported text scale.
1197 - double get textScaleFactor => ui.window.textScaleFactor; 1196 + double get textScaleFactor => engine.window.textScaleFactor;
1198 1197
1199 /// give access to TextTheme.of(context) 1198 /// give access to TextTheme.of(context)
1200 TextTheme get textTheme => theme.textTheme; 1199 TextTheme get textTheme => theme.textTheme;
@@ -1260,41 +1259,8 @@ extension GetNavigationExt on GetInterface { @@ -1260,41 +1259,8 @@ extension GetNavigationExt on GetInterface {
1260 TDelegate? delegate<TDelegate extends RouterDelegate<TPage>, TPage>() => 1259 TDelegate? delegate<TDelegate extends RouterDelegate<TPage>, TPage>() =>
1261 _getxController.routerDelegate as TDelegate?; 1260 _getxController.routerDelegate as TDelegate?;
1262 1261
1263 - // void resetRootNavigator() {  
1264 - // _getxController = GetMaterialController();  
1265 - // }  
1266 -  
1267 - // RouterDelegate? get routerDelegate => _getxController.routerDelegate;  
1268 - // RouteInformationParser? get routeInformationParser =>  
1269 - // _getxController.routeInformationParser;  
1270 1262
1271 GetMaterialController get _getxController => GetMaterialController.to; 1263 GetMaterialController get _getxController => GetMaterialController.to;
1272 -  
1273 - // void addPages(List<GetPage> getPages) {  
1274 - // routeTree.addRoutes(getPages);  
1275 - // }  
1276 -  
1277 - // void clearRouteTree() {  
1278 - // routeTree.routes.clear();  
1279 - // }  
1280 -  
1281 - // ParseRouteTree get routeTree {  
1282 - // final delegate = _getxController.routerDelegate;  
1283 - // if (delegate is GetDelegate) {  
1284 - // return delegate.routeTree;  
1285 - // } else {  
1286 - // //TODO: Urgent: Refactor this  
1287 - // return ParseRouteTree(routes: []);  
1288 - // }  
1289 - // }  
1290 -  
1291 - // void addPage(GetPage getPage) {  
1292 - // routeTree.addRoute(getPage);  
1293 - // }  
1294 -  
1295 - // void removePage(GetPage getPage) {  
1296 - // routeTree.removeRoute(getPage);  
1297 - // }  
1298 } 1264 }
1299 1265
1300 extension OverlayExt on GetInterface { 1266 extension OverlayExt on GetInterface {
@@ -61,7 +61,7 @@ class RouterReportManager<T> { @@ -61,7 +61,7 @@ class RouterReportManager<T> {
61 61
62 void reportRouteDispose(T disposed) { 62 void reportRouteDispose(T disposed) {
63 if (Get.smartManagement != SmartManagement.onlyBuilder) { 63 if (Get.smartManagement != SmartManagement.onlyBuilder) {
64 - ambiguate(WidgetsBinding.instance)!.addPostFrameCallback((_) { 64 + ambiguate(Engine.instance)!.addPostFrameCallback((_) {
65 _removeDependencyByRoute(disposed); 65 _removeDependencyByRoute(disposed);
66 }); 66 });
67 } 67 }
@@ -560,12 +560,6 @@ class GetDelegate extends RouterDelegate<RouteDecoder> @@ -560,12 +560,6 @@ class GetDelegate extends RouterDelegate<RouteDecoder>
560 _activePages.remove(RouteDecoder.fromRoute(name)); 560 _activePages.remove(RouteDecoder.fromRoute(name));
561 } 561 }
562 562
563 - @override  
564 - void back<T>([T? result]) {  
565 - _checkIfCanBack();  
566 - _popWithResult<T>(result);  
567 - notifyListeners();  
568 - }  
569 563
570 bool get canBack { 564 bool get canBack {
571 return _activePages.length > 1; 565 return _activePages.length > 1;
@@ -799,21 +793,30 @@ class GetDelegate extends RouterDelegate<RouteDecoder> @@ -799,21 +793,30 @@ class GetDelegate extends RouterDelegate<RouteDecoder>
799 return false; 793 return false;
800 } 794 }
801 795
  796 + @override
  797 + void back<T>([T? result]) {
  798 + _checkIfCanBack();
  799 + _popWithResult<T>(result);
  800 + notifyListeners();
  801 + }
  802 +
  803 +
802 bool _onPopVisualRoute(Route<dynamic> route, dynamic result) { 804 bool _onPopVisualRoute(Route<dynamic> route, dynamic result) {
803 final didPop = route.didPop(result); 805 final didPop = route.didPop(result);
804 if (!didPop) { 806 if (!didPop) {
805 return false; 807 return false;
806 } 808 }
807 - final settings = route.settings;  
808 - if (settings is GetPage) {  
809 - final config = _activePages.cast<RouteDecoder?>().firstWhere(  
810 - (element) => element?.route == settings,  
811 - orElse: () => null,  
812 - );  
813 - if (config != null) {  
814 - _removeHistoryEntry(config, result);  
815 - }  
816 - } 809 + _popWithResult(result);
  810 + // final settings = route.settings;
  811 + // if (settings is GetPage) {
  812 + // final config = _activePages.cast<RouteDecoder?>().firstWhere(
  813 + // (element) => element?.route == settings,
  814 + // orElse: () => null,
  815 + // );
  816 + // if (config != null) {
  817 + // _removeHistoryEntry(config, result);
  818 + // }
  819 + // }
817 notifyListeners(); 820 notifyListeners();
818 //return !route.navigator!.userGestureInProgress; 821 //return !route.navigator!.userGestureInProgress;
819 return true; 822 return true;
@@ -2,7 +2,6 @@ import 'dart:async'; @@ -2,7 +2,6 @@ import 'dart:async';
2 import 'dart:ui'; 2 import 'dart:ui';
3 3
4 import 'package:flutter/material.dart'; 4 import 'package:flutter/material.dart';
5 -import 'package:flutter/scheduler.dart';  
6 5
7 import '../../../get_core/get_core.dart'; 6 import '../../../get_core/get_core.dart';
8 import '../../get_navigation.dart'; 7 import '../../get_navigation.dart';
@@ -449,7 +448,7 @@ You need to either use message[String], or messageText[Widget] or define a userI @@ -449,7 +448,7 @@ You need to either use message[String], or messageText[Widget] or define a userI
449 } 448 }
450 449
451 void _configureLeftBarFuture() { 450 void _configureLeftBarFuture() {
452 - ambiguate(SchedulerBinding.instance)!.addPostFrameCallback( 451 + ambiguate(Engine.instance)!.addPostFrameCallback(
453 (_) { 452 (_) {
454 final keyContext = _backgroundBoxKey.currentContext; 453 final keyContext = _backgroundBoxKey.currentContext;
455 if (keyContext != null) { 454 if (keyContext != null) {
@@ -2,6 +2,7 @@ import 'dart:async'; @@ -2,6 +2,7 @@ import 'dart:async';
2 2
3 import 'package:flutter/foundation.dart'; 3 import 'package:flutter/foundation.dart';
4 import 'package:flutter/material.dart'; 4 import 'package:flutter/material.dart';
  5 +import 'package:get/utils.dart';
5 6
6 import '../../../get_rx/src/rx_types/rx_types.dart'; 7 import '../../../get_rx/src/rx_types/rx_types.dart';
7 import '../../../instance_manager.dart'; 8 import '../../../instance_manager.dart';
@@ -70,9 +71,10 @@ mixin StateMixin<T> on ListNotifier { @@ -70,9 +71,10 @@ mixin StateMixin<T> on ListNotifier {
70 } 71 }
71 } 72 }
72 73
73 - void futurize(Future<T> Function() Function() body,  
74 - {String? errorMessage, bool useEmpty = true}) {  
75 - final compute = body(); 74 + void futurize(Future<T> Function() body,
  75 + {T? initialData, String? errorMessage, bool useEmpty = true}) {
  76 + final compute = body;
  77 + _value ??= initialData;
76 compute().then((newValue) { 78 compute().then((newValue) {
77 if ((newValue == null || newValue._isEmpty()) && useEmpty) { 79 if ((newValue == null || newValue._isEmpty()) && useEmpty) {
78 status = GetStatus<T>.loading(); 80 status = GetStatus<T>.loading();
@@ -88,6 +90,10 @@ mixin StateMixin<T> on ListNotifier { @@ -88,6 +90,10 @@ mixin StateMixin<T> on ListNotifier {
88 } 90 }
89 } 91 }
90 92
  93 +typedef FuturizeCallback<T> = Future<T> Function(VoidCallback fn);
  94 +
  95 +typedef VoidCallback = void Function();
  96 +
91 class GetListenable<T> extends ListNotifierSingle implements RxInterface<T> { 97 class GetListenable<T> extends ListNotifierSingle implements RxInterface<T> {
92 GetListenable(T val) : _value = val; 98 GetListenable(T val) : _value = val;
93 99
@@ -239,28 +245,45 @@ extension StateExt<T> on StateMixin<T> { @@ -239,28 +245,45 @@ extension StateExt<T> on StateMixin<T> {
239 245
240 typedef NotifierBuilder<T> = Widget Function(T state); 246 typedef NotifierBuilder<T> = Widget Function(T state);
241 247
242 -abstract class GetStatus<T> { 248 +abstract class GetStatus<T> with Equality {
243 const GetStatus(); 249 const GetStatus();
244 factory GetStatus.loading() => LoadingStatus(); 250 factory GetStatus.loading() => LoadingStatus();
245 factory GetStatus.error(String message) => ErrorStatus(message); 251 factory GetStatus.error(String message) => ErrorStatus(message);
246 factory GetStatus.empty() => EmptyStatus(); 252 factory GetStatus.empty() => EmptyStatus();
247 factory GetStatus.success(T data) => SuccessStatus(data); 253 factory GetStatus.success(T data) => SuccessStatus(data);
  254 + factory GetStatus.custom() => CustomStatus();
  255 +}
  256 +
  257 +class CustomStatus<T> extends GetStatus<T> {
  258 + @override
  259 + List get props => [];
248 } 260 }
249 261
250 -class LoadingStatus<T> extends GetStatus<T> {} 262 +class LoadingStatus<T> extends GetStatus<T> {
  263 + @override
  264 + List get props => [];
  265 +}
251 266
252 class SuccessStatus<T> extends GetStatus<T> { 267 class SuccessStatus<T> extends GetStatus<T> {
253 final T data; 268 final T data;
  269 + const SuccessStatus(this.data);
254 270
255 - SuccessStatus(this.data); 271 + @override
  272 + List get props => [data];
256 } 273 }
257 274
258 class ErrorStatus<T, S> extends GetStatus<T> { 275 class ErrorStatus<T, S> extends GetStatus<T> {
259 final S? error; 276 final S? error;
260 - ErrorStatus([this.error]); 277 + const ErrorStatus([this.error]);
  278 +
  279 + @override
  280 + List get props => [error];
261 } 281 }
262 282
263 -class EmptyStatus<T> extends GetStatus<T> {} 283 +class EmptyStatus<T> extends GetStatus<T> {
  284 + @override
  285 + List get props => [];
  286 +}
264 287
265 extension StatusDataExt<T> on GetStatus<T> { 288 extension StatusDataExt<T> on GetStatus<T> {
266 bool get isLoading => this is LoadingStatus; 289 bool get isLoading => this is LoadingStatus;
@@ -96,13 +96,13 @@ mixin FullLifeCycleMixin on FullLifeCycleController { @@ -96,13 +96,13 @@ mixin FullLifeCycleMixin on FullLifeCycleController {
96 @override 96 @override
97 void onInit() { 97 void onInit() {
98 super.onInit(); 98 super.onInit();
99 - ambiguate(WidgetsBinding.instance)!.addObserver(this); 99 + ambiguate(Engine.instance)!.addObserver(this);
100 } 100 }
101 101
102 @mustCallSuper 102 @mustCallSuper
103 @override 103 @override
104 void onClose() { 104 void onClose() {
105 - ambiguate(WidgetsBinding.instance)!.removeObserver(this); 105 + ambiguate(Engine.instance)!.removeObserver(this);
106 super.onClose(); 106 super.onClose();
107 } 107 }
108 108