Section 1: Introduction to Flutter and Dart
In this section, you will gain an understanding of the core Flutter framework, explore the basics of the Dart language, learn how to set up your own environment, and finally learn how to get started with it.
This section comprises the following chapters:
- Chapter 1, An Introduction to Flutter
- Chapter 2, An Introduction to Dart
- Chapter 3, Flutter versus Other Frameworks
- Chapter 4 Classes and Constructs
Chapter 1: An Introduction to Flutter
In this chapter, you will learn the basics of the Flutter framework, the reasons for its creation, and what the future of Flutter may hold. You will learn about the thriving Flutter community, how it is contributing to the continued evolution of Flutter, and how and why Flutter has grown so quickly in the last couple of years. Along the way, you will see how to make (and run!) your first Flutter project, experience the excellent Flutter documentation, and see how Flutter is designed to work across a range of platforms including iOS, Android, Web, Windows, and Mac.
The following topics will be covered in this chapter:
- What is Flutter?
- Hello Flutter – a first glimpse of Flutter
- Widgets, widgets, everywhere
- Building and running Flutter
Technical requirements
In this chapter, we will create, build, and run a Flutter application. To do this, you will need to set up your system so that it is capable of doing this.
Specifically, you will need to set up your system to have the following:
- A Flutter software development kit (SDK) installed and added to your PATH
- An integrated development environment (IDE) where you can view and edit Flutter code
- Android Studio and/or Xcode so that you can use the Android and iOS development tools and iOS simulators/Android emulators
The chapter will give you some guidance on how to set up your system, but as you will discover, the Flutter documentation is excellent and includes very accurate and up-to-date getting started guides: https://flutter.dev/docs/get-started/install.
Feel free to set up your system now or at the specific points required during the chapter.
You can find the source code for this chapter on GitHub at https://github.com/PacktPublishing/Flutter-for-Beginners-Second-Edition/tree/main/hello_world/lib/chapter_01.
What is Flutter?
Since the advent of the Apple App Store (and subsequently the Google Play Store), there has been a way for organizations to share programs with mobile users in a very controlled and managed way. Much like web pages on the internet, mobile apps have proliferated to encompass all aspects of our life. And much like web pages, over the years, developers have iteratively discovered and learned the best ways to create reliable, scalable, and intuitive mobile apps.
As developers have learned to work within the mobile ecosystem, they have followed similar design patterns and framework ideas as were created to deal with the web ecosystem. Much like the complications of developing code for multiple browsers, in the mobile ecosystem, there has been the challenge of developing code that can work on both iOS and Android devices, with the dream always being to have one code base that works on all devices and even the web.
Flutter is a framework that is the culmination of this learning. Like most other frameworks, developers use a programming language specified by the framework, and structure their code in a way that aligns with the needs of the framework so that ultimately, the developer creates the least amount of "boilerplate" code and can focus on their business needs. Examples of "boilerplate" code would be how to manage touch input, how to connect to the internet, and how to package the app code to work with the App Store, Play Store, or web hosting service.
Flutter is a very new framework, and this means that it does not have a big section of the mobile development market yet, but this is changing, and the outlook for the next few years is highly positive.
When choosing a new programming language or framework, it is hugely important to developers and software companies that what they have chosen has certain key aspects that will ensure it is easy to pick up and that it has a bright future. Investing time and money into learning a new solution, and then developing a code base and development processes around that language and framework, is incredibly expensive. If that solution becomes outdated after a short period of time, there is poor support and documentation, there are a lack of new developers available to take your product forward, or the solution has scaling issues or usability problems, then that investment is wasted. Let's look at some of the aspects that suggest Flutter may be a good long-term investment.
Backed by Google
Flutter, and the Dart programming language it depends on, were created by Google, and although they are open source, they continue to be backed by Google. This ensures the framework has all the tools it needs to succeed in the community, with support from the Google team, presence at big events such as Google I/O, and investment in continuous improvements in the code base.
From the launch of the first stable release during the Flutter Live Event at the end of 2018, the growth of Flutter is evident:
- More than 200 million users of Flutter apps
- More than 50,000 Flutter apps on the Play Store
- Nearly 500,000 developers
- The 18th most popular software repository on GitHub
Let's look at some of the reasons why Flutter has become so popular.
Fuchsia OS and Flutter
It's not a secret anymore that Google has been working on a new operating system called Fuchsia OS, which has been rumored to be a potential future replacement for the Android OS. One thing to pay attention to is that Fuchsia OS may be a universal Google operating system that runs on more than just mobile phones, and this would directly affect Flutter adoption. This is because Flutter will be the first method of developing mobile apps for the new Fuchsia OS, and, not only this, Fuchsia uses Flutter as its UI render...