This commit is contained in:
toly
2023-12-27 00:55:04 +08:00
parent 34d8e6dd75
commit 1aeab4fa64
189 changed files with 85 additions and 8676 deletions

14
lib/15/01/main.dart Normal file
View File

@@ -0,0 +1,14 @@
import 'package:flutter/material.dart';
import 'pages/app/app.dart';
import 'pages/app/app_router_delegate.dart';
AppRouterDelegate router = AppRouterDelegate();
void main() {
runApp(const App());
}

View File

@@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
import '../../main.dart';
import 'app_tool_bar.dart';
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
appBarTheme: const AppBarTheme(
elevation: 0,
iconTheme: IconThemeData(color: Colors.black),
titleTextStyle: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.bold,
))),
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: const AppToolBar(),
body: Router(routerDelegate: router),
));
}
}

View File

@@ -0,0 +1,92 @@
import 'dart:ffi';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../page_a.dart';
import '../page_b.dart';
import '../page_c.dart';
import '../home_page.dart';
class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier{
List<String> _value = ['/'];
List<String> get value => _value;
set value(List<String> value){
_value = value;
notifyListeners();
}
@override
Widget build(BuildContext context) {
return Navigator(
onPopPage: _onPopPage,
pages: _value.map((e) => _pageMap[e]!).toList(),
);
}
final Map<String, Page> _pageMap = const {
'/': MaterialPage(child: HomePage()),
'a': MaterialPage(child: PageA()),
'b': MaterialPage(child: PageB()),
'c': MaterialPage(child: PageC()),
};
@override
Future<bool> popRoute() async{
print('=======popRoute=========');
return true;
}
bool _onPopPage(Route route, result) {
return route.didPop(result);
}
@override
Future<void> setNewRoutePath(configuration) async{
}
}
// class AppRouterDelegate extends RouterDelegate<String> with ChangeNotifier, PopNavigatorRouterDelegateMixin {
//
// List<String> _value = ['/'];
//
//
// List<String> get value => _value;
//
// set value(List<String> value){
// _value = value;
// notifyListeners();
// }
//
// @override
// Widget build(BuildContext context) {
// return Navigator(
// onPopPage: _onPopPage,
// pages: _value.map((e) => _pageMap[e]!).toList(),
// );
// }
//
// final Map<String, Page> _pageMap = const {
// '/': MaterialPage(child: HomePage()),
// 'a': MaterialPage(child: PageA()),
// 'b': MaterialPage(child: PageB()),
// 'c': MaterialPage(child: PageC()),
// };
//
// bool _onPopPage(Route route, result) {
// _value = List.of(_value)..removeLast();
// notifyListeners();
// return route.didPop(result);
// }
//
// @override
// GlobalKey<NavigatorState>? navigatorKey = GlobalKey<NavigatorState>();
//
// @override
// Future<void> setNewRoutePath(String configuration) async{
// }
// }

View File

@@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
import '../../main.dart';
class AppToolBar extends StatefulWidget implements PreferredSizeWidget{
const AppToolBar({super.key});
@override
State<AppToolBar> createState() => _AppToolBarState();
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
class _AppToolBarState extends State<AppToolBar> {
TextEditingController _ctrl = TextEditingController();
@override
void initState() {
super.initState();
_changRoute();
router.addListener(_changRoute);
}
@override
void dispose() {
router.removeListener(_changRoute);
_ctrl.dispose();
super.dispose();
}
void _changRoute() {
_ctrl.text= router.value.join(',');
}
@override
Widget build(BuildContext context) {
return AppBar(
backgroundColor: Colors.white,
elevation: 0,
title : TextField(
controller: _ctrl,
onSubmitted: _onSubmitted,
decoration: InputDecoration( //装饰
filled: true, //填充
fillColor: Color(0xffF3F6F9), //填充颜色
constraints: BoxConstraints(maxHeight: 34), //约束信息
contentPadding: EdgeInsets.only(top: -14,left: 10),
border: UnderlineInputBorder( //边线信息
borderSide: BorderSide.none,
borderRadius: BorderRadius.all(Radius.circular(6)),
),
hintText: "请输入路由", //提示字
hintStyle: TextStyle(fontSize: 14) //提示字样式
),
),
);
}
void _onSubmitted(String value) {
router.value = value.split(',');
}
}

View File

@@ -0,0 +1,30 @@
import 'package:flutter/material.dart';
import '../main.dart';
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
const Color bgColor = Color(0xffCCFFCC);
return Scaffold(
backgroundColor: bgColor,
appBar: AppBar(
title: const Text('主页起点'),
backgroundColor: bgColor,
),
body: Center(child: ElevatedButton(
onPressed: () => toPageA(context),
child: const Text('Push A'),
),
));
}
void toPageA(BuildContext context) {
router.value = ['/', 'a'];
}
}

View File

@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import '../main.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,
leading: BackButton(onPressed: _pop),
),
body: Center(
child: ElevatedButton(
onPressed: () => toPageB(context),
child: const Text('Push B'),
),
));
}
void toPageB(BuildContext context) {
router.value = ['/', 'a', 'b'];
}
void _pop() {
router.value = List.of(router.value)..removeLast();
}
}

View File

@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import '../main.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,
leading: BackButton(onPressed: _pop),
),
body: Center(
child: ElevatedButton(
onPressed: () => toPageC(context),
child: const Text('Push C'),
),
));
}
void toPageC(BuildContext context){
router.value = ['/','a','b','c'];
}
void _pop() {
router.value = List.of(router.value)..removeLast();
}
}

View File

@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import '../main.dart';
class PageC extends StatelessWidget {
const PageC({super.key});
@override
Widget build(BuildContext context) {
const Color bgColor = Color(0xffFFE6CC);
return Scaffold(
backgroundColor: bgColor,
appBar: AppBar(
title: const Text('C 界面'),
backgroundColor: bgColor,
leading: BackButton(onPressed: _pop),
),
body: Center(
child: Text('到达终点'),
));
}
void _pop() {
router.value = List.of(router.value)..removeLast();
}
}