我有两个文件。main.dart arview.dart
在arview.dart中,有由用户运动触发的回调,我想从回调内部返回到main.dart类
在arview.dart中
class ArViewState extends State<ArViewWidget> with WidgetsBindingObserver {
.
.
.
Future<void> onArchitectWidgetCreated() async {
this.architectWidget.setJSONObjectReceivedCallback((jsonObjectReceived) {
// I want to go back to the TopPage class in main.dart here.
// however how can I do that?? my code is like this below.
return Navigator.pushReplacement(context,
NoAnimationMaterialPageRoute(
builder: (context) => TopPage()));在main.dart中
import arview.dart;
class TopPage extends StatefulWidget {
TopPage({Key key, this.title}) : super(key: key);
final String title;
@override
_TopPageState createState() => _TopPageState();
}
class _TopPageState extends State<TopPage> {
Widget aboutButton(num){
return Expanded(
child:FlatButton(
padding:EdgeInsets.only(bottom:10,right:5,left:5,top:10),
child: Image.asset("mybtn.png");
),
);
}发布于 2019-12-26 11:04:58
使用Navigator.pop()返回。
要实现返回原始路由的
,请更新SecondRoute小部件中的onPressed()回调:
onPressed: () {
Navigator.pop(context);
}https://stackoverflow.com/questions/59486017
复制相似问题