flutter刷新页面_如何返回并刷新Flutter中的上一页?

小编典典

当您导航回首页时,可以触发API调用,例如此 伪代码

class PageOne extends StatefulWidget {

@override

_PageOneState createState() => new _PageOneState();

}

class _PageOneState extends State {

_getRequests()async{

}

@override

Widget build(BuildContext context) {

return new Scaffold(

body: new Center(

child: new RaisedButton(onPressed: ()=>

Navigator.of(context).push(new MaterialPageRoute(builder: (_)=>new PageTwo()),)

.then((val)=>val?_getRequests():null),

),

));

}

}

class PageTwo extends StatelessWidget {

@override

Widget build(BuildContext context) {

//somewhere

Navigator.pop(context,true);

}

}

或者,如果API经常更新,则可以使用流,新数据将在您的内部自动更新 ListView

例如使用firebase,我们可以做到这一点

stream: FirebaseDatabase.instance.reference().child(

"profiles").onValue

而且,只要您更改数据库中的某些内容(例如,从“编辑个人资料”页面进行更改),该内容就会反映在您的个人资料页面上。在这种情况下,这仅是可能的,因为我正在使用onValue它将继续监听所有更改并代表您进行更新。

2020-08-13


版权声明:本文为weixin_39609354原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。