pass state to another widget code example

Example 1: flutter pass parameter to statefulwidget

class _RecordPageState extends State {
  @override
  Widget build(BuildContext context) {
   .....
   widget.recordObject
   .....
  }
}

Example 2: pass string to a provider flutter

_secondPage(BuildContext context, Widget page) async {    final dataFromSecondPage = await Navigator.push(  context,  MaterialPageRoute(builder: (context) => page),  ) as Data;  // Here we have the data from the second screen  data.counter = dataFromSecondPage.counter;  data.dateTime = dataFromSecondPage.dateTime;  data.text = dataFromSecondPage.text;}

Tags:

Misc Example