Today we are pleased to announce the release of Flutter 2, more than two years after the release of Flutter 1.0, but in a short time, Flutter has closed 24,541 issues and consolidated 17,039 PR from 765 contributors.

Since The release of Flutter 1.22 last September, Flutter has closed 5807 issues and incorporated 4091 PR from 298 contributors.

Web

As of today, Flutter Web support has transitioned from Beta to stable Channel. In this initial stable release, Flutter took code reusability to another level on the Web platform, so that now when developers create Flutter applications, the Web is just another supported target device for that application.

By taking advantage of the many advantages of the Web platform, Flutter lays the foundation for building rich interactive Web applications. Flutter focuses on performance and rendering fidelity improvements. In addition to the HTML renderer, we have added a new CanvasKit-based renderer. We also added Web-specific features, such as Link widgets, to ensure that the application running in the browser feels like a Web application.

You can find more details about this stable version of Flutter in the Flutter Web support blog post: medium.com/flutter/web…

Sound Null Safety

The null-safety statement is an important addition to the Dart language and further enhances the type system by distinguishing between nullable and non-nullable types, which enables developers to prevent null error crashes.

By incorporating null checks into the type system, developers can catch these errors during development and prevent production crashes. Starting with Flutter 2, the stable version including Dart 2.12 fully supports air safety claims.

For more details, see the Dart 2.12 blog post: medium.com/dartlang/an…

The pub.dev package repository has published over 1,000 empty security packages, including hundreds from the Dart, Flutter, Firebase, and Material teams.

If you are a package author, check the migration guide and consider migrating immediately: dart.dev/null-safety…

Desktop

In this release, The desktop support for Flutter has been released on stable Channel, which means That Flutter is ready for you to try it out for desktop application development. Of course, you can think of this as a “beta snapshot” to preview the final stable version that will be released later this year.

PS: So it was released to catch up with KPI?

In order to achieve the release quality of the Flutter desktop, Flutter has been improved in size, starting with ensuring that text editing works like the native experience on every supported platform, including things like: The ability to text Selection pivot points and a keyboard event once it’s been handled.

After processing keyboard events, you can now immediately begin dragging on the mouse input side using a high-precision fixed-point device without having to wait for the delay required to process touch input.

In addition, built-in context menus have been added to TextField and TextFormField controls for the Materia L and Cupertino design languages.

Finally, grab handles have been added to the ReorderableListView control.

The ReorderableListView now has a draggable feature that can be easily dragged and dropped with the mouse. In a mobile project, the ReorderableListView requires the user to hold down the cursor to initiate the drag. This scenario works on mobile devices. But few desktop users would think to move an item with a long mouse press, so this version also includes movement for mouse or touch input. Another improvement to common features is an updated scroll bar that displays desktop shape factors correctly.

This version also includes an updated Scrollbar control, which is useful in desktop environments, including the ability to drag preview, click on a track to scroll pages up and down, and display tracks when the mouse hovers over any part of the mouse.

In addition, since the Scrollbar uses the new ScrollbarTheme theme, the developer can style it to match the look and style of the application.

For other desktop-specific features, this release also enables command line argument processing for the Flutter application so that files in the application can be opened using simple actions such as double-clicking a File in Windows File Explorer.

Additionally, Flutter aims to make resizing smoother on Windows and macOS applications, and enable IME (input editor) for international users.

In addition, we have provided updated documentation on what you need to do to start preparing your desktop application for deployment to a specific operating system store. Flutter. Dev/desktop# dis…

When trying to use Flutter desktop Beta, developers can access it by switching to the Beta channel as expected and setting configuration flags for the target platform according to the instructions on Flutter. Dev. In addition, we made beta snapshots available on stable channels.

If a developer uses flutter Config to enable a desktop configuration setting (such as enable-macos-desktop), they can try out the beta features supported by the desktop without having to go through a lengthy process such as removing the Flutter SDK before moving to beta channels. This is great for trying out or using desktop support as a simple “Flutter Emulator.”

However, if you choose to stay on Stable Channel to access desktop Beta, you won’t get new features or bug fixes as quickly as switching to Beta or Dev channels, so if you’re actively targeting Windows, macOS, or Linux, We recommend switching to a channel that provides faster updates.

