-
Notifications
You must be signed in to change notification settings - Fork 9
/
brands_navigation_rail.dart
233 lines (223 loc) · 7.67 KB
/
brands_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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import 'package:ECommerceApp/provider/products.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'brands_rail_widget.dart';
class BrandNavigationRailScreen extends StatefulWidget {
BrandNavigationRailScreen({Key key}) : super(key: key);
static const routeName = '/brands_navigation_rail';
@override
_BrandNavigationRailScreenState createState() =>
_BrandNavigationRailScreenState();
}
class _BrandNavigationRailScreenState extends State<BrandNavigationRailScreen> {
int _selectedIndex = 0;
final padding = 8.0;
String routeArgs;
String brand;
@override
void didChangeDependencies() {
routeArgs = ModalRoute.of(context).settings.arguments.toString();
_selectedIndex = int.parse(
routeArgs.substring(1, 2),
);
print(routeArgs.toString());
if (_selectedIndex == 0) {
setState(() {
brand = 'Addidas';
});
}
if (_selectedIndex == 1) {
setState(() {
brand = 'Apple';
});
}
if (_selectedIndex == 2) {
setState(() {
brand = 'Dell';
});
}
if (_selectedIndex == 3) {
setState(() {
brand = 'H&M';
});
}
if (_selectedIndex == 4) {
setState(() {
brand = 'Nike';
});
}
if (_selectedIndex == 5) {
setState(() {
brand = 'Samsung';
});
}
if (_selectedIndex == 6) {
setState(() {
brand = 'Huawei';
});
}
if (_selectedIndex == 7) {
setState(() {
brand = 'All';
});
}
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Row(
children: <Widget>[
LayoutBuilder(
builder: (context, constraint) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: constraint.maxHeight),
child: IntrinsicHeight(
child: NavigationRail(
minWidth: 56.0,
groupAlignment: 1.0,
selectedIndex: _selectedIndex,
onDestinationSelected: (int index) {
setState(() {
_selectedIndex = index;
if (_selectedIndex == 0) {
setState(() {
brand = 'Addidas';
});
}
if (_selectedIndex == 1) {
setState(() {
brand = 'Apple';
});
}
if (_selectedIndex == 2) {
setState(() {
brand = 'Dell';
});
}
if (_selectedIndex == 3) {
setState(() {
brand = 'H&M';
});
}
if (_selectedIndex == 4) {
setState(() {
brand = 'Nike';
});
}
if (_selectedIndex == 5) {
setState(() {
brand = 'Samsung';
});
}
if (_selectedIndex == 6) {
setState(() {
brand = 'Huawei';
});
}
if (_selectedIndex == 7) {
setState(() {
brand = 'All';
});
}
print(brand);
});
},
labelType: NavigationRailLabelType.all,
leading: Column(
children: <Widget>[
SizedBox(
height: 20,
),
Center(
child: CircleAvatar(
radius: 16,
backgroundImage: NetworkImage(
"https://cdn1.vectorstock.com/i/thumb-large/62/60/default-avatar-photo-placeholder-profile-image-vector-21666260.jpg"),
),
),
SizedBox(
height: 80,
),
],
),
selectedLabelTextStyle: TextStyle(
color: Color(0xffffe6bc97),
fontSize: 20,
letterSpacing: 1,
decoration: TextDecoration.underline,
decorationThickness: 2.5,
),
unselectedLabelTextStyle: TextStyle(
fontSize: 15,
letterSpacing: 0.8,
),
destinations: [
buildRotatedTextRailDestination('Addidas', padding),
buildRotatedTextRailDestination("Apple", padding),
buildRotatedTextRailDestination("Dell", padding),
buildRotatedTextRailDestination("H&M", padding),
buildRotatedTextRailDestination("Nike", padding),
buildRotatedTextRailDestination("Samsung", padding),
buildRotatedTextRailDestination("Huawei", padding),
buildRotatedTextRailDestination("All", padding),
],
),
),
),
);
},
),
// This is the main content.
ContentSpace(context, brand)
],
),
);
}
}
NavigationRailDestination buildRotatedTextRailDestination(
String text, double padding) {
return NavigationRailDestination(
icon: SizedBox.shrink(),
label: Padding(
padding: EdgeInsets.symmetric(vertical: padding),
child: RotatedBox(
quarterTurns: -1,
child: Text(text),
),
),
);
}
class ContentSpace extends StatelessWidget {
// final int _selectedIndex;
final String brand;
ContentSpace(BuildContext context, this.brand);
@override
Widget build(BuildContext context) {
final productsData = Provider.of<Products>(context, listen: false);
final productsBrand = productsData.findByBrand(brand);
if(brand=='All'){
for(int i=0; i<productsData.products.length;i++){
productsBrand.add(productsData.products[i]);
}
}
print('productsBrand ${productsBrand[0].imageUrl}');
print('brand $brand');
return Expanded(
child: Padding(
padding: const EdgeInsets.fromLTRB(24, 8, 0, 0),
child: MediaQuery.removePadding(
removeTop: true,
context: context,
child: ListView.builder(
itemCount: productsBrand.length,
itemBuilder: (BuildContext context, int index) =>
ChangeNotifierProvider.value(
value: productsBrand[index], child: BrandsNavigationRail()),
),
),
),
);
}
}