Jamalianpour / easy_sidemenu

An easy to use side menu (navigation rail) in flutter and can used for navigations
https://pub.dev/packages/easy_sidemenu
MIT License
145 stars 70 forks source link

Side menu not showing after logout until i hot restart #46

Closed shameel-zeepalm closed 1 year ago

shameel-zeepalm commented 1 year ago

Can you please help me with fixing this issue . Here is my code

import 'package:alert_web_application/app/data/constants/constants.dart'; import 'package:alert_web_application/app/modules/controllers/admin_controller.dart'; import 'package:alert_web_application/app/modules/views/dashboard/locations_screen.dart'; import 'package:alert_web_application/app/services/translation_services.dart'; import 'package:easy_sidemenu/easy_sidemenu.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart';

import '../../widgets/dialogs/logout_dialog.dart'; import '../profile/profile.dart'; import '../settings/settings.dart'; import 'dashboard_screen.dart';

class LandingPage extends StatefulWidget { const LandingPage({Key? key}) : super(key: key);

@override _LandingPageState createState() => _LandingPageState(); }

class _LandingPageState extends State { PageController page = PageController(); SideMenuController sideMenu = SideMenuController(); @override void initState() { sideMenu.addListener((p0) { page.jumpToPage(p0); }); super.initState(); }

@override Widget build(BuildContext context) { return GetBuilder( init: AdminController(), builder: (controller) { return Scaffold( appBar: AppBar( elevation: 0, automaticallyImplyLeading: false, // actions: [ // // Center( // // child: Text(AppTexts.admin, // // style: CustomTextStyles.kMedium16 // // .copyWith(color: CustomColors.kBlack))), // // SizedBox(width: 20.w), // // CircleAvatar(backgroundImage: AssetImage(CustomAssets.kUser)), // // SizedBox(width: 20.w), // ], ), body: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ SideMenu( controller: sideMenu, style: SideMenuStyle( displayMode: SideMenuDisplayMode.auto, hoverColor: CustomColors.kPrimary.withOpacity(0.5), selectedColor: CustomColors.kPrimary, selectedTitleTextStyle: CustomTextStyles.kMedium16 .copyWith(color: CustomColors.kWhite), unselectedTitleTextStyle: CustomTextStyles.kMedium16 .copyWith(color: CustomColors.kBlack), selectedIconColor: Colors.white, ), items: [ SideMenuItem( priority: 0, title: AppTexts.dashboard, iconWidget: SvgPicture.asset(CustomAssets.kMDashboardIcon), onTap: (page, ) { sideMenu.changePage(page); }, icon: const Icon(Icons.home), ), SideMenuItem( priority: 1, title: AppTexts.myProfile, onTap: (page, ) { sideMenu.changePage(page); }, icon: const Icon(Icons.supervisoraccount), ), SideMenuItem( priority: 2, title: AppTexts.settings, onTap: (page, ) { sideMenu.changePage(page); }, icon: const Icon(Icons.settings), ), SideMenuItem( priority: 3, title: "Locations", onTap: (page, _) { sideMenu.changePage(page); }, icon: const Icon(Icons.pin_drop), ), SideMenuItem( priority: 7, title: AppTexts.logout, icon: const Icon(Icons.exit_toapp), onTap: (page, ) { Get.dialog(const LogoutDialog()); }, ), ], ), Expanded( child: PageView( controller: page, children: [ DashboardScreen(), ProfileView(), const Settings(), LocationsView() ], ), ), ], ), ); }); } }

unvestigate commented 1 year ago

I can confirm that I have similar issues after updating from version 0.4.1 to 0.4.1+1. My app goes through a login screen to the main screen which features a side menu. When I enter the app the first time everything works fine, but if I go back to the login screen and log in again, the side menu isn't showing until I resize the window to small enough that the menu switches to compact mode.

More troubling though, is that clicking on any item in the menu (after having it re-appear) I get "setState() called after dispose()" errors, much like the ones described in: https://github.com/Jamalianpour/easy_sidemenu/issues/45. Also check the recent comments in https://github.com/Jamalianpour/easy_sidemenu/issues/31. I am experiencing very similar things. With version 0.4.1 everything worked fine.

shameel-zeepalm commented 1 year ago

I can confirm that I have similar issues after updating from version 0.4.1 to 0.4.1+1. My app goes through a login screen to the main screen which features a side menu. When I enter the app the first time everything works fine, but if I go back to the login screen and log in again, the side menu isn't showing until I resize the window to small enough that the menu switches to compact mode.

More troubling though, is that clicking on any item in the menu (after having it re-appear) I get "setState() called after dispose()" errors, much like the ones described in: #45. Also check the recent comments in #31. I am experiencing very similar things. With version 0.4.1 everything worked fine.

I can confirm that I have similar issues after updating from version 0.4.1 to 0.4.1+1. My app goes through a login screen to the main screen which features a side menu. When I enter the app the first time everything works fine, but if I go back to the login screen and log in again, the side menu isn't showing until I resize the window to small enough that the menu switches to compact mode.

More troubling though, is that clicking on any item in the menu (after having it re-appear) I get "setState() called after dispose()" errors, much like the ones described in: #45. Also check the recent comments in #31. I am experiencing very similar things. With version 0.4.1 everything worked fine.

Still Facining the same issue after changing version to 0.4.1

WalleGang commented 1 year ago

Same problem here!! on Android/iOS/Windows 😭

Jamalianpour commented 1 year ago

I really don't know why this bug happen But you can call this in initState :

@override
void initState() {
  super.initState();
  Future.delayed(const Duration(milliseconds: 50), () {
    setState(() {
      displayMode = SideMenuDisplayMode.compact;
    });
  });
  Future.delayed(const Duration(milliseconds: 100), () {
    setState(() {
      displayMode = SideMenuDisplayMode.open;
    });
  });
}
nikohpng commented 1 year ago

same issue

rojicp commented 1 year ago

same issue still

victor7w7r commented 1 year ago

Same here

badru254 commented 1 year ago

I have a workaround for this,but it only works as per my specific requirements if you are using it on a larger screen like pc and the side nav is set to be constantly open. Wrap the SideMenu widget in a Container of the same width as the openSideMenuWidth and height same as the device height. ... Container( color: Colors.black, height: Get.height, width: 200, child: SideMenu( ... UPDATE Only works with MediaQuery.of(context).size.height

verrelravanelli commented 1 year ago

I have a workaround for this,but it only works as per my specific requirements if you are using it on a larger screen like pc and the side nav is set to be constantly open. Wrap the SideMenu widget in a Container of the same width as the openSideMenuWidth and height same as the device height. ... Container( color: Colors.black, height: Get.height, width: 200, child: SideMenu( ... UPDATE Only works with MediaQuery.of(context).size.height

this solution work for me, thanks. I just add some change in the container width to MediaQuery.of(context).size.width > (your side menu collapse width) ? openSideMenuWidth : 50. This work if you dont want the side nav to be constantly open for smaller screen and in my case i set the displayMode to SideMenuDisplayMode.auto

rodrigomb81 commented 1 year ago

I'm on version 0.4.1. From what I've seen the bug is caused by _SideMenuState._widthSize. The second time it's called with mode compact it returns 0 because Global.displayModeState.value has not changed, and returning the correct width is tied up to that value changing.

The problem is on line 129.

Here's a quick and dirty fix. Replace the if that begins on that line with:

if (mode == SideMenuDisplayMode.compact) {
  if (Global.displayModeState.value != SideMenuDisplayMode.compact) {
    Global.displayModeState.change(SideMenuDisplayMode.compact);
    _notifyParent();
    Global.showTrailing = false;
  }

  return Global.style.compactSideMenuWidth ?? 50;
}

In this version I've separated calculating the size and notifying the parent. This way if the mode == compact then we always return the appropriate width, and only notify if necessary.

I'll try to make a PR soonish!

EDIT: here's the PR

Coder-Manuel commented 1 year ago

This issue is still persistent even on latest version v0.5.0 I've managed to come-up with a fix that should be atleast permanent, I followed pointers from @rodrigomb81 ..

The code in the if statements when in auto mode aren't being fired the 2nd time. This is because the displayModeState is set to open (atleast with my use case), hence the _widthSize() returns 0;

Here is the updated code that's working perfectly on my end.

 if (mode == SideMenuDisplayMode.auto) {
      if (MediaQuery.of(context).size.width > collapseWidth) {
        if (Global.displayModeState.value != SideMenuDisplayMode.open) {
          Global.displayModeState.change(SideMenuDisplayMode.open);
          _notifyParent();
          Future.delayed(_toggleDuration(), () {
            Global.showTrailing = true;
            for (var update in Global.itemsUpdate) {
              update();
            }
          });
        }
        return Global.style.openSideMenuWidth ?? 300; // Have the return statement outside the 2nd condition.
      }
      if (MediaQuery.sizeOf(context).width <= collapseWidth) {
        if (Global.displayModeState.value != SideMenuDisplayMode.compact) {
          Global.displayModeState.change(SideMenuDisplayMode.compact);
          _notifyParent();
          Global.showTrailing = false;
        }

        return Global.style.compactSideMenuWidth ?? 50; // Have the return statement outside the 2nd condition.
      }
      return _currentWidth;
    } // .... rest of code

PR: Fix width issue

aditya113141 commented 1 year ago

@Coder-Manuel 's PR involves fix in auto mode only. I have updated the code for open and compact mode too : - PR Link

double _widthSize(SideMenuDisplayMode mode, BuildContext context) {

    if (mode == SideMenuDisplayMode.auto) {
      // Rest of the code
    }
    else if(mode == SideMenuDisplayMode.open){

      if(Global.displayModeState.value != SideMenuDisplayMode.open){
        Global.displayModeState.change(SideMenuDisplayMode.open);
        _notifyParent();
        Future.delayed(_toggleDuration(), () {
          Global.showTrailing = true;
          for (var update in Global.itemsUpdate) {
            update();
          }
        });
      }
      return Global.style.openSideMenuWidth ?? 300;
    } 
    else if (mode == SideMenuDisplayMode.compact) {
      if (Global.displayModeState.value != SideMenuDisplayMode.compact) {
        Global.displayModeState.change(SideMenuDisplayMode.compact);
        _notifyParent();
        Global.showTrailing = false;
      }

      return Global.style.compactSideMenuWidth ?? 50;
    }

    return _currentWidth;

  }