Your First Flutter Project


In this article, we’re going to create a very simple flutter project called “Hello World”. If you don’t have an environment setup, feel free to check flutter documentation first

Creating your first project

flutter create firstapp
<span class="hljs-built_in">cd</span> firstapp

Editing /lib/main.dart

main.dart is a file that executes for the first time when you open an app. Like a C-Program, Dart also starts with main() as an initial function to execute. inside main() we need to return a runApp() with widgets This example, we have returned a simple Widget called Text()

Text Widget contains a few properties such as string, alignments, directions ..etc.(check out:

Final Code

<span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/material.dart'</span>;

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span>{
<span class="hljs-keyword">return</span> runApp(Text(<span class="hljs-string">'Hello World'</span>, textDirection: TextDirection.ltr));

Since, main() return only one function, we can simplify this code as follow

<span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/material.dart'</span>;

<span class="hljs-keyword">void</span> main() => runApp(Text(<span class="hljs-string">'Hello World'</span>, textDirection: TextDirection.ltr));