Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Every time menu item is clicked, screen is loaded again. How to solve this? #1

Open
Arpit-Awasthi-dev opened this issue Feb 21, 2021 · 5 comments

Comments

@Arpit-Awasthi-dev
Copy link

No description provided.

@salkuadrat
Copy link
Owner

salkuadrat commented May 19, 2021

I'm sure it depends on the onTap implementation on your project.

In example project, you can do it by checking first if the type is changed or still the same, such as here.

By checking first using:

if(this.type != type)

It will make sure the content will only be reload when the type changed.

On normal application, we don't even need to use _appKey, since we don't have to refresh the application to see the theme changes. So we can set onTap by directly navigate to the intended page.

@Arpit-Awasthi-dev
Copy link
Author

"It will make sure the content will only be reload when the type changed."
But I don't want to reload screen in any case, then how can we achieve this.

@salkuadrat
Copy link
Owner

salkuadrat commented May 19, 2021

Ok. First thing, this example needs reload because it needs to show many ways to use this drawer.

In normal application, we usually stick with one theme. So you don't need to copy the example as it is.
Mostly the menu item will click to navigate to other page, which you can do by calling Navigator.

@salkuadrat
Copy link
Owner

salkuadrat commented May 19, 2021

So, in normal application, the menu item will be like:

MenuItem('Basic', 
  icon: Icons.rss_feed,
  onTap: () => Navigator.push(context,
    MaterialPageRoute(builder: (context) => YourPage()),
  );
)

the _changeType function is only an example which is necessary in this example project to showcase many ways of using SlideDrawer (with background color, background gradient, etc.)

@salkuadrat
Copy link
Owner

salkuadrat commented May 19, 2021

And in normal application we don't need to set _appKey like in here.

So the app will simply be:

return MaterialApp(
  title: 'Slide Drawer Demo',
  theme: ThemeData(
    primarySwatch: Colors.blue,
    visualDensity: VisualDensity.adaptivePlatformDensity,
  ),
  home: _home,
);

In this example project, _appKey is necessary to force flutter to refresh application every time it needs to change the theme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants