diff --git a/lib/06/02/main.dart b/lib/06/02/main.dart new file mode 100644 index 0000000..77940c4 --- /dev/null +++ b/lib/06/02/main.dart @@ -0,0 +1,48 @@ +import 'package:flutter/material.dart'; + +import 'pages/page_a.dart'; +import 'pages/page_b.dart'; +import 'pages/page_c.dart'; + +void main() { + runApp(const MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Demo', + debugShowCheckedModeBanner: false, + theme: ThemeData( + appBarTheme: AppBarTheme( + elevation: 0, + iconTheme: IconThemeData(color: Colors.black), + titleTextStyle: TextStyle(color: Colors.black,fontSize: 18,fontWeight: FontWeight.bold) + ) + ), + home: const PageA(), + onUnknownRoute: _onUnknownRoute, + ); + } + + Route? _onUnknownRoute(RouteSettings settings) { + String? name = settings.name; + Widget? page ; + if(name=='/a'){ + page = const PageA(); + } + if(name=='/b'){ + page = const PageB(); + } + if(name=='/c'){ + page = const PageC(); + } + if(page!=null){ + return MaterialPageRoute(builder: (_)=> const PageB()); + } + return null; + } +} diff --git a/lib/06/02/pages/page_a.dart b/lib/06/02/pages/page_a.dart new file mode 100644 index 0000000..940ff84 --- /dev/null +++ b/lib/06/02/pages/page_a.dart @@ -0,0 +1,28 @@ +import 'package:flutter/material.dart'; +import 'page_b.dart'; + +class PageA extends StatelessWidget { + const PageA({super.key}); + + @override + Widget build(BuildContext context) { + const Color bgColor = Color(0xffCCFFFF); + + return Scaffold( + backgroundColor: bgColor, + appBar: AppBar(title: const Text('A'), + backgroundColor: bgColor, + ), + body: Center( + child: ElevatedButton( + onPressed: ()=>toPageB(context), + child: const Text('Push B'), + ), + ), + ); + } + + void toPageB(BuildContext context){ + Navigator.of(context).push(MaterialPageRoute(builder: (_)=> const PageB())); + } +} diff --git a/lib/06/02/pages/page_b.dart b/lib/06/02/pages/page_b.dart new file mode 100644 index 0000000..a132264 --- /dev/null +++ b/lib/06/02/pages/page_b.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; + +import 'page_c.dart'; + +class PageB extends StatelessWidget { + const PageB({super.key}); + + @override + Widget build(BuildContext context) { + const Color bgColor = Color(0xffCCE5FF); + + return Scaffold( + backgroundColor: bgColor, + appBar: AppBar(title: const Text('B',), + backgroundColor: bgColor, + ), + body: Center( + child: ElevatedButton( + onPressed: ()=>toPageC(context), + child: const Text('Push C'), + ), + ), + ); + } + + void toPageC(BuildContext context){ + Navigator.of(context).push(MaterialPageRoute(builder: (_)=> const PageC())); + } +} \ No newline at end of file diff --git a/lib/06/02/pages/page_c.dart b/lib/06/02/pages/page_c.dart new file mode 100644 index 0000000..ac595f0 --- /dev/null +++ b/lib/06/02/pages/page_c.dart @@ -0,0 +1,21 @@ +import 'package:flutter/material.dart'; + +class PageC extends StatelessWidget { + const PageC({super.key}); + + @override + Widget build(BuildContext context) { + const Color bgColor = Color(0xffFFE6CD); + + return Scaffold( + backgroundColor: bgColor, + appBar: AppBar( + title: const Text('C'), + backgroundColor: bgColor, + ), + body: const Center( + child: Text('到达终点'), + ), + ); + } +} diff --git a/lib/07/03/main.dart b/lib/07/03/main.dart new file mode 100644 index 0000000..346b963 --- /dev/null +++ b/lib/07/03/main.dart @@ -0,0 +1,48 @@ +import 'package:flutter/material.dart'; + +import 'pages/page_a.dart'; +import 'pages/page_b.dart'; +import 'pages/page_c.dart'; + +void main() { + runApp(const MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Demo', + debugShowCheckedModeBanner: false, + theme: ThemeData( + appBarTheme: AppBarTheme( + elevation: 0, + iconTheme: IconThemeData(color: Colors.black), + titleTextStyle: TextStyle(color: Colors.black,fontSize: 18,fontWeight: FontWeight.bold) + ) + ), + home: const PageA(), + onUnknownRoute: _onUnknownRoute, + ); + } + + Route? _onUnknownRoute(RouteSettings settings) { + String? name = settings.name; + Widget? page ; + if(name=='/a'){ + page = const PageA(); + } + if(name=='/b'){ + page = const PageB(); + } + if(name=='/c'){ + page = const PageC(); + } + if(page!=null){ + return MaterialPageRoute(builder: (_)=> page!,settings: settings); + } + return null; + } +} diff --git a/lib/07/03/pages/page_a.dart b/lib/07/03/pages/page_a.dart new file mode 100644 index 0000000..c68192d --- /dev/null +++ b/lib/07/03/pages/page_a.dart @@ -0,0 +1,28 @@ +import 'package:flutter/material.dart'; +import 'page_b.dart'; + +class PageA extends StatelessWidget { + const PageA({super.key}); + + @override + Widget build(BuildContext context) { + const Color bgColor = Color(0xffCCFFFF); + + return Scaffold( + backgroundColor: bgColor, + appBar: AppBar(title: const Text('A'), + backgroundColor: bgColor, + ), + body: Center( + child: ElevatedButton( + onPressed: ()=>toPageB(context), + child: const Text('Push B'), + ), + ), + ); + } + + void toPageB(BuildContext context){ + Navigator.of(context).pushNamed('/a'); + } +} diff --git a/lib/07/03/pages/page_b.dart b/lib/07/03/pages/page_b.dart new file mode 100644 index 0000000..b36561e --- /dev/null +++ b/lib/07/03/pages/page_b.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; + +import 'page_c.dart'; + +class PageB extends StatelessWidget { + const PageB({super.key}); + + @override + Widget build(BuildContext context) { + const Color bgColor = Color(0xffCCE5FF); + + return Scaffold( + backgroundColor: bgColor, + appBar: AppBar(title: const Text('B',), + backgroundColor: bgColor, + ), + body: Center( + child: ElevatedButton( + onPressed: ()=>toPageC(context), + child: const Text('Push C'), + ), + ), + ); + } + + void toPageC(BuildContext context){ + Navigator.of(context).pushNamed('/c'); + } +} \ No newline at end of file diff --git a/lib/07/03/pages/page_c.dart b/lib/07/03/pages/page_c.dart new file mode 100644 index 0000000..10b7a19 --- /dev/null +++ b/lib/07/03/pages/page_c.dart @@ -0,0 +1,36 @@ +import 'package:flutter/material.dart'; + +import 'page_d.dart'; + +class PageC extends StatelessWidget { + const PageC({super.key}); + + @override + Widget build(BuildContext context) { + const Color bgColor = Color(0xffFFE6CD); + + return Scaffold( + backgroundColor: bgColor, + appBar: AppBar( + title: const Text('C'), + backgroundColor: bgColor, + ), + body: Center( + child: ElevatedButton( + onPressed: ()=>toPageD(context), + child: const Text('Push D Remove Until A'), + ), + ), + ); + } + + void toPageD(BuildContext context){ + Navigator.of(context).pushAndRemoveUntil( + MaterialPageRoute(builder: (BuildContext context) => const PageD()), + ModalRoute.withName('/a'), + ); + } +} + + + diff --git a/lib/07/03/pages/page_d.dart b/lib/07/03/pages/page_d.dart new file mode 100644 index 0000000..dda11df --- /dev/null +++ b/lib/07/03/pages/page_d.dart @@ -0,0 +1,22 @@ +import 'package:flutter/material.dart'; +import 'package:iroute/06/02/pages/page_a.dart'; + +class PageD extends StatelessWidget { + const PageD({super.key}); + + @override + Widget build(BuildContext context) { + const Color bgColor = Color(0xffFFCCFF); + + return Scaffold( + backgroundColor: bgColor, + appBar: AppBar( + title: const Text('D'), + backgroundColor: bgColor, + ), + body: Center( + child: const Text('到达终点'), + ), + ); + } +}