Flutter setState to another class?

后端 未结 4 1171
日久生厌
日久生厌 2020-11-27 20:54

I have a root class RootPage which is a StatefulWidget which is always in view. I would like to change the body in RootPage

4条回答
  •  无人及你
    2020-11-27 21:21

    Actually the most effective way to do this is using BLoC package in flutter and implement it from the top of the widget tree so all inheriting widgets can use the same bloc. If you have worked with Android before - it works like Android Architecture Components - you separate data and state management from the UI - so you do not setState in the UI, but instead use the BLoC to manage state. So you can set and access the same data - from any widget that inherits from the top widget where the BLoC is implemented, for more complex apps, it is very useful.

    This is where you can find the package: https://pub.dev/packages/flutter_bloc#-readme-tab-

    Write-up: https://www.didierboelens.com/2018/08/reactive-programming-streams-bloc/

    And a great tutorial on youtube https://www.youtube.com/watch?v=hTExlt1nJZI&list=PLB6lc7nQ1n4jCBkrirvVGr5b8rC95VAQ5&index=7

提交回复
热议问题