Riverpod – How to wrap a PreferredSizeWidget inside a Consumer


I have a DefaultTabController and I have a method that returns List<PreferredSizeWidget> which are the AppBar‘s of pages. I want them to watch a state in a ChangeNotifier and therefore I want to wrap them inside of a Consumer. When I try to do so I get an error like this:

"The argument type ‘Widget’ can’t be assigned to the parameter type ‘PreferredSizeWidget’."

How can I fix this?

Thanks and regards.


The error comes from the appBar‘s parameter of Scaffold requiring a PreferredSizeWidget. I can think of two solutions :

  • You can wrap your Consumer with a PreferredSize and use Size.fromHeight() as preferredSize. That is if the height is constant amongst your appbars.
  • You can avoid using the appBar parameter altogether by wrapping your Scaffold‘s body with an Expanded inside a Column, and making the Consumer its first child.

Answered By – MickaelHrndz

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *