Introduction
In this article, we will understand some basic and common terms in a flutter that we are using most of the time when we write code in a flutter. It is a very good habit if you have a good idea about some common attribute or keyword to start your journey in any field.
In the previous article, we learned what is flutter and its features, how to install flutter in our android studio, and how we can create our first flutter project in Android Studio.
Some common fundamental terms in flutter are as below,
1. Widget
Flutter is completely all about widgets. A widget is used to make the user interface(UI) in the flutter application. To make beautiful UI in flutter we have good knowledge about different widgets. A widget can Color, Text, Button, ListView, AppBar, etc.
There are two types of widgets a flutter -
2. StatelessWidget
In our user interface(UI), some common widgets such as page title name, the background color of a screen, a title, or a static image. These widgets do not need to change dynamically so these widgets can be defined inside the class that extends stateless widgets.
3. StatefulWidget
In Flutter, a Stateful widget is a type of widget that can dynamically change its appearance in response to user interactions. Unlike a StatelessWidget, which is immutable and cannot change its appearance. When you use a Stateful widget, you need to manage the state of the widget yourself.
4. StatefulWidget Life Cycle Methods
It's very important to understand the lifecycle of a Stateful widget so that we can write efficient, robust, and responsive Flutter apps. By overriding the lifecycle methods, you can take control of the widget's behavior.
Here are the main lifecycle methods of a StatefulWidget-
1. createState()
This method is called when the framework creates a State object for the StatefulWidget. This method is called only once in the lifetime of the widget.
2. initState()
It is called once and only once when the State object is first created, and it is used to perform any one-time setup that is required for the widget. The initState method is called before the build method.
3. build()
This method is called whenever the framework needs to redraw the widget. We should use this method to describe the visual structure of the widget. This method is always executed when the setState() method is called.
4. didUpdateWidget()
This method is called whenever the framework decides that the widget's state has changed. We can use this method to respond to changes in the widget's state, such as when the parent changes.
5. setState()
It is used to redraw a Stateful widget in response to a change in its state. When the state of a Stateful widget changes, you call the setState method to schedule a redraw of the widget. The build method is automatically called when the setState() method is called.
6. dispose()
This method is called when the widget is removed from the tree. You should use this method to clean up any resources allocated by the widget.
5. MaterialApp()
The MaterialApp widget provides a Material Design look and feels to your app. It's the top-level widget in a Flutter app and sets up the basic structure and behavior of the app, including the navigation, the app bar, and the theme. The MaterialApp widget takes several optional parameters, such as the title of the app, the initial route, the theme, and the routes, to configure the appearance and behavior of the app.
6. Scaffold()
The Scaffold widget is a basic layout structure that provides support for a number several Design components, such as an app bar, a drawer, and a floating action button. The Scaffold widget is often used as the root widget of an app, or as the parent widget of a screen in an app.
7. Cupertino()
Cupertino provides a set of widgets for building iOS-style app designs such as buttons, switches, sliders, and navigation bars. Using the Cupertino widgets in your Flutter app can give your app a more native look and feel on iOS devices.
8. pubspec.yaml
This is a configuration file for Flutter projects. It is located at the root of the project and contains important information about your project, including its dependencies, assets, and other settings. The pubspec.yaml file is responsible for managing the packages and dependencies required by your Flutter project. It is used to define the dependencies that your project needs, as well as any assets or other resources that your project uses.
9. void main()
It is the entry point for a Flutter application. Inside this, we have to call the runApp () method to start the application.
10. State
The state is information that can change within an app and affects the user interface. The state is managed by widgets. A widget can either be stateful or stateless.
11. Pub
Pub is Package Manager which is used to manage dependencies for Flutter projects, allowing developers to easily include external libraries and packages in their projects. With Pub, you can search for packages, download packages, and manage the version of packages that you use in your projects.
Conclusion
In this article, we have seen common terms used in a flutter. Thanks for reading and hope you like it. If you have any suggestions or queries on this article, please share your thoughts.
Happy learning, friends!