简体   繁体   中英

Error in background image from asset in SliverAppBar in flutter

I am making an app in which i am using a sliver app bar. I want to change the background with image from my asset but i am getting an error that " The Constructor being called isn't a const constructor" I am new in flutter and unable to resolve this error. Please help enter image description here

enter image description here

The problem with your code is that you are assigning a constant FlexibleSpaceBar() widget to flexibleSpace parameter which isn't supposed to be constant as SliverAppBar is a dynamic widget and it changes its size at run-time as the user scrolls it up and down so making FlexibleSpaceBar() widget const doesn't make any sense.

SO the solution is to just remove the const keyword before the FlexibleSpaceBar() constructor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM