0% found this document useful (0 votes)
134 views8 pages

Flutter Ebook 15 22

Uploaded by

Fuady Dheo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views8 pages

Flutter Ebook 15 22

Uploaded by

Fuady Dheo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Flutter and the related logo are trademarks of Google LLC.

We are not endorsed by or affiliated


with Google LLC.
1 | Welcome

1.1 Introduction
Thank you for having put your faith on this book. If you want to learn how to use a powerful
tool that allows developers to quickly create native applications with top performances, you’ve
chosen the right book. Nowadays companies tend to consider cross-platform solutions in their
development stack mainly for three reasons:
1. Faster development: working on a single codebase;
2. Lower costs: maintaining a single project instead of many (N projects for N platforms);
3. Consistency: the same UI and functionalities on any platform.
All those advantages are valid regardless the framework being used. However, for a complete
overview, there’s the need to also consider the other side of the coin because a cross-platform
approach also has some drawbacks:
1. Lower performances: a native app can be slightly faster thanks to the direct contact
with the device. A cross-platform framework might produce a slower application due to a
necessary bridge required to communicate with the underlying OS;
2. Slower releases: when Google or Apple announce a major update for their OS, the main-
tainers of the cross-platform solution could have the need to release an update to enable
the latest features. The developers must wait for an update of the framework, which might
slow down the work.
Every framework adopts different strategies to maximize the benefits and minimize or get rid of
the drawbacks. The perfect product doesn’t exist, and very likely we will never have one, but
there are some high quality frameworks you’ve probably already heard:
• Flutter. Created by Google, it uses Dart;

Flutter Complete Reference 15


Chapter 1. Welcome

• React Native. Created by Facebook, it is based on javascript;


• Xamarin. Created by Microsoft, it uses the C#;
• Firemonkey. Created by Embarcadero, it uses Delphi.

During the reading of the book you will see how Google tries to make the cross-platform devel-
opment production-ready using the Dart programming language and the Flutter UI framework.
You will learn that Flutter renders everything by itself 1 in a very good way and it doesn’t use
any intermediate bridge to communicate with the OS. It compiles directly to ARM (for mobile)
or optimized JavaScript (for web).

1.1.1 Who is this book for


To get the most out of this book, you should already know the basics of object-oriented pro-
gramming and preferably at least an "OOP language" such as Java or C#. Our goal is trying
to make the contents of this book understandable for the widest possible range of developers.
Nevertheless, you should already have a minimum of experience in order to better understand
the concepts.
If you already know what is a class, what is inheritance and what is nullability, part 1 of this
book is going to be a walk in the park. Foreknowledge aside, we will talk about both Dart and
Flutter "from scratch" so that the reader can understand any concept regardless the expertise
level.

1.1.2 Author
Alberto Miola is an Italian software developer that started working with Delphi (Object Pascal)
for desktop development and Java for back-end and Android apps. He currently works in Italy
where he daily uses Flutter for mobile and Java for desktop and back-end. Alberto graduated
1
For example, it doesn’t use the system’s OEM widgets

Flutter Complete Reference 16


Chapter 1. Welcome

in computer science at University of Padua with a thesis about cross-platform frameworks and
OOP programming languages.

1.1.3 Acknowledgments
This book owes a lot to some people the author has to mention here because he thinks it’s the
minimum he can do to express his gratitude. They have technically supported the realization
of this book with their fundamental comments and critiques that improved the quality of the
contents.

• Rémi Rousselet. He is the author of the famous "provider" 2 package and a visible
member in the Flutter/Dart community. He actively answers on stackoverflow.com helping
tons of people and constantly works in the creation of open source projects.

• Felix Angelov. Felix is a Senior Software Engineer at Very Good Ventures. He previously
worked at BMW for 3 years and is the main maintainer of the bloc state management
library. He has been building enterprise software with Flutter for almost 2 years and loves
the technology as well as the amazing community.

• Matej Rešetár. He is helping people get prepared for real app development on re-
socoder.com and also on the Reso Coder YouTube channel. Flutter is an amazing framework
but it is easy to write spaghetti code in it. That’s why he’s spreading the message of proper
Flutter app architecture.

Special thanks to my friends Matthew Palomba and Alfred Schilken which carefully read the
book improving the style and the quality of the contents.

1.1.4 Online resources and the quiz


The official website of this book 3 contains the source code of the examples described in Part III.
While reading the chapters you might encounter this box:

B Resources > Chapter 16 > Files download

2
https://pub.dev/packages/provider
3
https://fluttercompletereference.com

Flutter Complete Reference 17


Chapter 1. Welcome

