by @kodeazy
flutter create hello world app
Note: To understand this tutorial you must have prior knowledge of any other Object Oriented Programming Language like C++ or JAVA
.- In this tutorial we will discuss about how to create sample
Hello World
app influtter
flutter create myapp
helps to create a project withmyapp
as project name- for mor details on cration please refer to this link
- Open
main.dart
file insidelib
folder - remove all the code present in the folder and write as below
import 'package:flutter/material.dart';
void main() {//like `c, c++, Java` even in dart, program starts with main function
runApp(MyApp());//runApp() function is p
// Here We are creating Object for MyApp class inside runApp() method
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Text(
'My First App'),
);
}
}
- Every thing inside flutter is a
widget
. runApp()
method is provided bymaterial.dart
package and it helps to display the widgetStatelessWidget
is a predefined class provided byflutter
for using widgets.- so lets create a class and extend a predefined class
StatelessWidget
by importingpackage:flutter/material.dart
package. - Now implement build method which returns
Widget
type having parameter asBuildContext
type ofStatelessWidget
class. - Inside
build
method we returnMaterialApp()
widget. MaterialApp()
does some basic setup to turn some combination of widgets into a real app that can be rendered.MaterialApp()
uses named arguments, here we usedhome
widget as argument. -home
is core widget that brings to the screen when entire app is mounted- Inside
Text('My First APP')
widget we write the text as parameter to display. - Before Executing the code open the
Android Emulator
. - Now Execute the command
flutter run
in the projectspath
.
Output: