Skip to content

dwyl/flutter-todo-list-tutorial

Repository files navigation

Flutter TodoList Tutorial

Create a simple todolist Flutter application

Widgets

Flutter is using Widgets to create the applications' UI. Widgets let you declare how and what to render on the screen.

Widgets can be composed to create more complex UI, creating a widgets tree, similar to the Document Object Model which is used to represent html pages.

For example a todo list app could be represented with the follownig wireframe:

todolist-app

From there we can start to have an idea of the widgets tree structure:

widgets-tree

see also:

Create a new Flutter application

A quick CLI tour

You can create a new Flutter project with the following command line:

flutter create --org com.dwyl --project-name todolist .

This will create the project todolist in the current folder .. The --org flag uses the reverse domain name notation to identify your application.

You can then run the application with flutter run and run the tests with flutter test.

For the list of command type flutter help. For more details about a specific command, for example create, run flutter create --help

Material Design

Material Design is a guideline to create user interface. Flutter implements the guideline with the material components widgets. This list of widgest allow us to create rapdly a UI folling the best practices from material design. To use these widgets you need first to import the material Dart package with import 'package:flutter/material.dart'; You can then browse all the material widgets and select the ones required for your application https://api.flutter.dev/flutter/material/material-library.html

You have also the possiblity to create an IOs look by using the Cupertino widgets package

Main Widgets used

Note that the Column and Exapanded widgets are "space" widgets.

Flutter provide a widget inspector where you can see the full tree of the application:

widget tree

Create the application

Dart requires a main function to be defined to create the start of your program.

void main() {
    print('hello');
}

the runApp function is used in the main function and takes a widget as parameter. This widget becomes the root element of your application and it is displayed on the user screen.

The MaterialApp widget create a material design application.

void main() {
  runApp(MaterialApp(title: 'TodoList', home: App()));

Note that the App widget is created later on as a StatelessWidget.

see also:

Stateless and Statefull widget

Tests

Unit tests

Widget tests

Integration tests