How to manage to force a Widget to rebuild immediately after one of the property value has changed? Some pseudo code:
class Live extends StatefulWidget {
String name;
Live(this.name);
@override
_LiveState createState() => _LiveState();
}
class _LiveState extends State<Live> {
// some turbo logic I don't want to move to Live class
..
@override
Widget build(BuildContext context) {
return Column(childrens: [
Text(widget.name),
Card(content calculated based on turbo logic),
]
);
}
}
When String name
property has updated (based on parent's setState call), everything is happening in real time. The change is reflected immediately in Text widget. The value is visible immediately only because i am using widget.name
call so in built()
method I am using property from Live
class instead of State.
The problem is that another widget wrapped in Card is calculated in place marked as // some turbo logic I don't want to move to Live class
. Due to this fact when I want to see updates in this section I need to switch tab and go to e.g Setting and then return to Live tab to see changes related to Card content. I believe it trigger build() method again.
Golas:
- Once the
name
value is updated in Live widget, a State widget rebuilds immediately. - do not move
turbo logic
to Live class and keep it in State class