It indicates that if you navigate to the Resources page of our website, you’ll find the complete
source code of the example being discussed at Chapter 16 > Files download. In addition, you
can play the "Quiz game" which will test the Dart and Flutter skills you’ve acquired reading this
book.

At the end, the result page will tell you the exact page of the book at which you can find an
explanation of the answer.

1.2 Introduction to Dart


Dart is a client-optimized, garbage-collected, OOP language for creating fast apps that run on
any platform. If you are familiar with an object oriented programming language such as Java or
C# you might find many similarities with Dart. The first part of this book aims to show how
the language can help you solving problems and the vastness of its API.

1.2.1 Supported platforms


Dart is a very flexible language thanks to the environment in which it lives. Once the source code
has been written (and tested) it can be deployed in many different ways:

Flutter Complete Reference 18


Chapter 1. Welcome

• Stand-alone. In the same way as a Java program can’t be run without the Java Virtual
Machine (JVM), a stand-alone Dart program can’t be executed without the Dart Virtual
Machine (DVM). There’s the need to download and install the DVM which to execute Dart
in a command-line environment. The SDK, other than the compiler and the libraries, also
offers a series of other tools:
– the pub package manager, which will be explored in detail in chapter 23;
– dart2js, which compiles Dart code to deployable JavaScript;
– dartdoc, the Dart documentation generator;
– dartfmt, a code formatter that follows the official style guidelines.
In other words, with the stand-alone way you’re creating a Dart program that can only
run if the DVM is installed. To develop Flutter apps for any platform (mobile, web and
desktop), instead of installing the "pure" Dart SDK, you need to install Flutter 4 (which is
basically the Dart SDK combined with Flutter tools).
• AOT compiled. The Ahead Of Time compilation is the act of translating a high-level
programming language, like Dart, into native machine code. Basically, starting from the
Dart source code you can obtain a single binary file that can execute natively on a certain
operating system. AOT is really what makes Flutter fast and portable.

With AOT there is NO need to have the DVM installed because at the end you get a single
binary file (an .apk or .aab for Android, an .ipa for iOS, an .exe for Windows...) that can
be executed.
– Thanks to the Flutter SDK you can AOT compile your Dart code into a native binary
4
https://flutter.dev/docs/get-started/install

Flutter Complete Reference 19


Chapter 1. Welcome

for mobile, web and desktop.

– As of Flutter 1.21, the Dart SDK is included in the Flutter SDK so you don’t have to
install them separately. They’re all bundled in a single install package.

– Starting from version 2.6, the dart2native command (supported on Windows, macOS
and Linux) makes AOT compiles a Dart program into x64 native machine code. The
output is a standalone executable file.

AOT compilation is very powerful because it natively brings Dart to mobile desktop. You’ll
end up having a single native binary which doesn’t require a DVM to be installed on the
client in order to run the application.

• Web. Thanks to the dart2js tool, your Dart project can be "transpiled" into fast and
compact JavaScript code. By consequence Flutter can be run, for example, on Firefox or
Chrome and the UI will be identical to the other platforms.

AngularDart 5 is a performant web app framework used by Google to build some famous
websites, such as "AdSense" and "AdWords". Of course it’s powered by Dart!

So far we’ve covered what you can do with Dart when it comes to deployment and production-
ready software. When you have to debug and develop, both for desktop/mobile and web, there
are useful some tools coming to the rescue.

5
https://angulardart.dev/

Flutter Complete Reference 20


Chapter 1. Welcome

This picture sums up very well how the Dart code can be used in development and deploy-
ment. We’ve just covered the "Deploy" side in the above part, so let’s analyze the "Develop"
column:

• Desktop/mobile. The Just In Time (JIT) technique can be seen as a "real time trans-
lation" because the compilation happens while the program is executing. It’s a sort of
"dynamic compilation" which happens while the program is being used.

JIT compilation, combined with the DVM (JIT + VM in the picture), allows the dispatch
of the code dynamically without considering the user’s machine architecture. In this way
it’s possible to smoothly run and debug the code everywhere without having to mess up
with the underlying architecture.

• Web. The Dart development compiler, abbreviated with dartdevc, allows you to run and
debug Dart web apps on Google Chrome. Note that dartdevc is for development only: for
deployment, you should use dart2js. Using special tools like webdev 6 there’s the possibility
to edit Dart files, refreshing Chrome and visualizing changes almost immediately.

As you’ve just seen, Dart can run literally everywhere: desktop, mobile and web. This book will
give you a wide overview of the language (Dart version 2.10, with null safety support) and all the
required skills to create easily maintainable projects.

6
https://dart.dev/tools/webdev#serve

Flutter Complete Reference 21

You might also like