by @kodeazy

flutter create hello world app

Home » flutter » 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 in flutter
  • flutter create myapp helps to create a project with myapp as project name
  • for mor details on cration please refer to this link
  • Open main.dart file inside lib 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 by material.dart package and it helps to display the widget
  • StatelessWidget is a predefined class provided by flutter for using widgets.
  • so lets create a class and extend a predefined class StatelessWidget by importing package:flutter/material.dart package.
  • Now implement build method which returns Widget type having parameter as BuildContext type of StatelessWidget class.
  • Inside build method we return MaterialApp() 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 used home 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 projects path.

Output: