-
Notifications
You must be signed in to change notification settings - Fork 32
/
yaru_navigation_rail.dart
150 lines (136 loc) · 3.71 KB
/
yaru_navigation_rail.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import 'package:flutter/material.dart';
import '../../../yaru_widgets.dart';
class YaruNavigationRail extends StatelessWidget {
const YaruNavigationRail({
super.key,
required this.destinations,
required this.selectedIndex,
required this.onDestinationSelected,
this.showLabels = false,
this.extended = false,
});
// TODO: add comments
final List<YaruPageItem> destinations;
final int selectedIndex;
final ValueChanged<int> onDestinationSelected;
final bool showLabels;
final bool extended;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: Column(
children: <Widget>[
for (int i = 0; i < destinations.length; i += 1)
_YaruNavigationRailItem(
i,
i == selectedIndex,
destinations[i],
onDestinationSelected,
showLabels,
showLabels && extended,
)
],
),
);
}
}
class _YaruNavigationRailItem extends StatelessWidget {
const _YaruNavigationRailItem(
this.index,
this.selected,
this.destination,
this.onSelected,
this.showLabel,
this.extended,
);
final int index;
final bool selected;
final YaruPageItem destination;
final ValueChanged<int> onSelected;
final bool showLabel;
final bool extended;
@override
Widget build(BuildContext context) {
return SizedBox(
width: extended
? 250
: showLabel
? 85
: 60,
child: Material(
child: InkWell(
onTap: () => onSelected(index),
child: Center(
child: Padding(
padding: EdgeInsets.symmetric(
vertical: extended ? 10 : 5,
horizontal: extended ? 8 : 5,
),
child: _columnOrRow([
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: selected
? Theme.of(context)
.colorScheme
.onSurface
.withOpacity(.1)
: null,
),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 2,
horizontal: 10,
),
child: Icon(destination.iconData),
),
),
if (showLabel) ...[
_gap(),
_buildLabel(context),
]
]),
),
),
),
),
);
}
Widget _columnOrRow(List<Widget> children) {
const mainAxisAlignment = MainAxisAlignment.start;
if (extended) {
return Row(
mainAxisAlignment: mainAxisAlignment,
children: children,
);
}
return Column(
mainAxisAlignment: mainAxisAlignment,
children: children,
);
}
Widget _gap() {
if (extended) {
return const SizedBox(width: 10);
}
return const SizedBox(height: 5);
}
Widget _buildLabel(BuildContext context) {
var label = destination.titleBuilder(context);
if (label is YaruPageItemTitle) {
label = DefaultTextStyle.merge(
child: label,
style: TextStyle(
fontSize: extended ? 13 : 12,
fontWeight: FontWeight.w500,
),
overflow: TextOverflow.ellipsis,
softWrap: true,
textAlign: extended ? TextAlign.left : TextAlign.center,
maxLines: extended ? 1 : 3,
);
}
return extended ? Expanded(child: label) : label;
}
}