Flutter - a mobile applications framework
Hello everyone,
Like any good dev who respects, I like to find new technos still little known but could become a basic model in the future.
I recently discovered a framework for creating Android / iOS applications.Code name: flutter. This was developed by Google and is quite comparable to React Native.
I must say that I find a lot of advantage in this framework:
- It’s pretty simple to use
- It seems relatively stable
- It is cross platform (although at the moment this argument is no longer valid)
- the hot reload (the system instantly replay your changes) that the framework offers.
It is based on a programming language I had never heard of before: Dart. As little as I read, it looks like an interesting mix between Java and Python.Since I am a Python developer and I had a mainly Java training, this can only suit me.
At first glance, the framework looks very promising and can create an application quickly.
Moreover its complete integration (I had to add two libraries) in an editor like Android Studio gives a little more to the framework.Let’s try to show its power by realizing a simple little application:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: Text('Welcome to Flutter'),
),
body: Center(
child: Text('Hello World'),
),
));
}
}
In this first example, we can read an import, which is none other than the base of flutter.
void main() => runApp(MyApp());
allows the execution of the main class. In this case MyApp is the famous magic class.
The => allows you to write code on a single line.
It extends another StatelessWidget class that is a stateless Widget.
Roughly speaking, it does not hold data. It should also be understood that in Flutter, everything is Widget, MyApp being a widget that contains a build method which itself returns a Widget of type MaterialApp.
This MaterialApp contains a scaffold widget that contains an AppBar as well as a body that is a Widget Center, this widget is a Widget Text.
The main purpose of a widget is to provide a build method that can tell its parents how to represent it.
This first application allows you to display a classic “Hello world” centered in an app with a menu bar. This bar contains a title “Welcome to flutter”.
For those interested in this framework, I invite you to discover the doc that explains how to easily install this and continue your discovery by yourself.