Recently, Google launched the first beta version of their mobile UI framework called Flutter at the Mobile World Congress in Barcelona in February. After this announcement, there was a nice collection of posts in the general tech press (for instance, Ars Technica, TechCrunch, VentureBeat, 9to5Google), lots of new Flutter posts on Medium by Flutter’s awesome community, and a huge stream of new developers and organisations around the globe downloading and using Flutter for development.
The unveiling of Flutter Beta 2
Google releases the second beta build (v0.2.8) of Flutter which is good news to developers community across the world. Google’s new mobile UI framework helps developers craft high-quality native interfaces for both iOS and Android. Lately, Google has been working hard to continue to support Flutter’s rapidly expanding community and are now introducing much easier installation process, default support for Dart 2, and more. If you are new to Flutter, get started today with beta 2 at flutter.io.
What’s new in Flutter second beta
Enhanced developer tools
Android Studio & IntelliJ gained a new ‘Outline view’ providing a structured tree view of the UI widgets in a build method, and support for ‘Format on Save’. Flutter’s developer tools and experience team shipped the M23 tools milestone featuring many improvements.VS Code got support for running unit tests, multi project support, and a new picker to select the current Flutter SDK when multiple are installed on your machine.
Seamless installation
After so much feedbacks received from developers that installation of Flutter could be easier; installing beta 1 required cloning Flutter’s GitHub repo with git command line tools. In this new version, a new installation procedure has been adopted, and now support installing beta 2 by simply downloading and extracting an installation archive: Windows, macOS, and Linux. For Windows users, a new cool feature was added called Flutter Console so you can get started with Flutter commands right after downloading:
Improved asset system
Flutter has done some pretty significant optimization of its asset system. They now place the assets using the structure that the underlying platform (Android, iOS) expects. This has a number of advantages.
First and foremost, Flutter apps now launch faster as unnecessary extractions of assets are not made. The previous asset system occasionally caused slow launch times on older Android devices.
Second, it enables plugins to access the assets from the native-code side of a plugin (i.e., from Java, Kotlin, Objective-C, or Swift). Let’s look at a concrete example, the video_player
plugin that was launched a few months ago. Until now it was only capable of playing videos from the network, but several developers requested the ability to “pass” it video files that had been embedded into the app using Flutter’s asset system. With beta 2, and version 0.4.0 of the plugin, this is now a reality. Because the assets has been placed as the underlying platform expects, they can be shared between Flutter and the native platform. And new APIs have been provided(Android, iOS) for getting a suitable asset lookup key for use in the native code, for example the Android AssetManager:
https://gist.github.com/Temidtech/045356b5f84c46951039134bc5a1a257
Dart 2 enabled by default
The first beta offered a preview of the Dart 2 programming language. Flutter testing has shown Dart 2 to be near complete, and very stable. Flutter’s second beta has Dart 2 enabled by default. As a result you will get faster async calls, and a much richer type system. I love this part trust me!
Let me show you a quick code snippet of how the new type system can save you a lot of debugging time, consider the following:
https://gist.github.com/Temidtech/15ba39f8fb7e4a9e1b7d649bef4b1d89
If you carefully check that code it definitely has a bug. It’s passing a list of strings and tasks to a widget that expects a list of widgets. Static analysis does not handle this, because the programmer intentionally used lax static typing for the todo list (List
is shorthand for List<dynamic>
).
Next Let’s consider how the app is using this list:
https://gist.github.com/Temidtech/ad9f54e317670191281e5761f1864bf5
Due to the fact that access to the todo list items is conditional, the error comes in quiet late. In Flutter beta 1, there would be no error at startup, and only once the user has tapped the button would you be informed that a string cannot be used as a widget which really sucks:
However, with the new complete run-time checks in Dart 2, “errors waiting to happen” is prevented like this by instead failing early, at the point where your code makes a false claim about generic types. In this case, Flutter fail as soon as the app launches, and the dynamic list todo
is passed to the TodoList
constructor, which expects a List<Widget>
:
https://gist.github.com/Temidtech/cdec91472bd9cb5b51c0130cb59b3a76
Dart 2 and optional new/const
Dart 2 also included support for making the new and const keywords optional when calling constructors. During the final testing of beta 2, a number of issues was discovered so for now it’s recommended that any non-experimental use of optional new/const is postponed until the launch of a new beta build declaring it ready.
In conclusion, if you haven’t tried out Flutter already, you are missing a whole lot of amazing stuffs already. Getting started is as simple as a button click.
No Comment! Be the first one.