Scaffold instead of Container - flutter

Scaffold occupies the available space to it, and sometimes Container can be replaced with Scaffold.
By using Scaffold instead of Container gives any performance issue ?

There's no performance issue here.
Scaffold is used as a root of a screen to get access to setting Appbar, FloatingActionButton, BottomNavigationBar, showing Snackbar, etc.
Whereas a Container is just a simple... well a Container where you can define custom shape & constraints.
Also, a Continer won't always take up entire space, for that you can either use Expanded or a Spacer widget.
Scaffold will take whole screen space as it is meant to be used as a root of a widget screen.
A Scaffold should not be used instead of a Container unless you want to explicitly use Scaffold's properties.

Related

Is there a way to dynamically size a widget according to whatever the size is left on the screen in Flutter?

Lets just say I have 2 widgets on the screen, one a dynamic container that the size depends on the things that are inside that container, and the second widget would be a scrollable ListView. Ideally, I am trying to have both widget on a non scrollable screen, only having the list view to be scrollable. I have tried using a GlobalKey attached to the dynamic container, and then defining the size of the container that's holding the ListView widget with that, but it did not work. This is done on Flutter Mobile development
There are multiple ways to do this. Here is how I would do it-
To limit the height of ListView, wrap the ListView with a Container widget and set the height of the Container to the required height. To make the container cover entire space, wrap with in an Expanded widget. So this is how your widget tree would look like-
//Expanded { //Container { //ListView }}

MaterialApp builder Method places shadow/gradient around widget

I have a MaterialApp with several routes for the various section of my application.
Description
I have used the builder method of the MaterialApp class to place a single scaffold around all of my routes.
The body of this scaffold is a Row which contains a custom side menu widget, and the Widget from the MaterialApp's builder method.
Problem
Flutter is placing a shadow/gradient between my side menu (the widget from the builder method) and the main body of the application. I do not want this shadow and I do not know how to remove it.
What it looks like at the moment:
What it should look like:
This photo shows the difference between the two results (look at the right hand side of the side menus):
What is the top widget in your routes?
This looks like some default elevation is applied by material. You might (worst case) want to wrap the child within the builder method with a ClipRRect or DecoratedBox with specified clip behaviour to avoid that shadow overlaying your other widgets

How to prevent widgets from being hidden behind the system status bar

So I am creating a new flutter widget and I am unable to understand how my app looks because of the space on top of the screen in my emulator,
As you can see there is a shaded area on top and my widgets are under it, is there any way to remove it?
Use Safe Area.
SafeArea is basically a glorified Padding widget. If you wrap another widget with SafeArea, it adds any necessary padding needed to keep your widget from being blocked by the system status bar, notches, holes, rounded corners, and other "creative" features by manufacturers.
Check this link for more.
Wrap your code with the SafeArea.
more info about SafeArea class

Should I always use a SafeArea at the top level of my flutter screens?

I am curious if I should always use a SafeArea widget at the top level of my screen. I mean....when would I want my content blocked by things like a notch? For me it seems like the answer is never.
So should I not just use SafeArea on every page? If so, should it be above or below the Scaffold widget?
You don't have to use SafeArea on every screen. It actually depends if an AppBar is used or not, because the AppBar automatically calculates the values and adds the required padding.
If you use it above a Scaffold the area where the padding is applied would be black. On the other hand, if you use it below the Scaffold the color of the area would depend on the app theme, probably the Scaffold background color.
If you won't add an app bar or add it. if you want to adjust the screen to be responsive using MediaQuery and you don't need any scroll inside the screen use it.
Use it as the first widget in the body of the scaffold.

Adding Semantics to the first widget on every page with Flutter

Google Play warns me about missing Content labeling under Accessibility tests for every page the crawler can reach.
I've tried to add a Semantics Widget to every page to surround the body element of the scaffold, I've even added an Extra Container as the first child of this Semantics widget with double.infinity as width and height.
The only other thing I can think of doing is to make it the parent of the Scaffold - but what is the correct solution?
Somewhat related: Should SafeArea be the parent or the body element of the Scaffold?
Concerning the placement of the safearea, you should always put your scaffold first. In other words, wrap the safearea with the scaffold. The content label error from play console can also be solved by specifying information such as hint text in input fields or labels for buttons where necessary.