Writing Mobile Apps With Flutter
In Chapter: Other Programming Languages
Author: Ian Darwin ('idarwin')
You want to build an app that will work on Android and iOS from a single code base.
Consider using Flutter, the free cool toolkit that makes Android and iOS apps from a single Dart-language code base.
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:
- lib - the main source folder
- android - a typical gradle-based Android project
- iOS - an Xcode-based iOS project.
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
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.