Home > database >  Flutter Riverpod: how to pass 3 arguments in family?
Flutter Riverpod: how to pass 3 arguments in family?

Time:12-13

i am trying to pass 3 aruguments to family of riverpod. i can only make 2 arugument but i want to make it 3.

here is what i am trying to archieved

final allEmployeeOfVenodrsOfaParticularVenderUser = FutureProvider.family<
    List<AllEmployeeOfVendorParticularVenUser>, String, String>(
  (ref, vendocode) {
    return ref
        .read(apiProvider)
        .getAllEmployeeOfaparticluarVendorUser(vendorCode: vendocode);
  },
);

using two arugument but i want to pass 3 arugment

CodePudding user response:

As per the riverpod documentation you can't pass 3 arguments to the family, But what you can do is pass 2 arguments but the second argument you can pass as Map<String, dynamic> or an Object(Model class).

You will find both of the examples below

1)

final allEmployeeOfVenodrsOfaParticularVenderUser = FutureProvider.family<
    List<AllEmployeeOfVendorParticularVenUser>, Map<String, dynamic>>(
  (ref, vendocode) {
    var arg1 = vendocode['arg1'];
    var arg2 = vendocode['arg2'];
    return ref
        .read(apiProvider)
        .getAllEmployeeOfaparticluarVendorUser(vendorCode: vendocode);
  },
);

2)

final allEmployeeOfVenodrsOfaParticularVenderUser = FutureProvider.family<
    List<AllEmployeeOfVendorParticularVenUser>, argsModel >(
  (ref, vendocode) {
    var arg1 = vendocode.arg1;
    var arg2 = vendocode.arg2;
    return ref
        .read(apiProvider)
        .getAllEmployeeOfaparticluarVendorUser(vendorCode: vendocode);
  },
);

@immutable
class argsModel extends Equatable {
  final String arg1;
  final String arg2;

  const argsModel(this. arg1, this. arg2);

  @override
  List<Object?> get props => [arg1, arg2];
}
  • Related