How to make custom Bloc builder using generic types in Flutter Bloc?

33 Views Asked by At

I need to pass types to a function that builds specific states stored in a list. For example, I have this list:

List<Type> types = [AppBloc,AppState];

Is it possible in Dart to pass these types to the following function, where A = types[0] = AppBloc and B = types[1] = AppState?

Widget genericBlocBuilder<A extends StateStreamable<B>, B>({
  required Widget child,
}) {
  return BlocBuilder<A, B>(
    builder: (context, state) => child,
  );
}
0

There are 0 best solutions below