-
Notifications
You must be signed in to change notification settings - Fork 48
/
example_mobile.dart
205 lines (196 loc) · 5.95 KB
/
example_mobile.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import 'package:flutter/material.dart';
import 'package:sidebarx/sidebarx.dart';
void main() {
runApp(SidebarXExampleApp());
}
class SidebarXExampleApp extends StatelessWidget {
SidebarXExampleApp({Key? key}) : super(key: key);
final _controller = SidebarXController(selectedIndex: 0, extended: true);
final _scaffoldKey = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SidebarX Example',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: primaryColor,
canvasColor: canvasColor,
scaffoldBackgroundColor: scaffoldBackgroundColor,
textTheme: const TextTheme(
headlineSmall: TextStyle(
color: Colors.white,
fontSize: 46,
fontWeight: FontWeight.w800,
),
),
),
home: Scaffold(
key: _scaffoldKey,
drawer: SidebarX(
controller: _controller,
theme: SidebarXTheme(
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: canvasColor,
borderRadius: BorderRadius.circular(20),
),
textStyle: const TextStyle(color: Colors.white),
selectedTextStyle: const TextStyle(color: Colors.white),
itemTextPadding: const EdgeInsets.only(left: 30),
selectedItemTextPadding: const EdgeInsets.only(left: 30),
itemDecoration: BoxDecoration(
border: Border.all(color: canvasColor),
),
selectedItemDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: actionColor.withOpacity(0.37),
),
gradient: const LinearGradient(
colors: [accentCanvasColor, canvasColor],
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.28),
blurRadius: 30,
)
],
),
iconTheme: const IconThemeData(
color: Colors.white,
size: 20,
),
),
extendedTheme: const SidebarXTheme(
width: 200,
decoration: BoxDecoration(
color: canvasColor,
),
margin: EdgeInsets.only(right: 10),
),
footerDivider: divider,
headerBuilder: (context, extended) {
return SafeArea(
child: SizedBox(
height: 100,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Image.asset('assets/images/avatar.png'),
),
),
);
},
items: [
SidebarXItem(
icon: Icons.home,
label: 'Home',
onTap: () {
debugPrint('Hello');
},
),
const SidebarXItem(
icon: Icons.search,
label: 'Search',
),
const SidebarXItem(
icon: Icons.people,
label: 'People',
),
const SidebarXItem(
icon: Icons.favorite,
label: 'Favorites',
),
],
),
appBar: AppBar(
backgroundColor: canvasColor,
title: const Text('SidebarX'),
leading: IconButton(
onPressed: () {
_scaffoldKey.currentState?.openDrawer();
},
icon: const Icon(Icons.menu_rounded),
),
),
body: Row(
children: [
Expanded(
child: Center(
child: _ScreensExample(controller: _controller),
),
),
],
),
),
);
}
}
class _ScreensExample extends StatelessWidget {
const _ScreensExample({
Key? key,
required this.controller,
}) : super(key: key);
final SidebarXController controller;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return AnimatedBuilder(
animation: controller,
builder: (context, child) {
switch (controller.selectedIndex) {
case 0:
return ListView.builder(
padding: const EdgeInsets.only(top: 10),
itemBuilder: (context, index) => Container(
height: 100,
width: double.infinity,
margin: const EdgeInsets.only(bottom: 10, right: 10, left: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Theme.of(context).canvasColor,
boxShadow: const [BoxShadow()],
),
),
);
case 1:
return Text(
'Search',
style: theme.textTheme.headlineSmall,
);
case 2:
return Text(
'People',
style: theme.textTheme.headlineSmall,
);
case 3:
return Text(
'Favorites',
style: theme.textTheme.headlineSmall,
);
case 4:
return Text(
'Profile',
style: theme.textTheme.headlineSmall,
);
case 5:
return Text(
'Settings',
style: theme.textTheme.headlineSmall,
);
default:
return Text(
'Not found page',
style: theme.textTheme.headlineSmall,
);
}
},
);
}
}
const primaryColor = Color(0xFF685BFF);
const canvasColor = Color(0xFF2E2E48);
const scaffoldBackgroundColor = Color(0xFF464667);
const accentCanvasColor = Color(0xFF3E3E61);
const white = Colors.white;
const actionColor = Color(0xFF5F5FA7);
final divider = Divider(color: white.withOpacity(0.3), height: 1);