I am learning flutter and have just updated app to include Riverpods. I have a collection within a collection and so need to pass two parameters. One is called localAuthId and the other is called orgId.

When I setup the Streambuilder I get an error saying there are too many positional arguments.

Here is the snippet that seems to be causing the problem

**final orgStreamProvider =
StreamProvider.autoDispose.family<Org, String>((ref, localAuthId, orgId) {
  final database = ref.watch(databaseProvider);
  return database != null && localAuthId != null && orgId !=null
      ? database.orgDocStream(localAuthId: localAuthId, orgId: orgId)
      : const Stream.empty();
})**

When I run the following on the top level collection i.e. with just 1 parameter of localAuthId it works just fine.

**final orgStreamProvider =
StreamProvider.autoDispose.family<Org, String>((ref, localAuthId) {
  final database = ref.watch(databaseProvider);
  return database != null && localAuthId != null
      ? database.orgDocStream(localAuthId: localAuthId)
      : const Stream.empty();
});**

Does anyone know what I am getting wrong with this please?

Thank you

1

There are 1 answers

1
Vinoth Vino On

As of now, You can pass only one value to the provider using family of Riverpod. Better create one class with two properties and pass the object to the provider.

class Auth {
  Auth({
    @required this.localAuthId,
    @required this.orgId,
  });
  final String localAuthId;
  final String orgId;
}

final auth = Auth(localAuthId: 'abc', orgId: 'abc1234');

final orgStreamProvider = StreamProvider.autoDispose.family<Org, Auth>((ref, auth) {
  final database = ref.watch(databaseProvider);
  return database != null && auth.localAuthId != null && auth.orgId !=null
    ? database.orgDocStream(localAuthId: auth.localAuthId, orgId: auth.orgId)
    : const Stream.empty();
})

With hooks_riverpod

final orgProvider = useProvider(orgStreamProvider(auth));