Skip to content

Commit

Permalink
Merge pull request #2896 from jonataslaw/rename_create
Browse files Browse the repository at this point in the history
rename create -> spawn and change logic of new GetWidget
  • Loading branch information
jonataslaw authored Aug 31, 2023
2 parents 806a601 + 7bd4623 commit 5dfdf3c
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 92 deletions.
5 changes: 3 additions & 2 deletions example_nav2/ios/Flutter/Generated.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
FLUTTER_ROOT=/Users/jonatasborges/flutter
FLUTTER_APPLICATION_PATH=/Users/jonatasborges/getx5/getx/example_nav2
COCOAPODS_PARALLEL_CODE_SIGN=true
FLUTTER_TARGET=lib/main.dart
FLUTTER_TARGET=/Users/jonatasborges/getx5/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
EXCLUDED_ARCHS[sdk=iphoneos*]=armv7
DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,RkxVVFRFUl9XRUJfQ0FOVkFTS0lUX1VSTD1odHRwczovL3d3dy5nc3RhdGljLmNvbS9mbHV0dGVyLWNhbnZhc2tpdC9iMjAxODNlMDQwOTYwOTRiY2MzN2Q5Y2RlMmE0Yjk2ZjVjYzY4NGNmLw==
DART_OBFUSCATION=false
TRACK_WIDGET_CREATION=true
TREE_SHAKE_ICONS=false
PACKAGE_CONFIG=.dart_tool/package_config.json
PACKAGE_CONFIG=/Users/jonatasborges/getx5/getx/example_nav2/.dart_tool/package_config.json
5 changes: 3 additions & 2 deletions example_nav2/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
export "FLUTTER_ROOT=/Users/jonatasborges/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/jonatasborges/getx5/getx/example_nav2"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_TARGET=/Users/jonatasborges/getx5/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==,RkxVVFRFUl9XRUJfQ0FOVkFTS0lUX1VSTD1odHRwczovL3d3dy5nc3RhdGljLmNvbS9mbHV0dGVyLWNhbnZhc2tpdC9iMjAxODNlMDQwOTYwOTRiY2MzN2Q5Y2RlMmE0Yjk2ZjVjYzY4NGNmLw=="
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
export "PACKAGE_CONFIG=/Users/jonatasborges/getx5/getx/example_nav2/.dart_tool/package_config.json"
7 changes: 5 additions & 2 deletions example_nav2/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -127,7 +127,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -171,10 +171,12 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand All @@ -185,6 +187,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 2 additions & 0 deletions example_nav2/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class ProductDetailsBinding extends Binding {
@override
List<Bind> dependencies() {
return [
Bind.create<ProductDetailsController>(
(_) => ProductDetailsController(
Bind.spawn<ProductDetailsController>(
() => ProductDetailsController(
Get.parameters['productId'] ?? '',
),
)
Expand Down

This file was deleted.

28 changes: 0 additions & 28 deletions example_nav2/lib/app/modules/splash/views/splash_view.dart

This file was deleted.

2 changes: 0 additions & 2 deletions example_nav2/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import 'package:example_nav2/services/auth_service.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'app/modules/splash/controllers/splash_service.dart';
import 'app/routes/app_pages.dart';

void main() {
runApp(
GetMaterialApp(
title: "Application",
binds: [
Bind.put(SplashService()),
Bind.put(AuthService()),
],
getPages: AppPages.routes,
Expand Down
8 changes: 3 additions & 5 deletions lib/get_instance/src/extension_instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ extension Inst on GetInterface {
/// Route `Get.reference` to keep the lifecycle active.
/// Is important to know that the instances created are only stored per Route.
/// So, if you call `Get.delete<T>()` the "instance factory" used in this
/// method (`Get.create<T>()`) will be removed, but NOT the instances
/// method (`Get.spawn<T>()`) will be removed, but NOT the instances
/// already created by it.
///
/// Example:
///
/// ```create(() => Repl());
/// ```Get.spawn(() => Repl());
/// Repl a = find();
/// Repl b = find();
/// print(a==b); (false)```
void create<S>(
void spawn<S>(
InstanceBuilderCallback<S> builder, {
String? tag,
bool permanent = true,
Expand Down Expand Up @@ -298,7 +298,6 @@ extension Inst on GetInterface {
}
}


/// The findOrNull method will return the instance if it is registered;
/// otherwise, it will return null.
S? findOrNull<S>({String? tag}) {
Expand All @@ -308,7 +307,6 @@ extension Inst on GetInterface {
return null;
}


/// Replace a parent instance of a class in dependency management
/// with a [child] instance
/// - [tag] optional, if you use a [tag] to register the Instance.
Expand Down
6 changes: 3 additions & 3 deletions lib/get_navigation/src/routes/get_information_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class GetInformationParser extends RouteInformationParser<RouteDecoder> {
.any((element) => element.name == '/')) {
location = initialRoute;
}
} else if (location.isEmpty) {
location = initialRoute;
}

Get.log('GetInformationParser: route location: $location');

final routeName = location ?? initialRoute;

return SynchronousFuture(RouteDecoder.fromRoute(routeName));
return SynchronousFuture(RouteDecoder.fromRoute(location));
}

@override
Expand Down
4 changes: 2 additions & 2 deletions lib/get_navigation/src/routes/modules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class Dependencies {
return find<S>();
}

void create<S>(InstanceBuilderCallback<S> builder,
void spawn<S>(InstanceBuilderCallback<S> builder,
{String? tag, bool permanent = true}) =>
Get.create<S>(builder, tag: tag, permanent: permanent);
Get.spawn<S>(builder, tag: tag, permanent: permanent);

S find<S>({String? tag}) => Get.find<S>(tag: tag);

Expand Down
12 changes: 11 additions & 1 deletion lib/get_state_manager/src/simple/get_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ abstract class Bind<T> extends StatelessWidget {
);
}

static Bind spawn<S>(InstanceBuilderCallback<S> builder,
{String? tag, bool permanent = true}) {
Get.spawn<S>(builder, tag: tag, permanent: permanent);
return _FactoryBind<S>(
tag: tag,
global: false,
autoRemove: permanent,
);
}

static S find<S>({String? tag}) => Get.find<S>(tag: tag);

static Future<bool> delete<S>({String? tag, bool force = false}) async =>
Expand Down Expand Up @@ -465,7 +475,7 @@ class BindElement<T> extends InheritedElement {
} else {
if (widget.create != null) {
_controllerBuilder = () => widget.create!.call(this);
Get.create<T>(_controllerBuilder!, tag: widget.tag, permanent: false);
Get.spawn<T>(_controllerBuilder!, tag: widget.tag, permanent: false);
} else {
_controllerBuilder = widget.init;
}
Expand Down
6 changes: 5 additions & 1 deletion lib/get_state_manager/src/simple/get_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/widgets.dart';

import '../../../instance_manager.dart';
import '../../../utils.dart';
import 'get_state.dart';
import 'get_widget_cache.dart';

/// GetView is a great way of quickly access your Controller
Expand Down Expand Up @@ -101,6 +102,9 @@ class _GetCache<S extends GetLifeCycleMixin> extends WidgetCache<GetWidget<S>> {
@override
Widget build(BuildContext context) {
return widget!.build(context);
return Binder(
init: () => _controller,
child: widget!.build(context),
);
}
}
32 changes: 20 additions & 12 deletions test/instance/get_instance_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,25 @@ void main() {
final instance = Get.put<Controller>(Controller(), tag: 'one');
final instance2 = Get.put<Controller>(Controller(), tag: 'two');
expect(instance == instance2, false);
expect(Get.find<Controller>(tag: 'one') == Get.find<Controller>(tag: 'two'), false);
expect(Get.find<Controller>(tag: 'one') == Get.find<Controller>(tag: 'one'), true);
expect(Get.find<Controller>(tag: 'two') == Get.find<Controller>(tag: 'two'), true);
expect(Get.find<Controller>(tag: 'one') == Get.find<Controller>(tag: 'two'),
false);
expect(Get.find<Controller>(tag: 'one') == Get.find<Controller>(tag: 'one'),
true);
expect(Get.find<Controller>(tag: 'two') == Get.find<Controller>(tag: 'two'),
true);
Get.reset();
});

test('Get.lazyPut tag test', () async {
Get.lazyPut<Controller>(() => Controller(), tag: 'one');
Get.lazyPut<Controller>(() => Controller(), tag: 'two');

expect(Get.find<Controller>(tag: 'one') == Get.find<Controller>(tag: 'two'), false);
expect(Get.find<Controller>(tag: 'one') == Get.find<Controller>(tag: 'one'), true);
expect(Get.find<Controller>(tag: 'two') == Get.find<Controller>(tag: 'two'), true);
expect(Get.find<Controller>(tag: 'one') == Get.find<Controller>(tag: 'two'),
false);
expect(Get.find<Controller>(tag: 'one') == Get.find<Controller>(tag: 'one'),
true);
expect(Get.find<Controller>(tag: 'two') == Get.find<Controller>(tag: 'two'),
true);
Get.reset();
});

Expand Down Expand Up @@ -95,7 +101,8 @@ void main() {

expect(Get.find<Controller>().count, 1);
Get.delete<Controller>();
expect(() => Get.find<Controller>(), throwsA(const m.TypeMatcher<String>()));
expect(
() => Get.find<Controller>(), throwsA(const m.TypeMatcher<String>()));
Get.reset();
});

Expand Down Expand Up @@ -134,7 +141,7 @@ void main() {
});

test('Get.create with abstract class test', () async {
Get.create<Service>(() => Api());
Get.spawn<Service>(() => Api());
final ct1 = Get.find<Service>();
final ct2 = Get.find<Service>();
// expect(ct1 is Service, true);
Expand All @@ -155,10 +162,12 @@ void main() {
test('Get.delete test with disposable controller', () async {
// Get.put(DisposableController());
expect(Get.delete<DisposableController>(), true);
expect(() => Get.find<DisposableController>(), throwsA(const m.TypeMatcher<String>()));
expect(() => Get.find<DisposableController>(),
throwsA(const m.TypeMatcher<String>()));
});

test('Get.put test after delete with disposable controller and init check', () async {
test('Get.put test after delete with disposable controller and init check',
() async {
final instance = Get.put<DisposableController>(DisposableController());
expect(instance, Get.find<DisposableController>());
expect(instance.initialized, true);
Expand Down Expand Up @@ -251,11 +260,10 @@ void main() {
Get.put<int>(1);
int? result = Get.findOrNull<int>();
expect(result, 1);

Get.delete<int>();
result = Get.findOrNull<int>();
expect(result, null);

});
});
}
Expand Down

0 comments on commit 5dfdf3c

Please sign in to comment.