While the first full production version of Flutter desktop is nearing its full release, we know there is still more work to be done, including support for integration with native top-level menus, a closer text editing experience for all platforms and accessibility support, as well as general

New iOS features

This release brings 178 IOS-related PR merges, including #23495 (bringing state recovery to iOS), #67781 (which satisfies the long-standing requirement to build IPA directly from the command line without opening Xcode), and #69809, which updates the CocoaPods version to match the latest tools.

In addition, some iOS controls have been added to the Cupertino Design Language implementation, such as the new Cupertino OSearchTextField, which provides an iOS search bar UI.

CupertinoFormSection CupertinoFormRow and CupertinoTextFormFieldRow controls are easier to satisfy the design style of iOS.

In addition to features for iOS, in terms of shaders and animations, we will continue to improve the performance of iOS and Flutter. IOS remains the main platform for Flutter and we will continue to work to bring important new features and performance improvements.

New widgets: Autocomplete and ScaffoldMessenger

This version of Flutter comes with two new controls: AutocompleteCore and ScaffoldMessenger.

AutocompleteCore represents the basic function required to incorporate autocompletion into a Flutter application.

Autocomplete is a feature that Flutter often requires. If you are curious about the design of the full function, please check the autocomplete design documentation. Docs.google.com/document/d/…

ScaffoldMessenger addresses a number of Issues related to SnackBar, including the ability to easily create SnackBars in response to AppBar actions; Ability to create SnackBars to persist between scaffolds transitions; The ability to display SnackBars capability when SnackBars is complete, even if the user has navigated to pages with other scaffolds, asynchronous operations will be performed.

All of these advantages can now be used to display SnackBars with a few lines of code:

final messenger = ScaffoldMessenger.of(context); Messenger. ShowSnackBar (SnackBar (content: Text (" I can fly. ")));Copy the code

Multiple Flutter instances with Add-to-App

From talking to many Flutter developers we know that many people have no idea of using Flutter to develop entirely new apps, but they can take advantage of Flutter by adding it to their existing iOS and Android apps.

This feature, called Add-to-app, is an excellent way to reuse Flutter code on both mobile platforms while still preserving the existing native code base. But before that we sometimes hear that it is not clear how to integrate the first page into Flutter.

Interweaving the Flutter with the native machine makes navigation state difficult to maintain, and integrating multiple Flutter at the view level takes up a lot of memory.

In the past, other Flutter instances had the same storage cost as the first one. With Flutter 2, we reduced the static memory cost of creating additional Flutter engines by about 99%, to about 180kB per instance.

The new API supporting this capability can be previewed on the beta channel, and a series of sample projects demonstrating this new mode are documented on flutter. Dev. With this change, we no longer hesitate to recommend creating multiple instances of the Flutter engine in native applications.

Flutter Fix

As any framework matures and gathers users with more and more code bases, the tendency over time is to avoid making any changes to the framework API to avoid breaking more and more lines of code.

With more than 500,000 Flutter developers and a growing number of platforms involved, Flutter 2 soon faced such problems. But to enable us to improve Flutter over time, we want to make significant changes to the API. The question is how do you continue to improve the Flutter API without disrupting the developers?

Dev /docs/develo…

A Flutter Fix is a combination of things. First, the dartCLI tool has a new command-line option called Dart Fix, which knows where to look for a list of deprecated apis and how to update code with them. Second, it is a list of available fixes themselves. Finally, it is a set of updated Flutter extensions for VS Code, IntelliJ and Android Studio IDE that know which changes are exposed to the same content, showing a list of available fixes. Quick fixes, such as underlined ones, help you change code with a single mouse click.

For example, suppose your application contains the following lines of code:

Since using this constructor parameter is not recommended, it should be replaced with the following:

Even with all the deprecated content of Flutter that you are familiar with, the greater the number of changes that must be made in the code, the more difficult and error-prone it becomes to apply all the fixes.

Humans aren’t very good at these kinds of repetitive tasks. But computers are good at it; You can see how we made all fixes throughout the project by executing the following command:

$ dart fix --dry-run
Copy the code

If you want to apply them in bulk, you can easily do so:

 dart fix --apply
Copy the code

Or, if you want to apply these patches interactively in your favorite IDE, do so:

We have been marking old apis as deprecated for many years, but now we have a policy on when to remove actually deprecated apis, and Flutter 2 is the first time we have done so.

Even though we have not captured all deprecated apis as data to provide a Flutter Fix, we will continue to add more information from previously deprecated apis and will continue to do so with future significant changes.

Our goal is to make the Flutter API the best it can be while keeping your code up to date.

Flutter DevTools

To make it clear that DevTools is a tool for debugging Flutter applications, we rename the Flutter DevTools when we debug the Flutter application. A lot of work has also been done to achieve the production quality of Flutter 2.

New features that can also help developers solve problems before you start DevTools are: Android Studio, IntelliJ, or Visual Studio Code can notify you when a common exception occurs and provide the ability to introduce it into DevTools to help you debug it.

For example, the following shows that an overflow exception has been raised in your application, which pops up an option in Visual Studio Code for debugging the problem in DevTools.

Pressing this button opens the Flutter Inspector in DevTools on the troubled control so that it can be repaired.

Today we only do this for layout overflow exceptions, but our plan is to provide this handling for all common exceptions that DevTools can resolve.

Once DevTools is running, the new error flags on the tabs will help developers track specific problems in their applications.

Another new feature of DevTools is the ability to easily view images at a higher resolution than the images displayed, which helps keep track of excessive application sizes and memory usage. To enable this feature, enable “Reverse Large Images” in the Flutter Inspector.

Now, when a developer displays an image with a resolution significantly larger than its display size, the image will be displayed upside down for easy lookup in the developer’s app.

In addition to displaying detailed information about flexible layouts in the Layout Explorer of the Flutter Inspector, we also added the ability to display fixed layouts to enable developers to debug various layouts.

This is not all. This is just a summary of some of the new features that Flutter DevTools 2 has:

  • Added average FPS information to the Flutter framework and improved usability;
  • Call up failed network requests in network profiler with red error labels.
  • Faster new memory-view charts, smaller and easier to use, including new hover cards for describing activities at specific times.
  • Add search and filtering to the Logging TAB.
  • Logs are tracked before DevTools is started, so the full log history can be viewed at startup.
  • Rename the “Performance” view to “CPU Profiler” to make it clearer what it provides.
  • Added a timing grid to the CPU Profiler flame map.
  • Rename the Timeline view to Performance to get a clearer picture of what it provides.

Android Studio/IntelliJ extension

The Flutter plugin for The IntelliJ family of ides also offers many new features for Flutter 2, starting with a new project wizard that matches the new wizard style in IntelliJ.

In addition, if you are using IntelliJ or Android Studio on Linux to program the Flutter SDK installed from the Snap Store, the Flutter snapshot path has been added to the list of known Flutter SDK paths. This makes it easier for users of Flutter Snapshots to configure the Flutter SDK in Settings.

Visual Studio code extensions

The Visual Studio Code Extension to Flutter also improves Flutter 2, starting with a number of test enhancements, including the ability to re-run only failed tests.

After two years of development, LSP (Language Server Protocol) support for Dart is now provided as the default for Dart analysers to integrate into The Visual Studio Code of the Flutter extension.

LSP support includes a number of improvements to Flutter development, including the ability to apply all fixes of a certain type in the current Dart file and make the code complete with generating full function calls (including parentheses and required parameters).

LSP support is not limited to Dart; it also supports code completion in pubspec.yaml and analysis_options.yaml files.

DartPad updated to support Flutter 2

Developers can now try out the new air-safe version of Flutter without leaving their favorite browser.

Ecosystem updates

The development experience for Flutter includes not only frameworks and tools, but also a variety of software packages and plug-ins for Flutter applications.

A lot has also happened in the field since the last stable version of Flutter was released. For example, nearly 30 PR’s have been merged between the Camera and Video_player plug-ins to greatly improve the quality of both.

In addition, if you’re a Firebase user, we’re happy to announce new improvements to the quality of our most popular add-ons, including air security support and full support for Android, iOS, Web, and MacOS. These add-ons include:

  • Core
  • Authentication
  • Cloud Firestore
  • Cloud Functions
  • Cloud Messaging
  • Cloud Storage
  • Crashlytics

