Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
fluttertpc_get
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jermaine McFarlane
2021-07-13 16:40:08 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9abd5ac448d86d9d0e837bf265eae544e5009a74
9abd5ac4
1 parent
195b46f8
add replace method on GetInstance
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
lib/get_instance/src/extension_instance.dart
test/instance/get_instance_test.dart
lib/get_instance/src/extension_instance.dart
View file @
9abd5ac
...
...
@@ -128,4 +128,12 @@ extension Inst on GetInterface {
/// [Get.lazyPut()], is registered in memory.
/// - [tag] optional, if you use a [tag] to register the Instance.
bool
isPrepared
<
S
>({
String
?
tag
})
=>
GetInstance
().
isPrepared
<
S
>(
tag:
tag
);
/// Replace a parent instance of a class in dependency management
/// with a [child] instance
void
replace
<
P
,
C
extends
P
>(
C
child
,
{
String
?
tag
,
bool
permanent
=
false
})
{
delete
<
P
>();
// ignore: unnecessary_cast
put
(
child
as
P
,
tag:
tag
,
permanent:
permanent
);
}
}
...
...
test/instance/get_instance_test.dart
View file @
9abd5ac
import
'package:flutter_test/flutter_test.dart'
;
import
'package:get/get.dart'
;
import
'util/matcher.dart'
as
m
;
class
Mock
{
...
...
@@ -155,6 +156,13 @@ void main() {
expect
(
instance
.
initialized
,
true
);
});
});
test
(
'Get.replace test for replacing parent instance with child'
,
()
async
{
Get
.
replace
<
DisposableController
,
Controller
>(
Controller
());
final
instance
=
Get
.
find
<
DisposableController
>();
expect
(
instance
is
Controller
,
isTrue
);
expect
((
instance
as
Controller
).
init
,
greaterThan
(
0
));
});
}
class
Controller
extends
DisposableController
{
...
...
Please
register
or
login
to post a comment