我编写了三页应用程序的简单代码,在第三页中,当它使用“SetState”时,它返回到第二页,但仅在第三页中发生,当我在第二页中使用“setState”时,它工作正常。我还尝试使用“Navigator.of.push”在页面之间导航,但 setState 只是没有执行任何操作,这里是我的代码示例String check="go to next page";String check2="state1";Widget page3(){ return return FlatButton( child:Text(check2) shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(18.0), side: BorderSide(color: Colors.blue[100])), color: Colors.white, onPressed: (){ setState((){check2="state3"}); }); }Widget Profile(){ return FlatButton( child:Text(check) shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(18.0), side: BorderSide(color: Colors.blue[100])), color: Colors.white, onPressed: (){ setState((){check2="state3"}); Navigator.push( context, MaterialPageRoute(builder: (context) => page3()), ) });}Widget Biuld(BuildContext context){ return return Scaffold( appBar: AppBar( // Here we take the value from the MyHomePage object that was created by // the App.build method, and use it to set our appbar title. title: Text(widget.title), ), body: FlatButton( child:Text("press to start") shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(18.0), side: BorderSide(color: Colors.blue[100])), color: Colors.white, onPressed: (){ Navigator.push( context, MaterialPageRoute(builder: (context) => profile()), ); })); }我得到的结果是,当按下第一个按钮时,它会转到第2页,当我按下第二个按钮时,它会更改第二个按钮文本并转到第三页,但是当我按下第三页上的按钮时,它会返回到第二页。使用 navgitor.of 时,它不会返回到第二页,但也不会更改文本
添加回答
举报
0/150
提交
取消