Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Scaffold and Container in Flutter?

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?

like image 458
wz366 Avatar asked Dec 09 '19 05:12

wz366


People also ask

What is Scaffold in Flutter?

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.

What is a container in Flutter?

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.

What is difference between material and Scaffold in Flutter?

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.


3 Answers

Scaffold and container serve different purposes for layout and design.

Scaffold

  • Implements the basic material design visual layout structure.
  • This class provides APIs for showing drawers, snack bars, and bottom sheets.

Link - Scaffold

Container

  • A convenience widget that combines common painting, positioning, and sizing widgets.
  • It basically contains different widget into one widget over which you can give padding , size , position etc.

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.

like image 76
Vrushi Patel Avatar answered Oct 20 '22 21:10

Vrushi Patel


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

like image 25
Gaurang Goda Avatar answered Oct 20 '22 22:10

Gaurang Goda


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.

like image 2
Sharjeel Moqrab Khan Avatar answered Oct 20 '22 21:10

Sharjeel Moqrab Khan