Skip to content

Commit 761c026

Browse files
committed
update navigation by tolyui
1 parent e43cc9f commit 761c026

File tree

9 files changed

+249
-464
lines changed

9 files changed

+249
-464
lines changed
Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import 'package:app/app.dart';
22
import 'package:flutter/material.dart';
3-
import 'package:flutter_unit/navigation/menus/menu_meta.dart';
43
import 'package:go_router/go_router.dart';
54
import 'package:l10n/l10n.dart';
6-
import 'unit_rail_navigation.dart';
7-
5+
import 'package:tolyui_navigation/tolyui_navigation.dart';
6+
import 'menu_bar_leading.dart';
7+
import 'menu_bar_tail.dart';
8+
import 'toly_unit_menu_cell.dart';
89
class FlutterUnitDeskNavigation extends StatelessWidget {
910
final Widget content;
11+
1012
const FlutterUnitDeskNavigation({super.key, required this.content});
1113

1214
@override
1315
Widget build(BuildContext context) {
1416
return Scaffold(
1517
body: Row(
1618
children: [
17-
DeskNavigationRail(),
19+
const DragToMoveAreaNoDouble(child: DeskNavigationRail()),
1820
Expanded(child: content),
1921
],
2022
),
2123
);
2224
}
23-
24-
2525
}
2626

