Committed by
GitHub
Update extension_instance.dart
Implemented findOrNull method
Showing
1 changed file
with
11 additions
and
0 deletions
@@ -298,6 +298,17 @@ extension Inst on GetInterface { | @@ -298,6 +298,17 @@ extension Inst on GetInterface { | ||
298 | } | 298 | } |
299 | } | 299 | } |
300 | 300 | ||
301 | + | ||
302 | + /// The findOrNull method will return the instance if it is registered; | ||
303 | + /// otherwise, it will return null. | ||
304 | + S? findOrNull<S>({String? tag}) { | ||
305 | + if (isRegistered<S>(tag: tag)) { | ||
306 | + return find<S>(tag: tag); | ||
307 | + } | ||
308 | + return null; | ||
309 | + } | ||
310 | + | ||
311 | + | ||
301 | /// Replace a parent instance of a class in dependency management | 312 | /// Replace a parent instance of a class in dependency management |
302 | /// with a [child] instance | 313 | /// with a [child] instance |
303 | /// - [tag] optional, if you use a [tag] to register the Instance. | 314 | /// - [tag] optional, if you use a [tag] to register the Instance. |
-
Please register or login to post a comment