Receive Response from pop navigator in Flutter

前端 未结 2 736
情深已故
情深已故 2021-01-28 04:38

Here is a simple example of code that navigator push for a form called. and pop for an answer. my goal is to make a pop of an object, not a string, but keeping it that simple st

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-28 05:14

    Add await to receive the result from Future and return the value;

       Future getFormData(BuildContext context) async {
        final result = await Navigator.push(
            context, MaterialPageRoute(builder: (context) => MyCustomForm()));
        return Future.value(result);
      }
    

    Modify the FloatingActionButton onPressed code to receive Future String

    onPressed: () async {
                final value = await getFormData(context);
                setState(() {
                  data = value;
                });
              },
    

提交回复
热议问题