我目前正在开发一个简单的项目crypto_wallet和ValueEquality

我目前正在开发一个简单的项目 crypto_wallet。状态管理 (BLoC) 和价值平等 (冻结) 为 DB (Firebase) 创建 CRUD 操作,在 watch 方法中我使用 StreamSubcription 代码是:

@injectable
class CoinWatcherBloc extends Bloc {
  final ICoinRepository _repository;
  CoinWatcherBloc(this._repository, this._coinStreamSubscription) : 
 super(CoinWatcherState.initial());
  StreamSubscription<Either<CoinFailure, KtList>>? _coinStreamSubscription;
  @override

  Stream mapEventToState(CoinWatcherEvent event) async* {
    yield* event.map(
      watchCoin: (e) async* {
        yield CoinWatcherState.loadInProgress();
        await _coinStreamSubscription?.cancel();
        _coinStreamSubscription = _repository.watchCoin().listen(
              (failureOrSuccess) => add(
                CoinWatcherEvent.coinsReceived(failureOrSuccess),
              ),

            );
      },
      coinsReceived: (e) async* {
        yield e.failureOrCoin.fold(
          (f) => CoinWatcherState.loadFailure(f),
          (coin) => CoinWatcherState.loadSuccess(coin),
        );
      },
    );

  }
  @override
  Future close() async {
    await _coinStreamSubscription?.cancel();
    return super.close();
  }
}

最后我关闭了流。我在@lazySingleton 上注入所有第 3 方模块:

@module
abstract class FirebaseInjectableModule {
  @lazySingleton
  FirebaseAuth get firebaseAuth => FirebaseAuth.instance;
  @lazySingleton
  FirebaseFirestore get firebaseFirestore => FirebaseFirestore.instance;
  @lazySingleton
  GoogleSignIn get googleSignIn => GoogleSignIn();
}

然后它说:

Object/factory with  type StreamSubscription<Either<CoinFailure, KtList>> is not 
registered inside GetIt. 
(Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;
Did you forget to register it?)

如果我也这样注册课程。

@lazySingleton
StreamSubcription get streamSubcription => StreamSubcription();

然后它抛出编译时错误抽象类不能像我注册的所有 3rd 方类一样实例化。如何注入抽象类?有没有其他方法可以做到这一点?还是我不应该将 StreamSubcription 用于其他用途?我会很感激的

© 版权声明
THE END
喜欢就支持一下吧
点赞250赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容