0% found this document useful (0 votes)
6 views

flutter course

Uploaded by

Bilel Gh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

flutter course

Uploaded by

Bilel Gh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

class MyHomePage extends StatelessWidget {

MyHomePage({Key key, this.title}) : super(key: key);

final String title;


@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(this.title), ),
body: Center(child: Text( 'Hello World',)),
);
}
}
Here, we have created a new widget by extending StatelessWidget.
Note that the StatelessWidget only requires a single method build to be implemented in its
derived class. The build method gets the context environment necessary to build the
widgets through BuildContext parameter and returns the widget it builds.
In the code, we have used title as one of the constructor argument and also used Key as
another argument. The title is used to display the title and Key is used to identify the widget
in the build environment.
Here, the build method calls the build method of Scaffold, which in turn calls
the build method of AppBar and Center to build its user interface.
Finally, Center build method calls Text build method.

For a better understanding, the visual representation of the same is given below −

State maintenance widgets


In Flutter, all widgets are either derived
from StatelessWidget or StatefulWidget.

Widget derived from StatelessWidget does not have any state information
but it may contain widget derived from StatefulWidget. The dynamic nature
of the application is through interactive behavior of the widgets and the
state changes during interaction. For example, tapping a counter button will
increase / decrease the internal state of the counter by one and reactive
nature of the Flutter widget will auto re-render the widget using new state
information.

We will learn the concept of StatefulWidget widgets in detail in the


upcoming State management chapter.

You might also like