When to use new Screens in Flutter instead of TabBarView - flutter

I am fairly new to Flutter and I try to understand when and why it would be necessary to navigate to a new screen. Most apps keep the same AppBar, Drawer & BottomNavigationBar (if any) through all the different "screens". Wouldn't it be easier to just have one single TabBarView, or only replace the Scaffold's body ?
I have a hard time to really understand the concept of why there needs to be a new Scaffold when routing. I couldn't find anything helpful in the official Flutter doc, even the Cookbook show you a Navigation example with 2 completely new screens just to show a different Text widget inside the Scaffold's body.
Also, what about the efficiency of always rebuilding the whole Scaffold ?

When you route to new page, the previous page stored in history of navigator, so you can easily return to previos page just clicking Back button. In principle all depends on what you need. You may use new page with its own Scaffold as well as one page with single Scaffold and different body widgets. For last case you need to controll Back button manually so this way is enough expensive in development.

Related

Flutter - web app - what's the best practice for displaying a modal data entry form?

I'm building a web app with Flutter, and I was wondering what the best options are for displaying a modal data entry form that does not need to take the whole screen space.
Initially, I was looking at pushing another Scaffold based screen, but that takes up the whole screen space.
Any suggestions?
My humble solution is to wrap your Scaffold's body's Widgets in a Stack.
You can choose whether or not to display the form using if (someState) ... inside the children list.
The form itself can be wrapped in a Card that is wrapped in a Center Widget.
There might be better solutions but that's what I use.

How do you create a side navigation drawer that persists across pages?

I've looked through many tutorials for the side nav drawer. I can create one that works fine to lead to different pages. However, when I travel to a page that's different from home, it only gives me the arrow icon to go back to home at the top left instead of keeping the button to bring me back to the side navbar. How can I prevent this?
I can't use the home page to navigate everywhere because it's just supposed to be a blank splash screen.
You can define your drawer in a separate widget file, that you can import everywhere you have a scafold.
I created a package for it because I was missing similar functionality. If you want a Flutter approach for this navigation check out: https://api.flutter.dev/flutter/material/NavigationRail-class.html
Or if you want to have a look at my package: https://pub.dev/packages/side_navigation
It's because you're moving to a new page/Scaffold (probably using Navigator.push()). So, the default button in the AppBar will be the back button.
You can either have the same Drawer in every Scaffold you navigate to, which is not recommended since you'll just keep pushing routes to the navigation stack.
Or, you can change pages within the Scaffold. Check the interactive examples in BottomNavigationBar and NavigationRail to get an idea of how to do it. Basically instead of calling Navigator.push() when a tile in Drawer is tapped, just update the selected index and call setState().

how to make the App bar stay across all the pages in flutter?

how to make the app bar stay persistent across all the page? I tried with creating a separate file and then importing it under drawer property but its not working...is there any other way of doing it?
from what I understand from persistent. You want that appbar to remain static when changing pages. To do that you should create and use a single scaffold for every page instead of creating a new scaffold for every page. You have to create widgets with bodies of different pages and then set those widgets to the main scaffold body using some conditions in setState. Note as you will be using setState you need to use a stateful widget.
Here is an elaborate article on how to do that with the bottom navbar.

Flutter Webview reloads every time I switch screen

I'm making an app with a BottomNavigationBar with 5 different screens, each of them has a web view. The problem is that everytime I come back to a screen that was previously loaded, it reloads. I have tried using AutomaticKeepAliveClient from copy pasting this code but I doesn't seem to work. I'm new with Flutter so be precise please, thank you.
AutomaticKeepAliveClient is mainly used for keeping a child alive in lazily rendered list views. In your case whenever you switch tabs your current page get disposed and new page materializes on top of it, that means each time when you switch tab a new page is created including all it's widgets.
So if you want to keep your previously loaded web views alive, you have to go with either PageView widget or use Stack widget to load your pages programmatically while the user clicks on a tab.
This is a detailed example about implementing your requirement using PageView widget . you can also find an example with Stack widget under that question.

How to distribute state of BottomNavigationBar across the app in Flutter?

In my app, the navigation bar works fine between the tabs, but when I go inside of each item in my list, I want the navigation bar to be there too.
What I did is that I made it a separate widget, and called in the bottomNavigationBar inside the Scaffold of the pages, but the problem is that I am changing the state of the navigation bar in my main page only, so the state doesn't get distributed across all pages in my app.
How do I make the body of the page change in an app where there is not only one body, but many?
Thanks!
Since there is not code over here in your post and I don't know what you have done so far so I can only advise you to go through this post.
I know you might have already seen this, but still, try to follow and this will really help.
Thanks....!!!!!!
https://medium.com/#lucassaltoncardinali/keeping-state-with-the-bottom-navigation-bar-in-flutter-69e4168878e1