首页 > 解决方案 > 如何在 navigator.pop 中定义路由

问题描述

类 Verification 扩展 StatelessWidget { const Verification({Key?key}) : super(key: key);

@override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( body: Padding( padding: const EdgeInsets.only(top: 30,left: 20), child: Column( children: [ Row( children)) : [ InkWell( onTap: (){ Navigator.pop(context); }, child: Image.asset( "assets/images/vector.png", scale: 2.5, ), ), SizedBox( width: MediaQuery.of( context).size.width * 0.2, ), Text( "验证", style: TextStyle(fontSize: 28, fontWeight: FontWeight.w700), ), ], ), Padding( padding: const EdgeInsets.only(top: 15 ), child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Text("Enter your" ,style: TextStyle(fontSize: 48, fontWeight: FontWeight.w700),), ], ), ),Row( mainAxisAlignment: MainAxisAlignment .start, children: [ Text("验证码" ,style: TextStyle(fontSize: 48,fontWeight: FontWeight.w700),), ], ),

        ],
      ),
    ),
  ),
);

} }

标签: flutter

解决方案


不能在 navigator.pop 中定义路由,只能返回一页。如果要返回几个 Screen,可以使用

nav = Navigator.of(context);
nav.pop();
nav.pop();

推荐阅读