v5
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
import 'v4/app.dart';
|
import 'v5/app.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|||||||
@@ -38,16 +38,7 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
|||||||
|
|
||||||
Completer<dynamic>? completer;
|
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 Map<String,dynamic> _pathExtraMap = {};
|
||||||
final List<Page> _livePages = [];
|
|
||||||
|
|
||||||
void setPathForData(String value,dynamic data){
|
void setPathForData(String value,dynamic data){
|
||||||
_pathExtraMap[value] = data;
|
_pathExtraMap[value] = data;
|
||||||
@@ -69,29 +60,15 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return Navigator(
|
||||||
onPopPage: _onPopPage,
|
onPopPage: _onPopPage,
|
||||||
pages: pages.toSet().toList(),
|
pages: _buildPageByPath(path),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Page> _buildPageByPath(String path) {
|
List<Page> _buildPageByPath(String path) {
|
||||||
Widget? child;
|
Widget? child;
|
||||||
if(path.startsWith('/color')){
|
if(path.startsWith('/color')){
|
||||||
// child = Navigator(
|
|
||||||
// pages: ,
|
|
||||||
// onPopPage: _onPopPage,
|
|
||||||
// );
|
|
||||||
return buildColorPages(path);
|
return buildColorPages(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,10 +102,9 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
|||||||
if(segment =='detail'){
|
if(segment =='detail'){
|
||||||
final Map<String, String> queryParams = uri.queryParameters;
|
final Map<String, String> queryParams = uri.queryParameters;
|
||||||
String? selectedColor = queryParams['color'];
|
String? selectedColor = queryParams['color'];
|
||||||
|
|
||||||
if (selectedColor != null) {
|
if (selectedColor != null) {
|
||||||
Color color = Color(int.parse(selectedColor, radix: 16));
|
Color color = Color(int.parse(selectedColor, radix: 16));
|
||||||
result.add( FadeTransitionPage(
|
result.add(FadeTransitionPage(
|
||||||
key: const ValueKey('/color/detail'),
|
key: const ValueKey('/color/detail'),
|
||||||
child:ColorDetailPage(color: color),
|
child:ColorDetailPage(color: color),
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -52,11 +52,7 @@ class _AppNavigationRailState extends State<AppNavigationRail> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _onDestinationSelected(int index) {
|
void _onDestinationSelected(int index) {
|
||||||
if(index==1){
|
router.path = kDestinationsPaths[index];
|
||||||
router.setPathKeepLive(kDestinationsPaths[index]);
|
|
||||||
}else{
|
|
||||||
router.path = kDestinationsPaths[index];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onRouterChange() {
|
void _onRouterChange() {
|
||||||
|
|||||||
@@ -89,9 +89,6 @@ class _ColorAddPageState extends State<ColorAddPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _selectColor() {
|
|
||||||
Navigator.of(context).pop(_color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void changeColor(Color value) {
|
void changeColor(Color value) {
|
||||||
_color = value;
|
_color = value;
|
||||||
|
|||||||
@@ -15,15 +15,6 @@ class ColorDetailPage extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
String text = '# ${color.value.toRadixString(16)}';
|
String text = '# ${color.value.toRadixString(16)}';
|
||||||
return Scaffold(
|
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(
|
body: Container(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
color: color,
|
color: color,
|
||||||
|
|||||||
@@ -36,10 +36,9 @@ class _ColorPageState extends State<ColorPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _selectColor(Color color){
|
void _selectColor(Color color){
|
||||||
String value = color.value.toRadixString(16);
|
// String value = color.value.toRadixString(16);
|
||||||
router.path = '/color/detail?color=$value';
|
// router.path = '/color/detail?color=$value';
|
||||||
// router.setPathForData('/color/detail',color);
|
router.setPathForData('/color/detail',color);
|
||||||
// router.setPathKeepLive('/color/detail?color=$value');
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,30 +38,28 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
|||||||
|
|
||||||
Completer<dynamic>? completer;
|
Completer<dynamic>? completer;
|
||||||
|
|
||||||
final List<String> _alivePaths = [];
|
final Map<String,List<Page>> _alivePageMap = {};
|
||||||
final Map<String,Page> _alivePageMap = {};
|
|
||||||
|
|
||||||
void setPathKeepLive(String value){
|
void setPathKeepLive(String value){
|
||||||
if(!_alivePaths.contains(value)){
|
_alivePageMap[value] = _buildPageByPath(value);
|
||||||
_alivePaths.add(value);
|
|
||||||
}
|
|
||||||
path = value;
|
path = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<String,dynamic> _pathExtraMap = {};
|
final Map<String,dynamic> _pathExtraMap = {};
|
||||||
final List<Page> _livePages = [];
|
|
||||||
|
|
||||||
void setPathForData(String value,dynamic data){
|
FutureOr<dynamic> changePath(String value,{bool forResult=false,Object? extra}){
|
||||||
_pathExtraMap[value] = data;
|
if(forResult){
|
||||||
path = value;
|
_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) {
|
set path(String value) {
|
||||||
if (_path == value) return;
|
if (_path == value) return;
|
||||||
@@ -71,22 +69,16 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
List<Page> pages = _buildPageByPath(path);
|
List<Page> pages = [];
|
||||||
|
if(_alivePageMap.containsKey(path)){
|
||||||
if(_alivePaths.contains(path)){
|
pages = _alivePageMap[path]!;
|
||||||
_alivePageMap[path] = pages.last;
|
}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(
|
return Navigator(
|
||||||
onPopPage: _onPopPage,
|
onPopPage: _onPopPage,
|
||||||
pages: pages.toSet().toList(),
|
pages: pages.toSet().toList(),
|
||||||
@@ -94,11 +86,11 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Page> _buildPageByPath(String path) {
|
List<Page> _buildPageByPath(String path) {
|
||||||
|
Widget? child;
|
||||||
if(path.startsWith('/color')){
|
if(path.startsWith('/color')){
|
||||||
return buildColorPages(path);
|
return buildColorPages(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget? child;
|
|
||||||
if (path == kDestinationsPaths[1]) {
|
if (path == kDestinationsPaths[1]) {
|
||||||
child = const CounterPage();
|
child = const CounterPage();
|
||||||
}
|
}
|
||||||
@@ -127,24 +119,24 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
if(segment =='detail'){
|
if(segment =='detail'){
|
||||||
// final Map<String, String> queryParams = uri.queryParameters;
|
final Map<String, String> queryParams = uri.queryParameters;
|
||||||
// String? selectedColor = queryParams['color'];
|
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),
|
|
||||||
// ));
|
|
||||||
// }
|
|
||||||
|
|
||||||
Color? selectedColor = _pathExtraMap[path];
|
|
||||||
if (selectedColor != null) {
|
if (selectedColor != null) {
|
||||||
|
Color color = Color(int.parse(selectedColor, radix: 16));
|
||||||
result.add( FadeTransitionPage(
|
result.add( FadeTransitionPage(
|
||||||
key: const ValueKey('/color/detail'),
|
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'){
|
if(segment == 'add'){
|
||||||
|
|||||||
@@ -54,8 +54,9 @@ class _AppNavigationRailState extends State<AppNavigationRail> {
|
|||||||
void _onDestinationSelected(int index) {
|
void _onDestinationSelected(int index) {
|
||||||
if(index==1){
|
if(index==1){
|
||||||
router.setPathKeepLive(kDestinationsPaths[index]);
|
router.setPathKeepLive(kDestinationsPaths[index]);
|
||||||
|
}else{
|
||||||
|
router.path = kDestinationsPaths[index];
|
||||||
}
|
}
|
||||||
router.path = kDestinationsPaths[index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onRouterChange() {
|
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:flutter/material.dart';
|
||||||
import 'package:iroute/components/components.dart';
|
import 'package:iroute/components/components.dart';
|
||||||
import '../router/app_router_delegate.dart';
|
import '../router/app_router_delegate.dart';
|
||||||
|
import 'app_router_editor.dart';
|
||||||
|
|
||||||
class AppTopBar extends StatelessWidget {
|
class AppTopBar extends StatelessWidget {
|
||||||
const AppTopBar({super.key});
|
const AppTopBar({super.key});
|
||||||
@@ -11,13 +12,26 @@ class AppTopBar extends StatelessWidget {
|
|||||||
child: Container(
|
child: Container(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
height: 46,
|
height: 46,
|
||||||
child: const Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
Expanded(child: Align(
|
const RouterIndicator(),
|
||||||
alignment: Alignment.centerLeft,
|
Expanded(
|
||||||
child: RouterIndicator())),
|
child: Row(children: [
|
||||||
WindowButtons()
|
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': '系统设置',
|
'/settings': '系统设置',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class _RouterIndicatorState extends State<RouterIndicator> {
|
class _RouterIndicatorState extends State<RouterIndicator> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -59,8 +72,8 @@ class _RouterIndicatorState extends State<RouterIndicator> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return TolyBreadcrumb(
|
return TolyBreadcrumb(
|
||||||
items: pathToBreadcrumbItems(router.path),
|
items: pathToBreadcrumbItems(router.path),
|
||||||
onTapItem: (item){
|
onTapItem: (item) {
|
||||||
if(item.to!=null){
|
if (item.to != null) {
|
||||||
router.path = item.to!;
|
router.path = item.to!;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -84,9 +97,8 @@ class _RouterIndicatorState extends State<RouterIndicator> {
|
|||||||
for (String segment in uri.pathSegments) {
|
for (String segment in uri.pathSegments) {
|
||||||
to += '/$segment';
|
to += '/$segment';
|
||||||
String label = kRouteLabelMap[to] ?? '未知路由';
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,10 @@ class UnitApp extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
// routerDelegate: router,
|
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
fontFamily: "宋体",
|
fontFamily: "宋体",
|
||||||
|
scaffoldBackgroundColor: Colors.white,
|
||||||
appBarTheme: const AppBarTheme(
|
appBarTheme: const AppBarTheme(
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
iconTheme: IconThemeData(color: Colors.black),
|
iconTheme: IconThemeData(color: Colors.black),
|
||||||
|
|||||||
@@ -36,15 +36,15 @@ class _ColorPageState extends State<ColorPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _selectColor(Color color){
|
void _selectColor(Color color){
|
||||||
// String value = color.value.toRadixString(16);
|
String value = color.value.toRadixString(16);
|
||||||
// router.path = '/color/detail?color=$value';
|
router.path = '/color/detail?color=$value';
|
||||||
router.setPathForData('/color/detail',color);
|
// router.setPathForData('/color/detail',color);
|
||||||
// router.setPathKeepLive('/color/detail?color=$value');
|
// router.setPathKeepLive('/color/detail?color=$value');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _toAddPage() async {
|
void _toAddPage() async {
|
||||||
Color? color = await router.changePathForResult('/color/add');
|
Color? color = await router.changePath('/color/add',forResult: true);
|
||||||
if (color != null) {
|
if (color != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_colors.add(color);
|
_colors.add(color);
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ class EmptyPage extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
// appBar: AppBar(
|
||||||
title: Text('界面走丢了'),
|
// title: Text('界面走丢了'),
|
||||||
),
|
// ),
|
||||||
body: Scaffold(
|
body: Scaffold(
|
||||||
body: Center(
|
body: Center(
|
||||||
child: Wrap(
|
child: Wrap(
|
||||||
|
|||||||
Reference in New Issue
Block a user