0
I have already understood how the process of changing the state of a widget
where it is 'updated' to show its new value. However, the documentation speaks of the flow, that is, the path that is traveled:
In Flutter, change Notifications flow "up" the widget Hierarchy by way of callbacks, while Current state flows "down" to the stateless widgets that do Presentation. The common Parent that Redirects this flow is the State. The following Slightly more Complex example shows how this Works in Practice:
I would like to understand how exactly this 'up' flow works when it refers to notifying change, while the current state flows 'down' to the widget
who made the presentation.
*Example referring to the English phrase:
class CounterDisplay extends StatelessWidget {
CounterDisplay({this.count});
final int count;
@override
Widget build(BuildContext context) {
return Text('Count: $count');
}
}
class CounterIncrementor extends StatelessWidget {
CounterIncrementor({this.onPressed});
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
return RaisedButton(
onPressed: onPressed,
child: Text('Increment'),
);
}
}
class Counter extends StatefulWidget {
@override
_CounterState createState() => _CounterState();
}
class _CounterState extends State<Counter> {
int _counter = 0;
void _increment() {
setState(() {
++_counter;
});
}
@override
Widget build(BuildContext context) {
return Row(children: <Widget>[
CounterIncrementor(onPressed: _increment),
CounterDisplay(count: _counter),
]);
}
}
I imagined that this was what was happening but without the explanation of the image was difficult to assimilate. As I’m starting I want to know the basics and then go deeper with Bloc, Provider, etc. Thanks for the great explanation.
– rubStackOverflow