外层使用StatelessWidget ,要将路由跳转功能封装到StatefulWidget中
class _HomePageState extends State<HomePage> { @override Widget build(BuildContext context) { return Scaffold( body: TextButton( child: const Text("open new route"), onPressed: () { Navigator.push(context, MaterialPageRoute(builder: (context) { return const Home();//挑转到home界面 }), ); }, ),