Please look at comments in the code to understand each use case:
class AnotherWidget extends StatefulWidget {
final String fromParentVariable;
AnotherWidget({
this.fromParentVariable
});
@override
_AnotherWidgetState createState() => _AnotherWidgetState();
}
class _AnotherWidgetState extends State<AnotherWidget> {
String localVariable;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
// You can access the variable coming from the parent by using the "widget." prefix.
Text(widget.fromParentVariable),
// You can access a local variable by simply calling normaly.
Text(localVariable),
],
);
}
}
When calling the Widget you would do this:
AnotherWidget(fromParentVariable: 'my string',)