Book Image

Flutter for Beginners

By : Alessandro Biessek
Book Image

Flutter for Beginners

By: Alessandro Biessek

Overview of this book

Google Flutter is a cross-platform mobile framework that makes it easy to write high-performance apps for Android and iOS. This book will help you get to grips with the basics of the Flutter framework and the Dart programming language. Starting from setting up your development environment, you’ll learn to design the UI and add user input functions. You'll explore the navigator widget to manage app routes and learn to add transitions between screens. The book will even guide you through developing your own plugin and later, you’ll discover how to structure good plugin code. Using the Google Places API, you'll also understand how to display a map in the app and add markers and interactions to it. You’ll then learn to improve the user experience with features such as map integrations, platform-specific code with native languages, and personalized animation options for designing intuitive UIs. The book follows a practical approach and gives you access to all relevant code files hosted at github.com/PacktPublishing/Flutter-for-Beginners. This will help you access a variety of examples and prepare your own bug-free apps, ready to deploy on the App Store and Google Play Store. By the end of this book, you’ll be well-versed with Dart programming and have the skills to develop your own mobile apps or build a career as a Dart and Flutter app developer.
Table of Contents (21 chapters)
Free Chapter
1
Section 1: Introduction to Dart
5
Section 2: The Flutter User Interface - Everything is a Widget
10
Section 3: Developing Fully Featured Apps
15
Section 4: Advanced Flutter - Resources to Complex Apps

Understanding why Flutter uses Dart

The Flutter framework aims to be a game-changer in mobile app development, providing all of the tools needed by the developer to make awesome applications with no drawbacks in performance and scalability. Flutter has, in its core structure, multiple concepts focused on app performance and the user interface. To deliver the best output to the developing world with high performance that compares to the official native SDKs, Flutter uses the support of Dart to provide tools that contribute to developer productivity in the development phase and to build applications optimized for publication.

As we have seen before in the Getting started with Dart section, Dart is mature enough and robust with many tools that contribute to Flutter's success. Let's understand why Dart was the perfect choice for the Flutter framework.

Adding productivity

Dart is not only a language, not in concept at least. The Dart SDK comes with a set of tools (seen in the previous Dart development tools section) that Flutter benefits from to help with common tasks during the development phase, such as the following:

Compiling Flutter apps and hot reload

When you're writing or debugging code, you will be using the Dart VM with JIT. This helps to utilize features such as profiling tools, hot reloading (you can refer to Chapter 3, An Introduction to Flutter), and more.

When building your app for release, the code will be compiled in AOT and your app will ship with a tiny version of the Dart VM (which is more like a runtime library) with Dart SDK capabilities such as core libraries and garbage collectors.

This difference, at first, does not seems to be important from the developer's point of view, as we want to simply write and run the app, right? However, when it comes to productivity, this becomes one of the most fundamental Dart strengths used by Flutter.

Flutter's hot reload is one of its most famous features and shows the promised productivity in action. It relies on JIT compilation to make live Dart code swaps while running the app, so we can change our application code and see the result almost in real time. With IDE plugins, this becomes even faster as, after saving a change, the plugin dispatches the reload and the result is seen quickly.

In Chapter 3, An Introduction to Flutter, we will check out hot reload and other features in more detail.

No image can describe the potential of this incredible feature. So, after checking out Chapter 3, An Introduction to Flutter, I suggest you run the Flutter starter project to have first contact with this incredible feature.

Another very cool Dart tool is the Dart analyzer:

This tool helps to figure out potential problems with types and the recommended syntax before running the code.

DevTools also adds an important value to the productivity offered by the Flutter framework; find out more information in Chapter 12, Testing, Debugging, and Deployment.

Easy learning

Dart is a new language for many developers, and learning a new framework and a new language at the same time can be challenging. However, Dart makes this task simple by not reinventing concepts, just fine-tuning them and trying to make them as effective as possible for designated tasks.

Dart is inspired by many modern and mature languages such as Java, JavaScript, C#, Swift, and Kotlin, as you can see here:

With this in mind, reading Dart code, even without knowing the language deeply, is possible. Also, take a look at the official documentation start page:

The documentation and guides are very clear and informative; in addition, the awesome community helps the developer to learn without any headaches.

Check out the official Dart guides on learning: https://dart.dev/guides.

Maturity

Despite being a relatively new language, Dart is not poor or lacking in resources. On the contrary, in version 2, it already has various modern language resources that help the developer to write effective high-level code.

One perfect feature to exemplify this is the async-await feature:

This enables the developer to write non-blocking calls with a very simple syntax, allowing the application to continue to render with no drawbacks.

As Dart focuses on the developer, another important thing for mobile and web developers is building user interfaces. With this in mind, the Dart syntax is easy to understand when you think in UI terms. Let's see an example:

These screenshots are taken from the official Dart website: dart.dev.

The collection if operator that can be seen in the preceding screenshot is one great example of a new feature that is easy to understand even if you are new to Dart.

Dart is evolving alongside Flutter, and these are only some of the important strengths the language provides to the framework. As long as you realize Dart is easy to learn and contributes to Flutter's power, the challenge of learning a new language together with a new framework becomes easier and even enjoyable.

In this book, we are not going to dive too deep into the details of the Dart syntax. You can check the source code of this chapter on GitHub for syntax examples and use this as a study guide or a learning path for the language. Later, you can explore specific syntax or features while you advance in your Flutter framework journey.