Skip to main content

MaterialApp and Scaffold in Flutter with Example

What is MaterialApp

Material design is for Google Android material design which is used to create UI for Android.MaterialApp is a predefined class in a flutter that extends the Material Design class.

It is likely the main or core component of flutter. We can access all the other components and widgets provided by Flutter SDK. It is a class that creates an instance of [WidgetsApp].

Text widget, AppBar widget, Scaffold widget, ListView widget, StatelessWidget, StatefulWidget, IconButton widget, TextField widget, and many more widgets that are accessed using MaterialApp class. 

For iOS, there is the Cupertino widgets class which I'll describe or discuss or explain in another article.

What is Scaffold

In Flutter Scaffold is a very useful and highly flexible class. Scaffold implements the basic material design layout structure.

A Scaffold Widget provides a framework that implements the flutter app's basic material design visual layout structure. 

The developer can implement a wide range of widgets using Scaffold as the Parent Widget. It provides APIs for showing FlottingButton, drawers, snack bars, and bottom sheets.

The most commonly used Widget, Scaffold can complete the entire App building with its flexible properties and attributes.

To know more about Widgets we can use in  Scaffold and which are the properties scaffold give us, we will see some of the important properties of the Scaffold class.

Properties of Scaffold Class

1. AppBar and Background

An app bar to display at the top of the scaffold. where you can give any text or set the menu icon or popupMenu. 

The background color of the Material widget focuses on the entire Scaffold which gives great application. This is a sample Background Color attribute like any other widget. An example of that is given below. Let's take the Example of AppBar and background.

2. Body

The body property is the primary content of the scaffold. We can create any widget to be held here. A basic example of this I have given here for more I'll discuss in a new section.


3. FloatingActionButton

FloatingActionButton gives by flutter which we can set in the different locations you can give as per your requirements like centerDocker, centerFloat, centerTop, endDocker, endTop, endFloat, miniCenterDocker, and many more. It is very useful and simple to create in Flutter. An example is given below.


4. BottomSheet

BottomSheet is also a widget that is similar to all other widgets. As the name says bottom sheet is open from the bottom of the screen. In flutter, they give us an inbuilt function showModelBottomSheet we just have to write our required list of widgets in it and ready to use.

I have given an example in which I have open the BottomSheet onPressed of FloatingButton.


5. Drawer

We can create Swipes in from either left-to-right or right-to-left. This is similar to the Sliding-drawers which we are using for Android’s Material Design. The creation of a  drawer is quite easy with Android and in the same way, Flutter has made it extremely easy to create one. 

An example is given below I have created a drawer and create a class for showing data in that drawer if you want to do code in one class you can also do that but it looks complex and not understandable so if possible then always create a different class for that.


6. BottomNavigationBar

BottomNavigationBarto display at the bottom of the scaffold.BottomNavigationBar is used to provide a Navigation-like bar at the bottom of the Application. A sample is given below in which I have created bottom navigation and explore some properties of the BottomNavigationBar.

7. PersistentFooterButtons

A set of buttons that are displayed at the bottom of the scaffold. This is a collection of FloatingActionButtons or any kind of button you can use like RaisedButton, OutlinedButton, and many more. that is present at the bottom of the Application. When used properly, it can be very useful. 

Let's take the example in which we are taking the list of values and multiple buttons and see how it will work.

Comments

  1. Detailed article with code implementation. Nice work. Very helpful. Keep it up!

    ReplyDelete
  2. Excellent explanation for freshers Thank you so much for this, helpful for new commerce.

    ReplyDelete

Post a Comment

Popular posts from this blog

Flutter BottomNavigationBar

BottomNavigationBar A material widget that's displayed at the bottom of an application. Which shows around three to five items and it includes labels and icons. BottomNavigationBar allows you to select one item at a time and quickly navigate to a given page. Properties of the BottomNavigationBar : items: It defines the list of BottomNavigationBar Items to display the bottom navigation bar. currentIndex: It determines the current active bottom navigation bar item on the screen. onTap: It is called when we tapped one of the items on the screen. iconSize: It is used to specify the size of all bottom navigation item icons. fixedColor: It is used to set the color of the selected item. If we have not set a color to the icon or title, it will be shown. type: It determines the layout and behavior of a bottom navigation bar. It behaves in two different ways that are:  1. fixed: Default it is fixed and If it is null, it will use fixed. 2. shifting: It will use shifting where w

Flutter TextField with Examples

Introduction to TextField TextField in Flutter is the most commonly used text input widget that allows users to collect inputs from the keyboard into an app. We can use the TextField widget in building forms, sending messages, creating search experiences, and many more. By default, Flutter decorated the TextField with an underline. We can also add several attributes with TextField, such as label, icon, inline hint text, and error text using an InputDecoration as the decoration. If we want to remove the decoration properties entirely, it is required to set the decoration to null. 1. decoration It is used to show the decoration around TextField.The most common attributes in decoration are as follows: border : It is used to create a default rounded rectangle border around TextField. labelText : It shows the label text on the selection of TextField. hintText : It shows the hint text inside TextField when there is no text entered.   TextField(               decoration: InputDecoration(