shiburagi / Drawer-Behavior-Flutter

Drawer behavior is a library that provide an extra behavior on drawer, such as, move view or scaling view's height while drawer on slide.
MIT License
209 stars 36 forks source link

is it possible to add divider between menuitems? #12

Closed legacyO7 closed 3 years ago

legacyO7 commented 4 years ago

is it possible to add divider between menuitems?

vaibhavrock commented 4 years ago

Yes, You can use custom widget with upgraded version (i.e. drawerbehavior: ^1.0.3).

Code will be looks like:

    return new DrawerScaffold(
        appBar: AppBar(),
        drawers: [
          SideDrawer(
            itemBuilder: (BuildContext context, MenuItem menuItem, bool isSelected) {
              return Column(
                children: [
                  Container(
                   // color: isSelected? getThemeColor().withOpacity(0.7): Colors.transparent,
                    padding: EdgeInsets.fromLTRB(24, 16, 24, 16),
                    child: Text(
                      menuItem.title,
                      style: Theme.of(context).textTheme.subtitle1.copyWith(
                          color: isSelected ?  Colors.white  : Colors.red,
                          fontWeight: FontWeight.bold,
                          fontSize: 16
                      ),
                     // style: TextStyle(color: isSelected ? Colors.white  : Colors.red, fontSize: 18),

                    ),
                  ),
                  (menuItem.id != 9) ? Divider(height: 2, color: Colors.white) : Container(),
                ],
              );
            },
            degree: null,
            elevation: 0.0,
            percentage: 1,
            cornerRadius: 0,
            menu: menu,
            direction: Direction.left,
            animation: false,
            alignment: Alignment.topLeft,
            color: getThemeColor(),
            selectorColor: Colors.white,
            selectedItemId: selectedMenuItemId,
            onMenuItemSelected: (itemId) {
              setState(() {
                selectedMenuItemId = itemId;
              });

              // Do whatever you want

              if (itemId == 1) {
                //Navigator.pushReplacementNamed(context, "/login");
              }
              else if(itemId == 2){
              }             
              else{
             }

            },
          )
        ],
      builder: (context, constraint) =>  HomeView(),

I hope this will help you.

Azzeccagarbugli commented 4 years ago

Yes, You can use custom widget with upgraded version (i.e. drawerbehavior: ^1.0.3).

Code will be looks like:

    return new DrawerScaffold(
        appBar: AppBar(),
        drawers: [
          SideDrawer(
            itemBuilder: (BuildContext context, MenuItem menuItem, bool isSelected) {
              return Column(
                children: [
                  Container(
                   // color: isSelected? getThemeColor().withOpacity(0.7): Colors.transparent,
                    padding: EdgeInsets.fromLTRB(24, 16, 24, 16),
                    child: Text(
                      menuItem.title,
                      style: Theme.of(context).textTheme.subtitle1.copyWith(
                          color: isSelected ?  Colors.white  : Colors.red,
                          fontWeight: FontWeight.bold,
                          fontSize: 16
                      ),
                     // style: TextStyle(color: isSelected ? Colors.white  : Colors.red, fontSize: 18),

                    ),
                  ),
                  (menuItem.id != 9) ? Divider(height: 2, color: Colors.white) : Container(),
                ],
              );
            },
            degree: null,
            elevation: 0.0,
            percentage: 1,
            cornerRadius: 0,
            menu: menu,
            direction: Direction.left,
            animation: false,
            alignment: Alignment.topLeft,
            color: getThemeColor(),
            selectorColor: Colors.white,
            selectedItemId: selectedMenuItemId,
            onMenuItemSelected: (itemId) {
              setState(() {
                selectedMenuItemId = itemId;
              });

              // Do whatever you want

              if (itemId == 1) {
                //Navigator.pushReplacementNamed(context, "/login");
              }
              else if(itemId == 2){
              }             
              else{
             }

            },
          )
        ],
      builder: (context, constraint) =>  HomeView(),

I hope this will help you.

This is giving me the following issue:

The following _TypeError was thrown building DrawerScaffoldMenuController(dirty, state: DrawerScaffoldMenuControllerState#20194):
type 'InkWell' is not a subtype of type '_MenuListItem'

I really can't understand why I got this problem

vaibhavrock commented 3 years ago

@Azzeccagarbugli As I'm seeing with your log, this issue occurs due to 'InkWell' widget. please check it.