I know both Scaffold and Container are parent widgets in Flutter, but when should I use a Scaffold and when should I use a Container to layout my child widget?
The Scaffold is a widget in Flutter used to implements the basic material design visual layout structure. It is quick enough to create a general-purpose mobile application and contains almost everything we need to create a functional and responsive Flutter apps. This widget is able to occupy the whole device screen.
Container class in flutter is a convenience widget that combines common painting, positioning, and sizing of widgets. A Container class can be used to store one or more widgets and position them on the screen according to our convenience. Basically, a container is like a box to store contents.
MaterialApp is the starting point of your app, it tells Flutter that you are going to use Material components and follow material design in your app. Scaffold is used under MaterialApp , it gives you many basic functionalities, like AppBar , BottomNavigationBar , Drawer , FloatingActionButton etc.
Scaffold
and container
serve different purposes for layout and design.
Scaffold
Link - Scaffold
Container
Link -Container
Conclusion
You need Scaffold widget as main parent of your page where you use container for smaller widget into page to give them different properties like size, border, padding, margin etc.
I would recommend you should understand MaterialApp Widget for a better understanding of Material Widgets like Scaffold and Container.
Scaffold:
The scaffold is the MaterialApp Widget which gives us pre-defined properties like AppBar, Body, Bottom Navigation, Floating Action & Persistent Footer. The scaffold will give Material look and feel in Screen.
Ideally, in MaterialApp every page/Screen will consist of the parent widget as a scaffold. If we don't give Scaffold as a parent widget there will be no material look and feel in Material App.
Helpful link for Scaffold Widget:
Scaffold Class: https://api.flutter.dev/flutter/material/Scaffold-class.html
App Samples: https://flutter.dev/docs/catalog/samples/Scaffold
Container:
The container is a basic/common widget in Flutter which will contain other widgets. Container widget used for decorating its child widget. we can give properties like borders, padding, alignment, height, width, etc. The container class will only contain one child widget.
Helpful link for Container Widget:
Container Class: https://api.flutter.dev/flutter/widgets/Container-class.html
Scaffold is like a parent widget or just consider a whole where you would have different properties like appbar,body all those type widgets are child widget scaffold gives better look to app where only using container is much uglier
Scaffold:
The scaffold has AppBar, Body, Bottom Navigation, Floating Action & Persistent Footer. The scaffold will give Material look and feel in Screen.
Container:
The container is a basic/common widget in Flutter which will contain other widgets. we can give padding , size , position etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With