Skip to content

Commit

Permalink
Merge pull request fluttercommunity#297 from lacopiroty/master
Browse files Browse the repository at this point in the history
It's funny I just might have a problem that could be solved easier with this
  • Loading branch information
escamoteur authored May 9, 2023
2 parents 76800ad + d09233c commit 57396d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/get_it.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,15 @@ abstract class GetIt {
/// If you really need to you can disable the asserts by setting[allowReassignment]= true
bool allowReassignment = false;

/// retrieves or creates an instance of a registered type [T] depending on the registration
/// retrieves or creates an instance of a registered type [T] or [type] depending on the registration
/// function used for this type or based on a name.
/// for factories you can pass up to 2 parameters [param1,param2] they have to match the types
/// given at registration with [registerFactoryParam()]
T get<T extends Object>({
String? instanceName,
dynamic param1,
dynamic param2,
Type? type,
});

/// Returns a Future of an instance that is created by an async factory or a Singleton that is
Expand All @@ -168,6 +169,7 @@ abstract class GetIt {
String? instanceName,
dynamic param1,
dynamic param2,
Type? type,
});

/// Callable class so that you can write `GetIt.instance<MyType>` instead of
Expand All @@ -176,6 +178,7 @@ abstract class GetIt {
String? instanceName,
dynamic param1,
dynamic param2,
Type? type,
});

/// registers a type so that a new instance will be created on each call of [get] on that type
Expand Down
9 changes: 6 additions & 3 deletions lib/get_it_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,9 @@ class _GetItImplementation implements GetIt {
String? instanceName,
dynamic param1,
dynamic param2,
Type? type,
}) {
final instanceFactory = _findFactoryByNameAndType<T>(instanceName);
final instanceFactory = _findFactoryByNameAndType<T>(instanceName, type);

Object instance = Object; //late
if (instanceFactory.isAsync || instanceFactory.pendingResult != null) {
Expand Down Expand Up @@ -451,8 +452,9 @@ class _GetItImplementation implements GetIt {
String? instanceName,
dynamic param1,
dynamic param2,
Type? type,
}) {
return get<T>(instanceName: instanceName, param1: param1, param2: param2);
return get<T>(instanceName: instanceName, param1: param1, param2: param2, type: type);
}

/// Returns a Future of an instance that is created by an async factory or a Singleton that is
Expand All @@ -464,8 +466,9 @@ class _GetItImplementation implements GetIt {
String? instanceName,
dynamic param1,
dynamic param2,
Type? type,
}) {
final factoryToGet = _findFactoryByNameAndType<T>(instanceName);
final factoryToGet = _findFactoryByNameAndType<T>(instanceName, type);
return factoryToGet.getObjectAsync<T>(param1, param2);
}

Expand Down

0 comments on commit 57396d5

Please sign in to comment.