Skip to content

dependsOn confusion #40

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

Closed
Reprevise opened this issue Jan 18, 2020 · 6 comments
Closed

dependsOn confusion #40

Reprevise opened this issue Jan 18, 2020 · 6 comments

Comments

@Reprevise
Copy link

Reprevise commented Jan 18, 2020

I'm a bit confused on the dependsOn syntax. Before I was using readyFuture and that worked fine but I decided to try the new beta version. Here's how I register my singletons.

  getIt.registerSingletonAsync<AndroidDetails>(
    (_) => AndroidDetailsImplementation()..init(),
  );
  getIt.registerSingletonAsync<ThemeService>(
    (_) => Future<ThemeService>.value(ThemeService()),
    dependsOn: <Type>[AndroidDetails],
  );

I keep getting The method <method name> was called on null since I'm using _details.<method name>().

Here's my ThemeService constructor:

  ThemeService() {
    _details = getIt.get<AndroidDetails>();
    settings = Hive.box<dynamic>(DatabaseHelper.SETTINGS_BOX);
  }

Am I doing something wrong? Should I be using getAsync?

EDIT: Here's my AndroidDetailsImplementation init() function:

  Future<void> init() async {
    try {
      final AndroidDeviceInfo _deviceInfo = await DeviceInfoPlugin().androidInfo;
      _deviceData = getDeviceData(_deviceInfo);
    } on PlatformException {
      _deviceData = <String, dynamic>{
        'Error:': 'Failed to get platform version.',
      };
    }
  }
@Reprevise
Copy link
Author

I think I fixed the issue by using the Completer manually and awaiting it in my main() function.

@escamoteur
Copy link
Collaborator

@Reprevise This will change mostly back to the way before with a lot of improvements

@Reprevise
Copy link
Author

Sounds good @escamoteur, what kind of improvements will there be?

@escamoteur
Copy link
Collaborator

async factories with dependencies but easier to use
also a new registerSingletonWithDependencies

@Reprevise
Copy link
Author

Sounds cool! What version will these changes be released on? The next one?

@escamoteur
Copy link
Collaborator

Yep, I guess next week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants