News

Null Safety Support for Flutter 2 and Dart 2.12

Flutter 2 and Dart 2.8 Higher Performance, Improvements and Null Safety

On March 3rd 2021, Google released a new version of the cross-platform framework Flutter – Flutter 2. According to Google estimates, there are approximately more than 150,000 Flutter apps available in the Play Store alone, including popular ones like WeChat, Grab, Yandex Go, Nubank, Sonos, Fast, Betterment, and realtor.com. Moreover, around  15,000 packages have been provided for Flutter and Dart by companies like Amazon, Microsoft, Adobe, Alibaba and eBay. What new did this release introduce?

Previously, Flutter was known for fully supporting the creation of applications for mobile platforms-Android and iOS. And with the release of Flutter 2, support for creating web applications has also been included – a feature that has been in beta for the past year.

  • Now it is possible to work on Flutter for Web, Desktop, embedded, and mobile devices.
  • An example of an application that operate on all platforms is Flutter Folio.
  • More than 150,000 apps have already been built on Flutter.

Flutter For Web

Flutter 2 offers the following three packages for building web applications:

  • The so-called Progressive web apps (PWA), which unites both the capacities of conventional web applications and desktop applications.
  • Single-page apps (Single page apps or SPA)
  • Expanding ready-made Flutter mobile apps to the web via common source code base.

As stated by Google, special focus was made to delivering improved rendering, and a new CanvasKit renderer was added to the standard HTML renderer. The HTML renderer is set for creating smaller applications with broad adaptability. While the CanvasKit renderer applies WebAssembly and WebGL to render Skia commands on the canvas component in the browser. Meaning, developers have several options of which renderer to use.

Even so, a number of widgets that are utilized specifically for web applications have also been included, for instance, the Link widget.

Flutter Desktop Support

Support for building applications for desktop systems Windows, macOS, Linux is currently in the preview mode, but now developers have the chance through a stable channel to test support for Desktop.

In order to add support for desktop development, you should run specific commands for a particular OS in the console:

flutter config --enable-windows-desktop
flutter config --enable-macos-desktop
flutter config --enable-linux-desktop

A stable version for Desktop will reportedly be out later this year.

The following editions were added:

  • Advanced text handling to be the same as on all supported platforms: highlighting, dragging, keyboard and mouse interaction. For instance, mouse dragging now starts right away, instead of waiting for the delay required when activating touch input.
  • A context menu has been included to the TextField and TextFormField widgets.
  • Grab handles have been introduced to the ReorderableListView widget to let you move list items without having to wait.
  • Updated scroll bar that displays the desktop form factor.
  • Implemented interactive components that are expected on the desktop, including the capacity to drag the slider, click the track to go to the page up and down, and show the track when the mouse cursor hovers over any part of the screen.
  • Added the ScrollbarTheme class, which you can utilize to modify its appearance. Work with additional PC items: for example, double-click on a data folder in Windows Explorer to access the file in the application.
  • Improved handling of resizing – now it’s more polished for both Windows and macOS.
  • Updated official guidelines that define what you need to do to start developing for Desktop.

Flutter Folio Adaptive Application

Flutter supports three platforms for production applications (Android, iOS, and the Web) and has three more reserved in beta (Windows, macOS, and Linux). Flutter Folio was created to produce customized applications that work well on small, medium, and large screens.

Folio is a great example of an application that operates well on multiple platforms based on a single code base. Here you can review the Folio source code to make the native application platform more adaptive.

Beta Version of the Google Mobile for Flutter

The beta version of the Google Mobile Ads SDK for Flutter is now available for use. It is a new plugin that offers embedded banners and native ads to the existing overlay design (overlay banners, interstitial ads). This plugin could be viewed as a combination of ADManager and Admob support that enables you to create various ad arrangements in Flutter apps.

AutocompleteCore and Scaffold Messenger Widgets

Additionally, Flutter 2 now has two new widgets: AutocompleteCore and ScaffoldMessenger.

AutocompleteCore is an autocompletion feature in the search bar that is presented as a drop-down window with suggestions.

ScaffoldMessenger was set to solve a number of technical issues and simplify working with SnackBar. Now the SnackBar saves its work when switching between different Scaffolds and remains on the screen.

AutocompleteCore and ScaffoldMessenger may seem like insignificant updates. Yet everyone who has ever worked with Flutter and tried to activate Autocomplete on their own will understand the importance of these modifications. ScaffoldMessenger probably should have been created from the moment Snackbar was launched.

New Add-to-App Function

The Add-to-App feature is a great for re-using Flutter code on both mobile platforms, while keeping the existing native code base. The interweaving of Flutter and native screens make it challenging to maintain navigation mode, and organizing multiple Flutter models which takes a lot of space.

In Flutter 2, the cost of using static memory for building extra Flutter modules is descreased by ~ 99% to ~ 180 KB per instance.

The new APIs that re in charge of this, are still in beta and documented on flutter. dev, along with a set of sample code. As advised by many developers, you should create multiple instances of the Flutter engine in your applications.

Flutter Fix Option

A command-line tool that enables you to remove legacy APIs in the project code base. Flutter Fix was mostly brought up in order not to mess with more than 500,000 developers and to prevent breaking the growing number of lines of code with editions to the infrastructure API.  According to Google, Flutter Fix has all outdated methods and variables in its database and helps to upgrade them.

Basically, Flutter Fix is a combination of several things. First, it exercises a new command-line option for the dart command-line tool, called dart fix. It has the list of deprecated APIs and knows how to update the code using these APIs. Secondly, it was designed as the list of available fixes itself, which is included in the Flutter SDK from version 2. And finally, it possesses an updated set of Flutter extensions for IDE VS Code, IntelliJ, and Android Studio.

New Dart 2.12

Same time with Flutter, a new version of the Dart language was launched – Dart 2.12, the main alterations of which were:

Sound Null Safety Addition

Sound Null Safety is the most important addition to the Dart language that further advances the type system by dividing NULL-capable types from non-NULL-capable types. This lets developers to avoid runtime breakdown – a common reason of many application failures. By including checks in the type system, these miscues can be detected during development. Null safety is fully supported in the stable version of Flutter 2, which also contains Dart 2.12.

The Dart FFI subsystem is currently at the release state. It enables you to use the C library code, meaning that you can write a library in C and later access its code right from a Dart program.


.

You may also like...