Flutter, a cross-platform app development platform which has been developed and announced by Google is making a sensation among the coders. Since it’s release, Flutter has been in great demand by developers as well as mobile app development companies. How do we get started with Flutter?
What Is Flutter?
Flutter is a cross-platform app development platform that uses a single programming language for app development. Flutter is developed at Google but it’s open to all external contributors for more features. The popularity of Flutter is increasing at a fast pace.
Flutter uses the programming language Dart, which supports the Object-Oriented Programming concepts and is easy to understand. Everything in Flutter is a widget. The smooth learning curve makes Flutter a favourite of developers, for new as well as experienced ones.
Installing Flutter
Flutter installation needs some command-line tools on macOS and Linux. Flutter SDK can be downloaded either from Github or the official page. Once we have the Flutter SDK, add it into the PATH to access Flutter binary globally. This can be done by using the following command:
$ cd ~/development
$ unzip ~/Downloads/flutter_macos_v1.5.4-hotfix.2-stable.zip
$ unzip flutter_macos_v0.7.3-beta.zip
$ export PATH=[PATH_TO_FLUTTER__DIRECTORY]/flutter/bin:$PATH
You can now confirm the installation by running:
$ flutter –help
This will run all the available commands of Flutter.
Installing Dart (Optional)
Once Flutter is installed, sometimes you may have to install Dart. Usually, some Dart libraries come with Flutter but additional developer tools may require the installation of Dart.
For Ubuntu, run the following commands:
$ sudo apt-get update
$ sudo apt-get install apt-transport-https
$ sudo sh -c ‘wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -‘
$ sudo sh -c ‘wget -qO- https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list’
$ sudo apt-get update
$ sudo apt-get install dart
For Windows, run:
C:\> choco install dart-sdk
C:\> choco upgrade dart-sdk
For Mac, run:
$ brew tap dart-lang/dart
$ brew install dart
Pub Package Manager
Flutter uses the Pub Package Manager to manage the Dart packages in the Flutter project. The file “pubspec.yaml” in the Flutter project imports Dart dependencies inside the project. You can in the dependencies in the file and install it using the command:
$ flutter packages get
This will install all the dependencies and create a locked version of the file named as “pubspec.lock”
Your First Flutter App
Now, you can create your first Flutter app. There are multiple ways to create a template app, like from the command line or from the IDE’s. We can generate a boilerplate template by running the following command from the command-line:
$ flutter create name_of_your_app
For now, let’s name our app as test_app
$ flutter create test_app
This command will create the boilerplate of the app inside the test_app directory. You can run your first ever Flutter app using the following commands. However, you need to have a mobile device or a simulator to see the app.
$ cd test_app
$ flutter run
The app will look like:
Understanding The Directory Structure
It’s very important to understand the directory structure of the Flutter app before coding with Flutter.
We have a dedicated directory for the iOS and Android platforms with configuration files like pubspec.yaml, .gitignore, etc at the root of the project. We have two main directories, “lib” and “test”, where most of our Flutter code will live. The “lib” directory has the “main.dart” file, where we specify and create the widgets for the app. The official documentation of Flutter will help you to understand better.
Conclusion
Flutter is a fast-growing cross-platform mobile application development framework. The demand for Flutter app developers are increasing constantly. Want to know more about how Flutter can help your business to grow? Contact us for free consulting.