14-02
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
import 'pages/app/app.dart';
|
||||
import 'pages/app/app_router_delegate.dart';
|
||||
|
||||
@@ -11,4 +12,3 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:iroute/13/04/app/navigation/router/iroute.dart';
|
||||
import 'package:iroute/common/pages/stl_color_page.dart';
|
||||
|
||||
import '../../pages/color/color_page.dart';
|
||||
import '../../pages/empty/empty_page.dart';
|
||||
@@ -34,9 +35,13 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
return null;
|
||||
}
|
||||
|
||||
late Completer<dynamic> completer;
|
||||
final Map<String,Completer<dynamic>> _completerMap = {};
|
||||
|
||||
Completer<dynamic>? completer;
|
||||
|
||||
Future<dynamic> changePathForResult(String value) async{
|
||||
completer = Completer();
|
||||
Completer<dynamic> completer = Completer();
|
||||
_completerMap[value] = completer;
|
||||
path = value;
|
||||
return completer.future;
|
||||
}
|
||||
@@ -78,30 +83,11 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
}
|
||||
|
||||
List<Page> _buildPageByPath(String path) {
|
||||
|
||||
|
||||
if(path.startsWith('/color')){
|
||||
return buildColorPages(path);
|
||||
}
|
||||
|
||||
Widget? child;
|
||||
List<Page> result = [];
|
||||
if(path.startsWith('/color')){
|
||||
result.add( FadeTransitionPage(
|
||||
key: ValueKey('/color'),
|
||||
child:const ColorPage(),
|
||||
));
|
||||
|
||||
|
||||
if(path == '/color/add'){
|
||||
result.add( FadeTransitionPage(
|
||||
key: ValueKey('/color/add'),
|
||||
child:const ColorAddPage(),
|
||||
));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (path == kDestinationsPaths[0]) {
|
||||
child = const ColorPage();
|
||||
}
|
||||
if (path == kDestinationsPaths[1]) {
|
||||
child = const CounterPage();
|
||||
}
|
||||
@@ -119,6 +105,38 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
];
|
||||
}
|
||||
|
||||
List<Page> buildColorPages(String path){
|
||||
List<Page> result = [];
|
||||
Uri uri = Uri.parse(path);
|
||||
for (String segment in uri.pathSegments) {
|
||||
if(segment == 'color'){
|
||||
result.add( const FadeTransitionPage(
|
||||
key: ValueKey('/color'),
|
||||
child:ColorPage(),
|
||||
));
|
||||
}
|
||||
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:StlColorPage(color: color),
|
||||
));
|
||||
}
|
||||
}
|
||||
if(segment == 'add'){
|
||||
result.add( const FadeTransitionPage(
|
||||
key: ValueKey('/color/add'),
|
||||
child:ColorAddPage(),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> popRoute() async {
|
||||
print('=======popRoute=========');
|
||||
@@ -126,17 +144,28 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
}
|
||||
|
||||
bool _onPopPage(Route route, result) {
|
||||
if(path == '/color/add'){
|
||||
completer.complete(result);
|
||||
path = '/color';
|
||||
if(_completerMap.containsKey(path)){
|
||||
_completerMap[path]?.complete(result);
|
||||
_completerMap.remove(path);
|
||||
}
|
||||
|
||||
path = backPath(path);
|
||||
return route.didPop(result);
|
||||
}
|
||||
|
||||
String backPath(String path){
|
||||
Uri uri = Uri.parse(path);
|
||||
if(uri.pathSegments.length==1) return path;
|
||||
List<String> parts = List.of(uri.pathSegments)..removeLast();
|
||||
return '/${parts.join('/')}';
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setNewRoutePath(configuration) async {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// class AppRouterDelegate extends RouterDelegate<String> with ChangeNotifier, PopNavigatorRouterDelegateMixin {
|
||||
//
|
||||
// List<String> _value = ['/'];
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
||||
|
||||
class ColorAddPage extends StatefulWidget {
|
||||
const ColorAddPage({super.key});
|
||||
@@ -22,31 +23,58 @@ class _ColorAddPageState extends State<ColorAddPage> {
|
||||
Widget build(BuildContext context) {
|
||||
String text = '# ${_color.value.toRadixString(16)}';
|
||||
return Scaffold(
|
||||
// appBar: AppBar(
|
||||
// title: Text('添加颜色'),
|
||||
// actions: [IconButton(onPressed: _selectColor, icon: Icon(Icons.check ))],
|
||||
// ),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0,vertical: 20),
|
||||
bottomNavigationBar: Container(
|
||||
margin: EdgeInsets.only(right:20,bottom: 20),
|
||||
// color: Colors.redAccent,
|
||||
child: Row(
|
||||
textDirection:TextDirection.rtl,
|
||||
children: [
|
||||
Expanded(child: Text(text,style: TextStyle(color: _color,fontSize: 24,letterSpacing: 4),)),
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: 10),
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: Icon(
|
||||
Icons.sell_outlined,
|
||||
color: Colors.white,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: _color,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
ElevatedButton(onPressed: (){
|
||||
Navigator.of(context).pop(_color);
|
||||
|
||||
}, child: Text('添加')),
|
||||
SizedBox(width: 12,),
|
||||
OutlinedButton(onPressed: (){
|
||||
Navigator.of(context).pop();
|
||||
}, child: Text('取消')),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: Text(text,style: TextStyle(color: _color,fontSize: 24,letterSpacing: 4),)),
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: 10),
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: Icon(
|
||||
Icons.sell_outlined,
|
||||
color: Colors.white,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: _color,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
ColorPicker(
|
||||
colorPickerWidth:200,
|
||||
// enableAlpha: false,
|
||||
displayThumbColor:true,
|
||||
pickerColor: _color,
|
||||
paletteType: PaletteType.hueWheel,
|
||||
onColorChanged: changeColor,
|
||||
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -64,4 +92,11 @@ class _ColorAddPageState extends State<ColorAddPage> {
|
||||
void _selectColor() {
|
||||
Navigator.of(context).pop(_color);
|
||||
}
|
||||
|
||||
void changeColor(Color value) {
|
||||
_color = value;
|
||||
setState(() {
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:iroute/common/components/colors_panel.dart';
|
||||
import 'package:iroute/common/pages/stl_color_page.dart';
|
||||
import '../../app/navigation/app_router_delegate.dart';
|
||||
|
||||
// class HomePage extends StatelessWidget {
|
||||
// const HomePage({super.key});
|
||||
//
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// body: const Center(child: Text('HomePage')));
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
class ColorPage extends StatefulWidget {
|
||||
const ColorPage({super.key});
|
||||
|
||||
@@ -45,11 +33,12 @@ class _ColorPageState extends State<ColorPage> {
|
||||
}
|
||||
|
||||
void _selectColor(Color color){
|
||||
// String value = color.value.toRadixString(16);
|
||||
String value = color.value.toRadixString(16);
|
||||
router.path = '/color/detail?color=$value';
|
||||
}
|
||||
|
||||
void _toAddPage() async {
|
||||
dynamic color = await router.changePathForResult('/color/add');
|
||||
Color? color = await router.changePathForResult('/color/add');
|
||||
if (color != null) {
|
||||
setState(() {
|
||||
_colors.add(color);
|
||||
|
||||
Reference in New Issue
Block a user