@@ -7,6 +7,7 @@ import '../../../../models/role.dart';
77import '../../../../services/auth_service.dart' ;
88
99import '../../../../models/screens.dart' ;
10+ import '../controllers/my_drawer_controller.dart' ;
1011
1112class DrawerWidget extends StatelessWidget {
1213 const DrawerWidget ({
@@ -15,20 +16,23 @@ class DrawerWidget extends StatelessWidget {
1516
1617 @override
1718 Widget build (BuildContext context) {
18- return Drawer (
19- //changing the shape of the drawer
20- shape: const RoundedRectangleBorder (
21- borderRadius: BorderRadius .only (
22- topRight: Radius .circular (0 ), bottomRight: Radius .circular (20 )),
23- ),
24- width: 200 ,
25- child: Column (
26- children: drawerItems (context),
27- ),
28- );
19+ MyDrawerController controller = Get .put (MyDrawerController ([]),
20+ permanent: true ); //must make true else gives error
21+ Screen .drawer ().then ((v) => {controller.values.value = v});
22+ return Obx (() => Drawer (
23+ //changing the shape of the drawer
24+ shape: const RoundedRectangleBorder (
25+ borderRadius: BorderRadius .only (
26+ topRight: Radius .circular (0 ), bottomRight: Radius .circular (20 )),
27+ ),
28+ width: 200 ,
29+ child: Column (
30+ children: drawerItems (context, controller.values),
31+ ),
32+ ));
2933 }
3034
31- List <Widget > drawerItems (BuildContext context) {
35+ List <Widget > drawerItems (BuildContext context, Rx < Iterable < Screen >> values ) {
3236 List <Widget > list = [
3337 Container (
3438 height: 100 ,
@@ -43,34 +47,38 @@ class DrawerWidget extends StatelessWidget {
4347 )
4448 ];
4549
46- for (var i = 0 ; i <= AuthService .to.maxRole.index; i++ ) {
47- Role role = Role .values[i];
48- list.add (ListTile (
49- title: Text (
50- role.name,
51- style: const TextStyle (
52- color: Colors .blue,
50+ if (AuthService .to.maxRole.index > 1 ) {
51+ for (var i = 0 ; i <= AuthService .to.maxRole.index; i++ ) {
52+ Role role = Role .values[i];
53+ list.add (ListTile (
54+ title: Text (
55+ role.name,
56+ style: const TextStyle (
57+ color: Colors .blue,
58+ ),
5359 ),
54- ),
60+ onTap: () {
61+ Get .rootDelegate
62+ .toNamed (Screen .HOME .route, arguments: {'role' : role});
63+ //to close the drawer
64+ Navigator .of (context).pop ();
65+ },
66+ ));
67+ }
68+ }
69+
70+ for (Screen screen in values.value) {
71+ list.add (ListTile (
72+ title: Text (screen.label ?? '' ),
5573 onTap: () {
56- Get .rootDelegate
57- .toNamed (Screen .HOME .route, arguments: {'role' : role});
74+ Get .rootDelegate.toNamed (screen.route);
5875 //to close the drawer
76+
5977 Navigator .of (context).pop ();
6078 },
6179 ));
6280 }
6381
64- Screen .drawer ().forEach ((Screen screen) => list.add (ListTile (
65- title: Text (screen.label ?? '' ),
66- onTap: () {
67- Get .rootDelegate.toNamed (screen.route);
68- //to close the drawer
69-
70- Navigator .of (context).pop ();
71- },
72- )));
73-
7482 if (AuthService .to.isLoggedInValue) {
7583 list.add (ListTile (
7684 title: const Text (
0 commit comments