In addition, if you are looking for the collapse of the application report, you may need to consider the Sentry, the company has released the applicable to Flutter the application of the new SDK: blog. Sentry. IO / 2021/03/03 /… .

With Sentry’s Flutter SDK, you can receive real-time notifications of errors that occur on Android, iOS or native platforms.

Also, if you do not already see the “plus” plugin for Flutter Community, you need to check it out.

They forked many of the popular plug-ins originally developed by the Flutter team and added NULL security support, support for other platforms and a whole new set of documentation, as well as starting to fix appropriate issues in the Flutter/Plugins repository. The plugin included the following:

  • Android Alarm+
  • Android Intent+
  • Battery+
  • Connectivity+
  • Device Info+
  • Network Info+
  • Package Info+
  • Sensors+
  • Share+

plus.fluttercommunity.dev/

The number of software packages and plug-ins compatible with Flutter at this time exceeds 15,000, making it difficult for developers to find good ones.

Therefore, we publish publish points (static analysis scores), popularity, likeability, and, for particularly high quality, packaging that is specifically labeled Flutter Favorite. In order to timely respond to Flutter 2, we have added several new packages to our favorites list:

  • animated_text_kit
  • bottom_navy_bar
  • chopper
  • font_awesome_flutter
  • flutter_local_notifications
  • just_audio

Last but not least, for package authors or package users interested in whether a package is suitable for the latest version of Flutter, you will need to visit Codemagic’s new pub.green website.

Codemagic’s new Pub. green website shows the compatibility of the latest versions of Flutter with top software packages. The Pub. green website tests the compatibility of the Flutter and Dart packages available on Pub. dev with different Flutter versions.

Codemagic. IO /pub-green/

Breaking Changes

We made the following major changes to Flutter 2, many of which can be alleviated automatically using the Dart fix command or a quick fix in the IDE of your choice:

  • #61366 Continue the clipBehavior breaking change.
  • # 66700The defaultFittedBoxtheclipBehaviorFor nothing.
  • # 68905 从 CupertinoColor resolution API removes the nullOk parameter
  • # 69808 从 Scaffold.ofScaffoldMessenger.ofDelete the nullOk parameter
  • # 68910 从 Router.of To remove the nullOk argument and make it return a non-null value
  • # 68911addmaybeLocaleOfTo localize
  • # 68736 在 Media.queryOfDelete nullOK
  • # 68917 从 Focus.ofFocusTraversalOrder.ofFocusTraversalGroup.ofDelete the nullOk parameter from
  • # 68921 从 Shortcuts.ofActions.findActions.handlerDelete the nullOk parameter from
  • # 68925 从AnimatedList.ofSliverAnimatedList.ofDelete the nullOk parameter from
  • # 69620 从 BuildContexDelete is not recommended
  • # 70726 从 Navigator.ofDelete the nullOk parameter and addNavigator.maybeOft
  • # 72017Delete unrecommended itemsCupertinoTextThemeData.brightness
  • # 72395 从 HoverEventIs deleted from the recommendedPointerEnterEvent.PointerExitEvent
  • # 72532Delete the unused itemsshowDialog.child
  • # 72890Delete unrecommended itemsScaffold.resizeToAvoidBottomPadding
  • # 72893Delete unrecommended itemsWidgetsBinding.deferFirstFrameReport.allowFirstFrameReport]
  • # 72901Delete unrecommended itemsStatefulElement.inheritFromElement
  • # 72903Delete unrecommended itemsElementmethods
  • # 73604Delete the unused itemsCupertinoDialog
  • # 73745From the [CupertinoSliver]NavigationBarDelete unrecommended itemsactionForegroundColor
  • 73746Delete the object that is not approvedButtonTheme.bar
  • #73747 Remove SPAN deprecations
  • # 73748Delete deprecatedRenderView.scheduleInitialFrame
  • # 73749Delete the object that is not approvedLayer.findAll
  • # 75657 从 Localizations.localeOfDelete residual nullOk parameters
  • # 74680 从Actions.invokeDelete nullOk and addActions.maybeInvoke .