v5
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import 'v4/app.dart';
|
||||
import 'v5/app.dart';
|
||||
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
@@ -38,16 +38,7 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
|
||||
Completer<dynamic>? completer;
|
||||
|
||||
final List<String> _alivePaths = [];
|
||||
final Map<String,List<Page>> _alivePageMap = {};
|
||||
|
||||
void setPathKeepLive(String value){
|
||||
_alivePageMap[value] = _buildPageByPath(value);
|
||||
path = value;
|
||||
}
|
||||
|
||||
final Map<String,dynamic> _pathExtraMap = {};
|
||||
final List<Page> _livePages = [];
|
||||
|
||||
void setPathForData(String value,dynamic data){
|
||||
_pathExtraMap[value] = data;
|
||||
@@ -69,29 +60,15 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<Page> pages = [];
|
||||
if(_alivePageMap.containsKey(path)){
|
||||
pages = _alivePageMap[path]!;
|
||||
}else{
|
||||
for (var element in _alivePageMap.values) {
|
||||
pages.addAll(element);
|
||||
}
|
||||
pages.addAll(_buildPageByPath(path));
|
||||
}
|
||||
|
||||
return Navigator(
|
||||
onPopPage: _onPopPage,
|
||||
pages: pages.toSet().toList(),
|
||||
pages: _buildPageByPath(path),
|
||||
);
|
||||
}
|
||||
|
||||
List<Page> _buildPageByPath(String path) {
|
||||
Widget? child;
|
||||
if(path.startsWith('/color')){
|
||||
// child = Navigator(
|
||||
// pages: ,
|
||||
// onPopPage: _onPopPage,
|
||||
// );
|
||||
return buildColorPages(path);
|
||||
}
|
||||
|
||||
@@ -125,10 +102,9 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
if(segment =='detail'){
|
||||
final Map<String, String> queryParams = uri.queryParameters;
|
||||
String? selectedColor = queryParams['color'];
|
||||
|
||||
if (selectedColor != null) {
|
||||
Color color = Color(int.parse(selectedColor, radix: 16));
|
||||
result.add( FadeTransitionPage(
|
||||
result.add(FadeTransitionPage(
|
||||
key: const ValueKey('/color/detail'),
|
||||
child:ColorDetailPage(color: color),
|
||||
));
|
||||
|
||||
@@ -52,11 +52,7 @@ class _AppNavigationRailState extends State<AppNavigationRail> {
|
||||
}
|
||||
|
||||
void _onDestinationSelected(int index) {
|
||||
if(index==1){
|
||||
router.setPathKeepLive(kDestinationsPaths[index]);
|
||||
}else{
|
||||
router.path = kDestinationsPaths[index];
|
||||
}
|
||||
router.path = kDestinationsPaths[index];
|
||||
}
|
||||
|
||||
void _onRouterChange() {
|
||||
|
||||
@@ -89,9 +89,6 @@ class _ColorAddPageState extends State<ColorAddPage> {
|
||||
);
|
||||
}
|
||||
|
||||
void _selectColor() {
|
||||
Navigator.of(context).pop(_color);
|
||||
}
|
||||
|
||||
void changeColor(Color value) {
|
||||
_color = value;
|
||||
|
||||
@@ -15,15 +15,6 @@ class ColorDetailPage extends StatelessWidget {
|
||||
);
|
||||
String text = '# ${color.value.toRadixString(16)}';
|
||||
return Scaffold(
|
||||
// appBar: AppBar(
|
||||
// systemOverlayStyle: SystemUiOverlayStyle(
|
||||
// statusBarColor: Colors.transparent,
|
||||
// statusBarIconBrightness: Brightness.light
|
||||
// ),
|
||||
// iconTheme: IconThemeData(color: Colors.white),
|
||||
// titleTextStyle:TextStyle(color: Colors.white,fontSize: 18) ,
|
||||
// backgroundColor: color,
|
||||
// title: Text('颜色界面',),),
|
||||
body: Container(
|
||||
alignment: Alignment.center,
|
||||
color: color,
|
||||
|
||||
@@ -36,10 +36,9 @@ class _ColorPageState extends State<ColorPage> {
|
||||
}
|
||||
|
||||
void _selectColor(Color color){
|
||||
String value = color.value.toRadixString(16);
|
||||
router.path = '/color/detail?color=$value';
|
||||
// router.setPathForData('/color/detail',color);
|
||||
// router.setPathKeepLive('/color/detail?color=$value');
|
||||
// String value = color.value.toRadixString(16);
|
||||
// router.path = '/color/detail?color=$value';
|
||||
router.setPathForData('/color/detail',color);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -38,30 +38,28 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
|
||||
Completer<dynamic>? completer;
|
||||
|
||||
final List<String> _alivePaths = [];
|
||||
final Map<String,Page> _alivePageMap = {};
|
||||
final Map<String,List<Page>> _alivePageMap = {};
|
||||
|
||||
void setPathKeepLive(String value){
|
||||
if(!_alivePaths.contains(value)){
|
||||
_alivePaths.add(value);
|
||||
}
|
||||
_alivePageMap[value] = _buildPageByPath(value);
|
||||
path = value;
|
||||
}
|
||||
|
||||
final Map<String,dynamic> _pathExtraMap = {};
|
||||
final List<Page> _livePages = [];
|
||||
|
||||
void setPathForData(String value,dynamic data){
|
||||
_pathExtraMap[value] = data;
|
||||
path = value;
|
||||
FutureOr<dynamic> changePath(String value,{bool forResult=false,Object? extra}){
|
||||
if(forResult){
|
||||
_completerMap[value] = Completer();
|
||||
}
|
||||
if(extra!=null){
|
||||
_pathExtraMap[value] = extra;
|
||||
}
|
||||
|
||||
if(forResult){
|
||||
return _completerMap[value]!.future;
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> changePathForResult(String value) async{
|
||||
Completer<dynamic> completer = Completer();
|
||||
_completerMap[value] = completer;
|
||||
path = value;
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
set path(String value) {
|
||||
if (_path == value) return;
|
||||
@@ -71,22 +69,16 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<Page> pages = _buildPageByPath(path);
|
||||
|
||||
if(_alivePaths.contains(path)){
|
||||
_alivePageMap[path] = pages.last;
|
||||
List<Page> pages = [];
|
||||
if(_alivePageMap.containsKey(path)){
|
||||
pages = _alivePageMap[path]!;
|
||||
}else{
|
||||
for (var element in _alivePageMap.values) {
|
||||
pages.addAll(element);
|
||||
}
|
||||
pages.addAll(_buildPageByPath(path));
|
||||
}
|
||||
|
||||
pages.insertAll(0,_alivePageMap.values);
|
||||
|
||||
// if(!_livePaths.contains(path)){
|
||||
// if(_livePaths.isNotEmpty){
|
||||
// pages.addAll(_buildPageByPath(_livePaths.first));
|
||||
// }
|
||||
// }
|
||||
|
||||
// pages.addAll();
|
||||
|
||||
return Navigator(
|
||||
onPopPage: _onPopPage,
|
||||
pages: pages.toSet().toList(),
|
||||
@@ -94,11 +86,11 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
}
|
||||
|
||||
List<Page> _buildPageByPath(String path) {
|
||||
Widget? child;
|
||||
if(path.startsWith('/color')){
|
||||
return buildColorPages(path);
|
||||
}
|
||||
|
||||
Widget? child;
|
||||
if (path == kDestinationsPaths[1]) {
|
||||
child = const CounterPage();
|
||||
}
|
||||
@@ -127,24 +119,24 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
));
|
||||
}
|
||||
if(segment =='detail'){
|
||||
// final Map<String, String> queryParams = uri.queryParameters;
|
||||
// String? selectedColor = queryParams['color'];
|
||||
//
|
||||
// if (selectedColor != null) {
|
||||
// Color color = Color(int.parse(selectedColor, radix: 16));
|
||||
// result.add( FadeTransitionPage(
|
||||
// key: const ValueKey('/color/detail'),
|
||||
// child:ColorDetailPage(color: color),
|
||||
// ));
|
||||
// }
|
||||
final Map<String, String> queryParams = uri.queryParameters;
|
||||
String? selectedColor = queryParams['color'];
|
||||
|
||||
Color? selectedColor = _pathExtraMap[path];
|
||||
if (selectedColor != null) {
|
||||
Color color = Color(int.parse(selectedColor, radix: 16));
|
||||
result.add( FadeTransitionPage(
|
||||
key: const ValueKey('/color/detail'),
|
||||
child:ColorDetailPage(color: selectedColor),
|
||||
child:ColorDetailPage(color: color),
|
||||
));
|
||||
_pathExtraMap.remove(path);
|
||||
}else{
|
||||
Color? selectedColor = _pathExtraMap[path];
|
||||
if (selectedColor != null) {
|
||||
result.add( FadeTransitionPage(
|
||||
key: const ValueKey('/color/detail'),
|
||||
child:ColorDetailPage(color: selectedColor),
|
||||
));
|
||||
_pathExtraMap.remove(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(segment == 'add'){
|
||||
|
||||
@@ -54,8 +54,9 @@ class _AppNavigationRailState extends State<AppNavigationRail> {
|
||||
void _onDestinationSelected(int index) {
|
||||
if(index==1){
|
||||
router.setPathKeepLive(kDestinationsPaths[index]);
|
||||
}else{
|
||||
router.path = kDestinationsPaths[index];
|
||||
}
|
||||
router.path = kDestinationsPaths[index];
|
||||
}
|
||||
|
||||
void _onRouterChange() {
|
||||
|
||||
64
lib/v5/app/navigation/views/app_router_editor.dart
Normal file
64
lib/v5/app/navigation/views/app_router_editor.dart
Normal file
@@ -0,0 +1,64 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:iroute/components/toly_ui/button/hover_icon_button.dart';
|
||||
import '../router/app_router_delegate.dart';
|
||||
|
||||
class AppRouterEditor extends StatefulWidget {
|
||||
final ValueChanged<String>? onSubmit;
|
||||
const AppRouterEditor({super.key, this.onSubmit});
|
||||
|
||||
@override
|
||||
State<AppRouterEditor> createState() => _AppRouterEditorState();
|
||||
}
|
||||
|
||||
class _AppRouterEditorState extends State<AppRouterEditor> {
|
||||
|
||||
final TextEditingController _controller = TextEditingController();
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_onRouteChange();
|
||||
router.addListener(_onRouteChange);
|
||||
}
|
||||
|
||||
void _onRouteChange() {
|
||||
_controller.text=router.path;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
router.removeListener(_onRouteChange);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
alignment: Alignment.centerRight,
|
||||
children: [
|
||||
SizedBox(
|
||||
child: CupertinoTextField(
|
||||
controller: _controller,
|
||||
style: TextStyle(fontSize: 14),
|
||||
padding: EdgeInsets.only(left:12,top: 6,bottom: 6,right: 32),
|
||||
placeholder: '输入路由地址导航',
|
||||
onSubmitted: widget.onSubmit,
|
||||
decoration: BoxDecoration(color: Color(0xffF1F2F3),borderRadius: BorderRadius.circular(6)),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: HoverIconButton(
|
||||
icon: Icons.directions_outlined,
|
||||
defaultColor: Color(0xff68696B),
|
||||
onPressed:()=>widget.onSubmit?.call(_controller.text),
|
||||
size: 20
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:iroute/components/components.dart';
|
||||
import '../router/app_router_delegate.dart';
|
||||
import 'app_router_editor.dart';
|
||||
|
||||
class AppTopBar extends StatelessWidget {
|
||||
const AppTopBar({super.key});
|
||||
@@ -11,13 +12,26 @@ class AppTopBar extends StatelessWidget {
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
height: 46,
|
||||
child: const Row(
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(width: 16),
|
||||
Expanded(child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: RouterIndicator())),
|
||||
WindowButtons()
|
||||
const SizedBox(width: 16),
|
||||
const RouterIndicator(),
|
||||
Expanded(
|
||||
child: Row(children: [
|
||||
const Spacer(),
|
||||
SizedBox(
|
||||
width: 250,
|
||||
child: AppRouterEditor(
|
||||
onSubmit: (path) => router.path = path,
|
||||
)),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 12.0),
|
||||
child: VerticalDivider(
|
||||
width: 32,
|
||||
),
|
||||
)
|
||||
])),
|
||||
const WindowButtons()
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -41,7 +55,6 @@ Map<String, String> kRouteLabelMap = {
|
||||
'/settings': '系统设置',
|
||||
};
|
||||
|
||||
|
||||
class _RouterIndicatorState extends State<RouterIndicator> {
|
||||
@override
|
||||
void initState() {
|
||||
@@ -59,8 +72,8 @@ class _RouterIndicatorState extends State<RouterIndicator> {
|
||||
Widget build(BuildContext context) {
|
||||
return TolyBreadcrumb(
|
||||
items: pathToBreadcrumbItems(router.path),
|
||||
onTapItem: (item){
|
||||
if(item.to!=null){
|
||||
onTapItem: (item) {
|
||||
if (item.to != null) {
|
||||
router.path = item.to!;
|
||||
}
|
||||
},
|
||||
@@ -84,9 +97,8 @@ class _RouterIndicatorState extends State<RouterIndicator> {
|
||||
for (String segment in uri.pathSegments) {
|
||||
to += '/$segment';
|
||||
String label = kRouteLabelMap[to] ?? '未知路由';
|
||||
result.add(BreadcrumbItem(to: to, label: label,active: to==distPath));
|
||||
result.add(BreadcrumbItem(to: to, label: label, active: to == distPath));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,10 @@ class UnitApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return MaterialApp(
|
||||
// routerDelegate: router,
|
||||
theme: ThemeData(
|
||||
fontFamily: "宋体",
|
||||
scaffoldBackgroundColor: Colors.white,
|
||||
appBarTheme: const AppBarTheme(
|
||||
elevation: 0,
|
||||
iconTheme: IconThemeData(color: Colors.black),
|
||||
|
||||
@@ -36,15 +36,15 @@ class _ColorPageState extends State<ColorPage> {
|
||||
}
|
||||
|
||||
void _selectColor(Color color){
|
||||
// String value = color.value.toRadixString(16);
|
||||
// router.path = '/color/detail?color=$value';
|
||||
router.setPathForData('/color/detail',color);
|
||||
String value = color.value.toRadixString(16);
|
||||
router.path = '/color/detail?color=$value';
|
||||
// router.setPathForData('/color/detail',color);
|
||||
// router.setPathKeepLive('/color/detail?color=$value');
|
||||
|
||||
}
|
||||
|
||||
void _toAddPage() async {
|
||||
Color? color = await router.changePathForResult('/color/add');
|
||||
Color? color = await router.changePath('/color/add',forResult: true);
|
||||
if (color != null) {
|
||||
setState(() {
|
||||
_colors.add(color);
|
||||
|
||||
@@ -6,9 +6,9 @@ class EmptyPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('界面走丢了'),
|
||||
),
|
||||
// appBar: AppBar(
|
||||
// title: Text('界面走丢了'),
|
||||
// ),
|
||||
body: Scaffold(
|
||||
body: Center(
|
||||
child: Wrap(
|
||||
|
||||
Reference in New Issue
Block a user