educative.io

Erorr in code While building AppBar

appBar: buildAppBarWidget(),
gives error stating:
The argument type ‘Widget’ can’t be assigned to the parameter type ‘PreferredSizeWidget?’

Type your question above this line.

Course: https://www.educative.io/collection/5726865580883968/6563776842170368
Lesson: https://www.educative.io/collection/page/5726865580883968/6563776842170368/6073911025336320

Hi @Shree_Mahadik,
The problem you are facing is is because the AppBar widget of the material library is of the PreferredSizeWidget class and not as a Widget. This happened in the newer version of Flutter. We will look into this issue.
Thank you for pointing it out

I solved it by replacing “Widget” to “Static”.
Hope this solution helps.

Another way to fix it is return PreferredSizeWidget class instead of Widget class

PreferredSizeWidget buildAppBarWidget()

1 Like