how to pass provider classname as an argument?


I want to pass provider classname as an argument but it keeps giving me error The name ‘providerClassName’ isn’t a type so it can’t be used as a type argument.

I am trying this

  Widget buildText<T>({@required T providerClassName}) {
    return Text(
        Provider.of<providerClassName>(context, listen: false).username);

and i am calling function like this

 buildText(providerClassName: HomeScreenProvider);


You almost got it correct.
You have the generic type T of the method

buildText<T extends HomeScreenProvider>

so you can use it like Provider.of<T>(context, listen: false).username and call it

Answered By – Calvin Gonsalves

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published