2727
class DeskNavigationRail extends StatefulWidget {
@@ -32,12 +32,21 @@ class DeskNavigationRail extends StatefulWidget {
3232
}
3333

3434
class _DeskNavigationRailState extends State<DeskNavigationRail> {
35+
3536
@override
3637
Widget build(BuildContext context) {
37-
return UnitRailNavigation(
38-
selectedIndex: activeIndex,
39-
onAction: _onAction,
40-
itemData: deskNavBarMenus,
38+
return TolyRailMenuBar(
39+
cellBuilder: FlutterUnitMenuCell.create,
40+
width: 130,
41+
gap: 8,
42+
padding: EdgeInsets.zero,
43+
backgroundColor: const Color(0xff2C3036),
44+
menus: deskNavBarMenus,
45+
activeId: activePath,
46+
enableWidthChange: false,
47+
onSelected: context.go,
48+
tail: (_) => const MenuBarTail(),
49+
leading: (_) => const MenuBarLeading(),
4150
);
4251
}
4352

@@ -52,36 +61,22 @@ class _DeskNavigationRailState extends State<DeskNavigationRail> {
5261
String treasure = context.l10n.treasureTools;
5362
String account = context.l10n.homeAccount;
5463

55-
deskNavBarMenus = [
56-
MenuMeta(label: widget, icon: TolyIcon.icon_layout, path: '/widget'),
57-
MenuMeta(label: canvas, icon: Icons.palette, path: '/painter'),
58-
MenuMeta(label: knowledge, icon: TolyIcon.icon_artifact, path: '/knowledge'),
59-
MenuMeta(label: treasure, icon: TolyIcon.icon_fast, path: '/tools'),
60-
MenuMeta(label: account, icon: Icons.person, path: '/account'),
64+
deskNavBarMenus = [
65+
MenuMeta(label: widget, icon: TolyIcon.icon_layout, router: '/widget'),
66+
MenuMeta(label: canvas, icon: Icons.palette, router: '/painter'),
67+
MenuMeta(label: knowledge, icon: TolyIcon.icon_artifact, router: '/knowledge'),
68+
MenuMeta(label: treasure, icon: TolyIcon.icon_fast, router: '/tools'),
69+
MenuMeta(label: account, icon: Icons.person, router: '/account'),
6170
];
6271
}
63-
72+
6473
final RegExp _segReg = RegExp(r'/\w+');
6574

66-
int? get activeIndex {
75+
String? get activePath {
6776
final String path = GoRouterState.of(context).uri.toString();
6877
RegExpMatch? match = _segReg.firstMatch(path);
6978
if (match == null) return null;
7079
String? target = match.group(0);
71-
72-
int index = deskNavBarMenus.indexWhere((menu) => menu.path!.contains(target??''));
73-
if (index == -1) return null;
74-
return index;
75-
}
76-
77-
void _onAction(ActionType value) {
78-
String? path = value.path;
79-
if(path!=null){
80-
if(value == ActionType.settings || value == ActionType.collection){
81-
context.push(path);
82-
}else{
83-
context.go(path);
84-
}
85-
}
80+
return target;
8681
}
8782
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2014 The 张风捷特烈 . All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Author: 张风捷特烈
6+
// CreateTime: 2024-05-13
7+
// Contact Me: [email protected]
8+
9+
import 'package:app/app.dart';
10+
import 'package:flutter/material.dart';
11+
import 'package:toly_ui/toly_ui.dart';
12+
import 'package:url_launcher/url_launcher.dart';
13+
14+
class MenuBarLeading extends StatelessWidget {
15+
const MenuBarLeading({super.key});
16+
17+
@override
18+
Widget build(BuildContext context) {
19+
return Padding(
20+
padding: const EdgeInsets.only(top: 20,bottom: 20),
21+
child: Column(
22+
children: [
23+
const Wrap(
24+
direction: Axis.vertical,
25+
spacing: 10,
26+
crossAxisAlignment: WrapCrossAlignment.center,
27+
children: [
28+
CircleImage(
29+
image: AssetImage('assets/images/icon_head.webp'),
30+
size: 60,
31+
),
32+
Text(
33+
'张风捷特烈',
34+
style: TextStyle(color: Colors.white70),
35+
)
36+
],
37+
),
38+
_buildIcons(),
39+
const Divider(
40+
color: Colors.white,
41+
height: 1,
42+
endIndent: 20,
43+
),
44+
const SizedBox(height: 16,),
45+
],
46+
),
47+
);
48+
}
49+
50+
Widget _buildIcons() {
51+
return Padding(
52+
padding: const EdgeInsets.only(bottom: 16, top: 16),
53+
child: Wrap(
54+
spacing: 8,
55+
children: [
56+
FeedbackWidget(
57+
onPressed: () =>
58+
_launchURL("https://github.com/toly1994328/FlutterUnit"),
59+
child: const Icon(
60+
TolyIcon.icon_github,
61+
color: Colors.white,
62+
),
63+
),
64+
FeedbackWidget(
65+
onPressed: () =>
66+
_launchURL("https://juejin.im/user/5b42c0656fb9a04fe727eb37"),
67+
child: const Icon(
68+
TolyIcon.icon_juejin,
69+
color: Colors.white,
70+
),
71+
),
72+
FeedbackWidget(
73+
onPressed: () => _launchURL("http://blog.toly1994.com"),
74+
child: const Icon(
75+
TolyIcon.icon_item,
76+
color: Colors.white,
77+
),
78+
),
79+
],
80+
),
81+
);
82+
}
83+
84+
void _launchURL(String url) async {
85+
if (!await launchUrl(Uri.parse(url))) {
86+
// throw Exception('Could not launch $url');
87+
}
88+
}
89+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2014 The 张风捷特烈 . All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Author: 张风捷特烈
6+
// CreateTime: 2024-05-13
7+
// Contact Me: [email protected]
8+
9+
import 'package:app/app.dart';
10+
import 'package:flutter/material.dart';
11+
import 'package:go_router/go_router.dart';
12+
import 'package:toly_ui/toly_ui.dart';
13+
14+
import 'theme_model_switch_icon.dart';
15+
16+
enum ActionType{
17+
settings(path: '/settings'),
18+
collection(path: '/collection');
19+
final String path;
20+
const ActionType({required this.path});
21+
}
22+
23+
class MenuBarTail extends StatelessWidget {
24+
const MenuBarTail({super.key});
25+
26+
@override
27+
Widget build(BuildContext context) {
28+
return Column(
29+
children: [
30+
const Divider(indent: 20, color: Colors.white, height: 1),
31+
Wrap(
32+
spacing: 12,
33+
children: [
34+
FeedbackWidget(
35+
onPressed: () {
36+
context.push(ActionType.settings.path);
37+
},
38+
child: const Padding(
39+
padding: EdgeInsets.only(bottom: 16, top: 16),
40+
child: Icon(
41+
Icons.settings,
42+
color: Colors.white,
43+
),
44+
),
45+
),
46+
FeedbackWidget(
47+
onPressed: () => context.push(ActionType.collection.path),
48+
child: const Padding(
49+
padding: EdgeInsets.only(bottom: 16, top: 16),
50+
child: Icon(
51+
TolyIcon.icon_collect,
52+
color: Colors.white,
53+
),
54+
),
55+
),
56+
const ThemeModelSwitchIcon(),
57+
],
58+
),
59+
],
60+
);
61+
}
62+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2014 The 张风捷特烈 . All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Author: 张风捷特烈
6+
// CreateTime: 2024-05-13
7+
// Contact Me: [email protected]
8+
9+
import 'package:flutter/material.dart';
10+
import 'package:tolyui_navigation/tolyui_navigation.dart';
11+
12+
final Tween<double> _widthTween = Tween(begin: 0.82, end: 0.95);
13+
final Tween<double> _sizeTween = Tween(begin: 18.0, end: 22.0);
14+
final Tween<double> _fontSizeTween = Tween(begin: 14.0, end: 15);
15+
16+
class FlutterUnitMenuCell extends StatelessWidget {
17+
final MenuMeta menu;
18+
final DisplayMeta display;
19+
20+
const FlutterUnitMenuCell.create(this.menu, this.display, {super.key});
21+
22+
Color? get foregroundColor => display.selected ? Colors.white : Colors.white70;
23+
24+
@override
25+
Widget build(BuildContext context) {
26+
double height = 42;
27+
28+
double anim = display.rate;
29+
Color? color = ColorTween(
30+
begin: Colors.white.withAlpha(33),
31+
end: Theme.of(context).primaryColor)
32+
.transform(anim);
33+
34+
double iconSize = _sizeTween.transform(anim);
35+
double fontSize = _fontSizeTween.transform(anim);
36+
37+
TextStyle style = TextStyle(color: foregroundColor, fontSize: fontSize);
38+
Radius radius = Radius.circular(height / 2);
39+
BorderRadius br = BorderRadius.only(topRight: radius, bottomRight: radius);
40+
41+
return Align(
42+
alignment: Alignment.centerLeft,
43+
child: Container(
44+
alignment: Alignment.center,
45+
decoration: BoxDecoration(color: color, borderRadius: br),
46+
width: _widthTween.transform(anim) * 130,
47+
height: height,
48+
child: Wrap(
49+
spacing: 6,
50+
crossAxisAlignment: WrapCrossAlignment.center,
51+
children: [
52+
Icon(menu.icon, color: foregroundColor, size: iconSize),
53+
Text(menu.label, style: style),
54+
],
55+
),
56+
),
57+
);
58+
}
59+
}

0 commit comments

Comments
 (0)