Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support form type #297

Merged
merged 1 commit into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -391,8 +391,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 @@ -428,8 +429,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 @@ -441,8 +443,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