get_it icon indicating copy to clipboard operation
get_it copied to clipboard

`getMaybe` to get object if registered and null otherwise

Open spydon opened this issue 7 months ago • 0 comments

Sometimes you don't know if what you're looking for is already registered, it is then handy to have a get method that can return null when the registration doesn't exist.

Currently I'm using this workaround:

extension GetItExtension on GetIt {
  T? getMaybe<T extends Object>() {
    return isRegistered<T>() ? get<T>() : null;
  }
}

spydon avatar Jun 17 '25 13:06 spydon