Jonny Borges
Committed by GitHub

Merge pull request #2896 from jonataslaw/rename_create

rename create -> spawn and change logic of new GetWidget
... ... @@ -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
... ...
... ... @@ -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"
... ...
... ... @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {
/* Begin PBXBuildFile section */
... ... @@ -127,7 +127,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
... ... @@ -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 = (
... ... @@ -185,6 +187,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
... ...
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
... ...
... ... @@ -43,5 +43,7 @@
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
... ...
... ... @@ -6,8 +6,8 @@ class ProductDetailsBinding extends Binding {
@override
List<Bind> dependencies() {
return [
Bind.create<ProductDetailsController>(
(_) => ProductDetailsController(
Bind.spawn<ProductDetailsController>(
() => ProductDetailsController(
Get.parameters['productId'] ?? '',
),
)
... ...
import 'dart:async';
import 'package:async/async.dart';
import 'package:get/get.dart';
class SplashService extends GetxService {
final welcomeStr = ['GetX', 'Rules!'];
final activeStr = 0.obs;
final memo = AsyncMemoizer<void>();
Future<void> init() {
return memo.runOnce(_initFunction);
}
void _changeActiveString() {
activeStr.value = (activeStr.value + 1) % welcomeStr.length;
}
Future<void> _initFunction() async {
final t = Timer.periodic(
const Duration(milliseconds: 500),
(t) => _changeActiveString(),
);
//simulate some long running operation
await Future.delayed(const Duration(seconds: 5));
//cancel the timer once we are done
t.cancel();
}
}
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/splash_service.dart';
class SplashView extends GetView<SplashService> {
const SplashView({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Obx(
() => Text(
controller.welcomeStr[controller.activeStr.value],
style: const TextStyle(fontSize: 20),
),
),
const CircularProgressIndicator(),
],
),
),
);
}
}
... ... @@ -2,7 +2,6 @@ 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() {
... ... @@ -10,7 +9,6 @@ void main() {
GetMaterialApp(
title: "Application",
binds: [
Bind.put(SplashService()),
Bind.put(AuthService()),
],
getPages: AppPages.routes,
... ...
... ... @@ -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,
... ... @@ -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}) {
... ... @@ -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.
... ...
... ... @@ -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
... ...
... ... @@ -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);
... ...
... ... @@ -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 =>
... ... @@ -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;
}
... ...
... ... @@ -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
... ... @@ -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),
);
}
}
... ...
... ... @@ -55,9 +55,12 @@ 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();
});
... ... @@ -65,9 +68,12 @@ void main() {
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();
});
... ... @@ -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();
});
... ... @@ -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);
... ... @@ -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);
... ... @@ -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);
});
});
}
... ...