TL;DR: when do I pass a variable to a state contra access it from the widget.
I often come to a point when I must choose to either pass a property from my stateful widget to my state constructor, or use the widget.property
syntax to access it directly from the Widget.
class MyWidget extends StatefulWidget {
final myProperty;
ParallaxView({this.myProperty});
@override
_MyWidgetState createState() => _MyWidgetState(myProperty);
}
class MyWidgetState extends State<MyWidget> {
final myProperty;
MyWidgetState({this.myProperty});
@override
Widget build(BuildContext context) {
return Container(child: myProperty); //<-using passed property
return Container(child: widget.myProperty); //<-or, using widgets property?
}
Is there a right way to go about this or is it only preference?