Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art
Writing Mobile Apps With FlutterBack to Android Cookbook Home | Up to Chapter: Other Programming Languages

Author: Ian Darwin ('idarwin')
In Published Edition? Yes
FormatLanguage: AsciiDoc

Writing Mobile Apps With Flutter

Problem

You want to build an app that will work on Android and iOS from a single code base.

Solution

Consider using Flutter, the free cool toolkit that makes Android and iOS apps from a single Dart-language code base.

Discussion

Download Flutter from flutter.io. For Mac you should also have the Xcode-based tools installed. The command `flutter doctor` will tell you if you have anything missing.

Note that you can develop on any major platform, but you can only test and package for iOS on a Macintosh dev computer. This is true of almost all cross-platform tool sets, so just blame Apple for restricting Xcode to their platform.

Give the command

flutter create helloworld

This will create a project folder helloworld with several subdirectories:

If you have Android Studio installed, add the Flutter plug-in from the Plugins menu, and open the new project. The plugin lets you start Apple simulators and Android emulators, and do full run or hot reload on both.

Examine the file lib/main.dart. since you presumably know Java, you will be able to figure out most of the code here.

To run it, plug in your Android device and run the app, either form the run menu or by giving the command

flutter run

If you are on a Mac, start the simulator and run the app there too.

Click the Floating Button to increment the counter. Then make the change suggested in the code for the color scheme and do the hot-reload; you should see the color change but not the counter value.

To learn more about Flutter, please see my page at https://darwinsys.com/flutter for more information.