From 74f9c288ab638f75c6c80d8c1baaa8c76f9ac512 Mon Sep 17 00:00:00 2001 From: toly <1981462002@qq.com> Date: Thu, 11 Jan 2024 14:55:19 +0800 Subject: [PATCH] fix pushAndRemoveUntil demo --- lib/08/02/main.dart | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/08/02/main.dart b/lib/08/02/main.dart index 346b963..0e745f2 100644 --- a/lib/08/02/main.dart +++ b/lib/08/02/main.dart @@ -23,7 +23,7 @@ class MyApp extends StatelessWidget { titleTextStyle: TextStyle(color: Colors.black,fontSize: 18,fontWeight: FontWeight.bold) ) ), - home: const PageA(), + home: const HomePage(), onUnknownRoute: _onUnknownRoute, ); } @@ -46,3 +46,28 @@ class MyApp extends StatelessWidget { return null; } } + +class HomePage extends StatelessWidget { + const HomePage({super.key}); + @override + Widget build(BuildContext context) { + const Color bgColor = Color(0xffCCFFFF); + + return Scaffold( + backgroundColor: bgColor, + appBar: AppBar(title: const Text('主页'), + backgroundColor: bgColor, + ), + body: Center( + child: ElevatedButton( + onPressed: ()=>toPageB(context), + child: const Text('Push A'), + ), + ), + ); + } + + void toPageB(BuildContext context){ + Navigator.of(context).pushNamed('/a'); + } +}