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> {
void onInit() {
super.onInit();
//Loading, Success, Error handle with 1 line of code
futurize(() => homeRepository.getCases);
futurize(homeRepository.getCases);
}
Country getCountryById(String id) {
... ...
... ... @@ -2,12 +2,13 @@
FLUTTER_ROOT=/Users/jonatasborges/flutter
FLUTTER_APPLICATION_PATH=/Users/jonatasborges/consertar/getx/example_nav2
COCOAPODS_PARALLEL_CODE_SIGN=true
FLUTTER_TARGET=lib/main.dart
FLUTTER_TARGET=/Users/jonatasborges/consertar/getx/example_nav2/lib/main.dart
FLUTTER_BUILD_DIR=build
FLUTTER_BUILD_NAME=1.0.0
FLUTTER_BUILD_NUMBER=1
EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386
DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==
DART_OBFUSCATION=false
TRACK_WIDGET_CREATION=false
TRACK_WIDGET_CREATION=true
TREE_SHAKE_ICONS=false
PACKAGE_CONFIG=.dart_tool/package_config.json
PACKAGE_CONFIG=/Users/jonatasborges/consertar/getx/example_nav2/.dart_tool/package_config.json
... ...
... ... @@ -3,11 +3,12 @@
export "FLUTTER_ROOT=/Users/jonatasborges/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/jonatasborges/consertar/getx/example_nav2"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_TARGET=/Users/jonatasborges/consertar/getx/example_nav2/lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
export "PACKAGE_CONFIG=/Users/jonatasborges/consertar/getx/example_nav2/.dart_tool/package_config.json"
... ...
... ... @@ -41,5 +41,7 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
</dict>
</plist>
... ...
... ... @@ -14,11 +14,12 @@ class HomeView extends GetView<HomeController> {
final delegate = context.navigation;
//This router outlet handles the appbar and the bottom navigation bar
final currentLocation = context.location;
print(currentLocation);
var currentIndex = 0;
if (currentLocation.startsWith(Routes.products) == true) {
currentIndex = 2;
}
if (currentLocation.startsWith(Routes.products) == true) {
if (currentLocation.startsWith(Routes.profile) == true) {
currentIndex = 1;
}
return Scaffold(
... ...
... ... @@ -73,12 +73,15 @@ class AppPages {
name: _Paths.products,
page: () => const ProductsView(),
title: 'Products',
transition: Transition.zoom,
transition: Transition.cupertino,
showCupertinoParallax: true,
participatesInRootNavigator: false,
bindings: [ProductsBinding()],
children: [
GetPage(
name: _Paths.productDetails,
transition: Transition.cupertino,
showCupertinoParallax: true,
page: () => ProductDetailsView(),
bindings: [ProductDetailsBinding()],
middlewares: [
... ...
... ... @@ -3,7 +3,7 @@ version: 1.0.0+1
publish_to: none
description: A new Flutter project.
environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.17.0 <3.0.0"
dependencies:
cupertino_icons: ^1.0.2
... ...
library get_core;
export 'src/flutter_engine.dart';
export 'src/get_interface.dart';
export 'src/get_main.dart';
export 'src/log.dart';
export 'src/smart_management.dart';
export 'src/typedefs.dart';
... ...
import 'package:flutter/widgets.dart';
class Engine{
static WidgetsBinding get instance {
return WidgetsFlutterBinding.ensureInitialized();
}
}
\ No newline at end of file
... ...
import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';
import '../../get.dart';
... ... @@ -18,7 +17,8 @@ mixin GetLifeCycleMixin {
@protected
@mustCallSuper
void onInit() {
ambiguate(SchedulerBinding.instance)
ambiguate(Engine.instance)
?.addPostFrameCallback((_) => onReady());
}
... ...
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import '../../get_core/get_core.dart';
import '../../get_instance/src/bindings_interface.dart';
... ... @@ -358,7 +357,7 @@ extension ExtensionSnackbar on GetInterface {
if (instantInit) {
controller.show();
} else {
ambiguate(SchedulerBinding.instance)!.addPostFrameCallback((_) {
ambiguate(Engine.instance)!.addPostFrameCallback((_) {
controller.show();
});
}
... ... @@ -469,7 +468,7 @@ extension ExtensionSnackbar on GetInterface {
controller.show();
} else {
//routing.isSnackbar = true;
ambiguate(SchedulerBinding.instance)!.addPostFrameCallback((_) {
ambiguate(Engine.instance)!.addPostFrameCallback((_) {
controller.show();
});
}
... ... @@ -1170,14 +1169,14 @@ extension GetNavigationExt on GetInterface {
}
/// The window to which this binding is bound.
ui.SingletonFlutterWindow get window => ui.window;
ui.SingletonFlutterWindow get window => engine.window;
Locale? get deviceLocale => ui.window.locale;
Locale? get deviceLocale => engine.window.locale;
///The number of device pixels for each logical pixel.
double get pixelRatio => ui.window.devicePixelRatio;
double get pixelRatio => engine.window.devicePixelRatio;
Size get size => ui.window.physicalSize / pixelRatio;
Size get size => engine.window.physicalSize / pixelRatio;
///The horizontal extent of this size.
double get width => size.width;
... ... @@ -1187,14 +1186,14 @@ extension GetNavigationExt on GetInterface {
///The distance from the top edge to the first unpadded pixel,
///in physical pixels.
double get statusBarHeight => ui.window.padding.top;
double get statusBarHeight => engine.window.padding.top;
///The distance from the bottom edge to the first unpadded pixel,
///in physical pixels.
double get bottomBarHeight => ui.window.padding.bottom;
double get bottomBarHeight => engine.window.padding.bottom;
///The system-reported text scale.
double get textScaleFactor => ui.window.textScaleFactor;
double get textScaleFactor => engine.window.textScaleFactor;
/// give access to TextTheme.of(context)
TextTheme get textTheme => theme.textTheme;
... ... @@ -1260,41 +1259,8 @@ extension GetNavigationExt on GetInterface {
TDelegate? delegate<TDelegate extends RouterDelegate<TPage>, TPage>() =>
_getxController.routerDelegate as TDelegate?;
// void resetRootNavigator() {
// _getxController = GetMaterialController();
// }
// RouterDelegate? get routerDelegate => _getxController.routerDelegate;
// RouteInformationParser? get routeInformationParser =>
// _getxController.routeInformationParser;
GetMaterialController get _getxController => GetMaterialController.to;
// void addPages(List<GetPage> getPages) {
// routeTree.addRoutes(getPages);
// }
// void clearRouteTree() {
// routeTree.routes.clear();
// }
// ParseRouteTree get routeTree {
// final delegate = _getxController.routerDelegate;
// if (delegate is GetDelegate) {
// return delegate.routeTree;
// } else {
// //TODO: Urgent: Refactor this
// return ParseRouteTree(routes: []);
// }
// }
// void addPage(GetPage getPage) {
// routeTree.addRoute(getPage);
// }
// void removePage(GetPage getPage) {
// routeTree.removeRoute(getPage);
// }
}
extension OverlayExt on GetInterface {
... ...
... ... @@ -61,7 +61,7 @@ class RouterReportManager<T> {
void reportRouteDispose(T disposed) {
if (Get.smartManagement != SmartManagement.onlyBuilder) {
ambiguate(WidgetsBinding.instance)!.addPostFrameCallback((_) {
ambiguate(Engine.instance)!.addPostFrameCallback((_) {
_removeDependencyByRoute(disposed);
});
}
... ...
... ... @@ -560,13 +560,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder>
_activePages.remove(RouteDecoder.fromRoute(name));
}
@override
void back<T>([T? result]) {
_checkIfCanBack();
_popWithResult<T>(result);
notifyListeners();
}
bool get canBack {
return _activePages.length > 1;
}
... ... @@ -799,21 +793,30 @@ class GetDelegate extends RouterDelegate<RouteDecoder>
return false;
}
@override
void back<T>([T? result]) {
_checkIfCanBack();
_popWithResult<T>(result);
notifyListeners();
}
bool _onPopVisualRoute(Route<dynamic> route, dynamic result) {
final didPop = route.didPop(result);
if (!didPop) {
return false;
}
final settings = route.settings;
if (settings is GetPage) {
final config = _activePages.cast<RouteDecoder?>().firstWhere(
(element) => element?.route == settings,
orElse: () => null,
);
if (config != null) {
_removeHistoryEntry(config, result);
}
}
_popWithResult(result);
// final settings = route.settings;
// if (settings is GetPage) {
// final config = _activePages.cast<RouteDecoder?>().firstWhere(
// (element) => element?.route == settings,
// orElse: () => null,
// );
// if (config != null) {
// _removeHistoryEntry(config, result);
// }
// }
notifyListeners();
//return !route.navigator!.userGestureInProgress;
return true;
... ...
... ... @@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import '../../../get_core/get_core.dart';
import '../../get_navigation.dart';
... ... @@ -449,7 +448,7 @@ You need to either use message[String], or messageText[Widget] or define a userI
}
void _configureLeftBarFuture() {
ambiguate(SchedulerBinding.instance)!.addPostFrameCallback(
ambiguate(Engine.instance)!.addPostFrameCallback(
(_) {
final keyContext = _backgroundBoxKey.currentContext;
if (keyContext != null) {
... ...
... ... @@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/utils.dart';
import '../../../get_rx/src/rx_types/rx_types.dart';
import '../../../instance_manager.dart';
... ... @@ -70,9 +71,10 @@ mixin StateMixin<T> on ListNotifier {
}
}
void futurize(Future<T> Function() Function() body,
{String? errorMessage, bool useEmpty = true}) {
final compute = body();
void futurize(Future<T> Function() body,
{T? initialData, String? errorMessage, bool useEmpty = true}) {
final compute = body;
_value ??= initialData;
compute().then((newValue) {
if ((newValue == null || newValue._isEmpty()) && useEmpty) {
status = GetStatus<T>.loading();
... ... @@ -88,6 +90,10 @@ mixin StateMixin<T> on ListNotifier {
}
}
typedef FuturizeCallback<T> = Future<T> Function(VoidCallback fn);
typedef VoidCallback = void Function();
class GetListenable<T> extends ListNotifierSingle implements RxInterface<T> {
GetListenable(T val) : _value = val;
... ... @@ -239,28 +245,45 @@ extension StateExt<T> on StateMixin<T> {
typedef NotifierBuilder<T> = Widget Function(T state);
abstract class GetStatus<T> {
abstract class GetStatus<T> with Equality {
const GetStatus();
factory GetStatus.loading() => LoadingStatus();
factory GetStatus.error(String message) => ErrorStatus(message);
factory GetStatus.empty() => EmptyStatus();
factory GetStatus.success(T data) => SuccessStatus(data);
factory GetStatus.custom() => CustomStatus();
}
class CustomStatus<T> extends GetStatus<T> {
@override
List get props => [];
}
class LoadingStatus<T> extends GetStatus<T> {}
class LoadingStatus<T> extends GetStatus<T> {
@override
List get props => [];
}
class SuccessStatus<T> extends GetStatus<T> {
final T data;
const SuccessStatus(this.data);
SuccessStatus(this.data);
@override
List get props => [data];
}
class ErrorStatus<T, S> extends GetStatus<T> {
final S? error;
ErrorStatus([this.error]);
const ErrorStatus([this.error]);
@override
List get props => [error];
}
class EmptyStatus<T> extends GetStatus<T> {}
class EmptyStatus<T> extends GetStatus<T> {
@override
List get props => [];
}
extension StatusDataExt<T> on GetStatus<T> {
bool get isLoading => this is LoadingStatus;
... ...
... ... @@ -96,13 +96,13 @@ mixin FullLifeCycleMixin on FullLifeCycleController {
@override
void onInit() {
super.onInit();
ambiguate(WidgetsBinding.instance)!.addObserver(this);
ambiguate(Engine.instance)!.addObserver(this);
}
@mustCallSuper
@override
void onClose() {
ambiguate(WidgetsBinding.instance)!.removeObserver(this);
ambiguate(Engine.instance)!.removeObserver(this);
super.onClose();
}
... ...