This book deals with a specific innovative technology for the efficient development of apps for mobile devices. Consequently, it is possible to realize native apps crossplatform in only one programming language. Various practical examples introduce a new technology called “Flutter.” The main part of this book is the description of a more complex app, a 2D game called “Chicken Maze.” The goal of the game is to navigate a chicken through several levels, where it earns points and fights enemies.
When Steve Jobs presented the iPhone at the beginning of 2007, it was a turning point in the digital world. He also demonstrated a new type of software that can be run on the new device, the so-called apps, which is an abbreviation for “Applications.” The abbreviation was probably intended to suggest that these are smaller programs. The first apps were smaller gadgets, for example, the beer-drinker app: You could put the phone to your mouth and tilt it, a beer level that could be seen on the display slowly decreased, and in the end, you heard a burping sound. The amazing thing was that the beer level always remained horizontal, as the program could determine the angle of the device using a built-in sensor. The app is available from the App Store, Apple’s cloud-based software sales platform, revolutionary for its time and exclusive to Apple’s mobile devices.
People stood in line at Apple stores to buy an iPhone and expected new apps. Developers also started rushing for the new device; it was a kind of new gold rush. In 2008 the first competing mobile phone with an Android operating system was launched. The operating system was mainly developed by Google. Google gave the manufacturers of mobile devices a ready-made system software. A store, the Google Play-Store, was also integrated there. For a short time, there were other competing systems such as Windows Mobile or webOS, but these were unable to establish themselves and eventually disappeared. What remained are iOS and Android, so today’s development tools concentrate exclusively on these two. The gold rush is long gone, and meanwhile, you have to do a lot of work as a developer to have commercial success by developing apps.
1.1 Cross-Platform Development
Apps are often developed twice and individually ported to the respective platform. Native Apps1for the iOS environment, i.e., for Apple mobile devices, are programmed using the programming languages Objective-C or Swift and Apple’s frameworks. Android apps, on the other hand, are usually based on the Java platform with the programming languages Java or Kotlin. If you want to work with the in-house technology of competing companies, you have to laboriously translate the code into the other languages by hand. The need for a cross-platform solution, therefore soon came up and various technologies were developed. Basically, we can distinguish between two approaches: On the one hand, there are frameworks that work with web technologies. However, this should not be confused with web apps. These are merely web pages that adapt as well as possible to the mobile device. For app development, there is the procedure of embedding web pages into the app and presenting them via a browser component that fills the entire screen. Your own code is programmed in JavaScript. Via an API, you can talk to native components, which can then address the specific hardware of the device. This approach has two disadvantages: You can only use features that are available on both platforms. Furthermore, the performance is limited because, in the end, you are dealing with a browser application. The advantage is that web developers can also attempt app programming. Well-known frameworks of this kind are React Native from Facebook and Apache Cordova (formerly PhoneGap from Adobe).
The other approach is the following: You program with platform-unspecific languages and frameworks, which are then cross-compiled into the desired environment and therefore have a better performance. A well-known representative of this technology is Xamarin from Microsoft. There, programming is done with C#. The Flutter framework with the programming language Dart also belongs to this category.
1.2 Motivation
The hype about Flutter started in 2018 when it became known that Google was working on a new operating system called Fuchsia, and there was the rumor that this new operating system should replace Android. Meanwhile, Google denied this and announced that the new operating system would be used on new types of devices in the future. Fuchsia is open source and freely available, it can be tested and installed [35]. Flutter is used for the user interface programming. The book does not discuss Fuchsia itself, but you can use the knowledge taught in the book to develop applications for Fuchsia. The graphical user interface is displayed with a render engine called Skia, which is used in Flutter. The framework was in the alpha and beta phase after the first release and allowed the programming of native apps for iOS and Android systems. In addition, Google recommended that you should better realize your apps with Flutter, as it realizes the Google material design. The interest in Flutter was then awakened in the author, who was planning a course for media computer scientists on app programming at that time.
1.3 Target Group
This book targets app developers who are interested in developing new cross-platform apps. These can be professional programmers or students of courses in computer science or media-related studies.
All such persons should have some basic knowledge of programming. The book does not provide a basic introduction to programming. It does not discuss the meaning of variables, loops and control structures. Although the syntax of these structures in the Dart language is also explained, the meaning of the constructs should be clear. The reader should also have some knowledge of object-oriented programming. Ideally, readers should also have already dealt with program libraries and the command line. Knowledge of Java, C#, JavaScript or C++ as first the programming language would be ideal.
1.4 Structure and Aim of the Book
The book points out the pitfalls that you inevitably run into when you take on the adventure of learning a new programming language and a new framework. The book is divided into two parts: a fundamental section and a practical section. The first part explains the most important constructs of the Dart language. This is followed by an introduction to app programming with Flutter. Simple examples are shown there. In the second section, which is the practical part, more sophisticated examples follow, starting with a messenger app that demonstrates how the app connects to the cloud. A more complex application follows, a 2D game called “Chicken Maze,” where a chicken is the game character. The game is not too complex, but is more than a demo app. It contains features that professional applications need. The code of the examples is explained in detail and specific programming techniques of Flutter and Dart are described.