MikeMitterer / dryice

Dependency injection framework for Dart

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

3d-party library injection

wasylews opened this issue · comments

Hello, I don't know if it's related to dryice or more to reflectable. But how can I inject class from another package?
Here is the code:

import 'package:dryice/dryice.dart';
import 'package:flutter_facebook_login/flutter_facebook_login.dart';

@inject
class FacebookService {

  FacebookLogin facebookLogin;

  @inject
  FacebookService(this.facebookLogin);

  Future<String> login() async {
    FacebookLoginResult result = await facebookLogin.logInWithReadPermissions(['email']);
    switch (result.status) {
      case FacebookLoginStatus.loggedIn:
        return Future.value(result.accessToken.token);
      case FacebookLoginStatus.error:
        return Future.error(new Exception(result.errorMessage));
      case FacebookLoginStatus.cancelledByUser:
        return Future.error(new Exception("Cancelled by user"));
    }
    // doesn't go here
    return null;
  }

And when i'm starting an app I get an exception:

E/flutter (24038): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter (24038): Reflecting on type 'FacebookLogin' without capability

This should work:

@inject
class FirestoreWrapper {
  Firestore firestore;
  FirestoreWrapper(this.firestore);
}

bind(FirestoreWrapper).toInstance(FirestoreWrapper(firestore));