0

I have a Stateful widget called Widget1 shown in one page. When I open my app the widget1 gets build from scratch and shown in the page. Let's assume the widget1 is quite heavy with lot's of other widget's inside it.

Now I want to display the same widget in another page but I don't want to build the same widget1 from scratch like I did in the first page. I want to reuse the widget which was built in the Previous page to be shown in this page.

Is that possible in flutter? I know flutter must build a widget inorder to make changes in Ui. But is this really possible? that is , to store a widget and use it, whenever we want without having to rebuild it, again from scratch?.

Allan
  • 110
  • 9
  • While maybe possible, you should think about making the widget itself rather lightweight and having the *data* in a central location in your program. This way the heavy lifting (acessing the data) is done once and your widget can be shown in multiple places without problems. – nvoigt Aug 24 '21 at 11:28
  • @nvoigt Yeah it's the flutter way. But it'll be easy If there's a way to use one widget ( one- time processing) and reuse it, whenever we want like storing it in a global variable and accessing it. – Allan Aug 24 '21 at 11:30
  • Your device is more powerful than the thing they flew to the moon with. Why do you think re-building a widget would be a problem? What are you doing in there that takes that much time and cpu cycles? – nvoigt Aug 24 '21 at 11:32
  • @nvoigt actually I'm just using a pageview builder to creating Inappwebview widget (also a youtube iframe video is fed to the inappwebview and video is played in it) on every page. My app is laggy when I swipe the page. I can clearly see the delay is on start of the swipe , and the lag stops after the inappwebview is rendered on the screen. I've optimized my app without any memory leakages and the statemanagement way. But The widget pageview itself is a bit buggy and works smooth on only lighter widgets. – Allan Aug 24 '21 at 11:37
  • I would suggest you post the code to it and the problem as a question here on SO. Guessing a solution and asking about that solution here is a surefire way to go off into the completely wrong direction. – nvoigt Aug 24 '21 at 11:39
  • @nvoigt https://stackoverflow.com/questions/68847830/how-to-make-pageview-builder-scrolling-animation-from-laggy-to-extremely-smoot . I've posted it already. – Allan Aug 24 '21 at 11:42
  • oh, perfect. I did not see that. – nvoigt Aug 24 '21 at 11:43

0 Answers0