Jonny Borges
Committed by GitHub

Merge pull request #2624 from jonataslaw/refactor-bind-create

Refactor bind create
@@ -76,14 +76,14 @@ class AppPages { @@ -76,14 +76,14 @@ class AppPages {
76 transition: Transition.cupertino, 76 transition: Transition.cupertino,
77 showCupertinoParallax: true, 77 showCupertinoParallax: true,
78 participatesInRootNavigator: false, 78 participatesInRootNavigator: false,
79 - bindings: [ProductsBinding()], 79 + bindings: [ProductsBinding(), ProductDetailsBinding()],
80 children: [ 80 children: [
81 GetPage( 81 GetPage(
82 name: _Paths.productDetails, 82 name: _Paths.productDetails,
83 transition: Transition.cupertino, 83 transition: Transition.cupertino,
84 showCupertinoParallax: true, 84 showCupertinoParallax: true,
85 page: () => ProductDetailsView(), 85 page: () => ProductDetailsView(),
86 - bindings: [ProductDetailsBinding()], 86 + bindings: [],
87 middlewares: [ 87 middlewares: [
88 //only enter this route when authed 88 //only enter this route when authed
89 EnsureAuthMiddleware(), 89 EnsureAuthMiddleware(),
  1 +import 'package:example_nav2/services/auth_service.dart';
1 import 'package:flutter/material.dart'; 2 import 'package:flutter/material.dart';
2 import 'package:get/get.dart'; 3 import 'package:get/get.dart';
3 4
4 import 'app/modules/splash/controllers/splash_service.dart'; 5 import 'app/modules/splash/controllers/splash_service.dart';
5 import 'app/routes/app_pages.dart'; 6 import 'app/routes/app_pages.dart';
6 -import 'services/auth_service.dart';  
7 7
8 void main() { 8 void main() {
9 runApp( 9 runApp(
@@ -20,6 +20,11 @@ class InstanceInfo { @@ -20,6 +20,11 @@ class InstanceInfo {
20 required this.isPrepared, 20 required this.isPrepared,
21 required this.isInit, 21 required this.isInit,
22 }); 22 });
  23 +
  24 + @override
  25 + String toString() {
  26 + return 'InstanceInfo(isPermanent: $isPermanent, isSingleton: $isSingleton, isRegistered: $isRegistered, isPrepared: $isPrepared, isInit: $isInit)';
  27 + }
23 } 28 }
24 29
25 extension Inst on GetInterface { 30 extension Inst on GetInterface {
@@ -463,6 +463,12 @@ class BindElement<T> extends InheritedElement { @@ -463,6 +463,12 @@ class BindElement<T> extends InheritedElement {
463 } 463 }
464 } 464 }
465 } else { 465 } else {
  466 + if (widget.create != null) {
  467 + _controllerBuilder = () => widget.create!.call(this);
  468 + Get.create<T>(_controllerBuilder!, tag: widget.tag, permanent: false);
  469 + } else {
  470 + _controllerBuilder = widget.init;
  471 + }
466 _controllerBuilder = 472 _controllerBuilder =
467 (widget.create != null ? () => widget.create!.call(this) : null) ?? 473 (widget.create != null ? () => widget.create!.call(this) : null) ??
468 widget.init; 474 widget.init;
@@ -81,6 +81,7 @@ class _GetCache<S extends GetLifeCycleMixin> extends WidgetCache<GetWidget<S>> { @@ -81,6 +81,7 @@ class _GetCache<S extends GetLifeCycleMixin> extends WidgetCache<GetWidget<S>> {
81 } 81 }
82 82
83 GetWidget._cache[widget!] = _controller; 83 GetWidget._cache[widget!] = _controller;
  84 +
84 super.onInit(); 85 super.onInit();
85 } 86 }
86 87