Reputation:
I have a stateful widget that has one method called in initialisation. I wanna know how to be able to get a parameter from the previous screen and pass it in initState to my initialisation method
class LabDetalheWidget extends StatefulWidget {
final String path;
const LabDetalheWidget({
Key key,
this.path,
}) : super(key: key);
Upvotes: 2
Views: 4119
Reputation: 464
I believe you wanna pass data across routes.. If so then read this flutter cookbook's section you might get the idea https://flutter.dev/docs/cookbook/navigation/passing-data
Upvotes: 0
Reputation: 2529
class MyWidget extends StatefulWidget {
final String param;
const MyWidget({
Key key,
this.param,
}) : super(key: key);
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
@override
void initState() {
print(widget.param);
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
);
}
}
print(widget.param)
Upvotes: 2