Original link: medium.com/flutter/wha…

After nearly two months of version iteration, Flutter officially released Flutter 2.5 yesterday. According to the official introduction, this is a major release update that closes 4,600 issues in total and incorporates 3,932 PR from 252 contributors and 216 reviewers.

This release continues a number of important performance and tooling improvements, as well as a number of new features including:

  • Full screen support for Android, more Material You (also known as V3) support;
  • Updated text editing to support swappable keyboard shortcuts;
  • See your widgets in more detail in the Widget Inspector;
  • Add new support for dependencies in Visual Studio Code projects;
  • New support for getting coverage information from IntelliJ/Android Studio test runs;
  • And provide a brand new application template to provide a better foundation for your Real world Flutter application.

Performance: iOS shader warm-up, asynchronous tasks, GC, and messaging

This release brings several performance improvements.

(#25644) The first PR in this list, which is mainly used to precompile with Metal shaders connected from offline training runs, reduces the rasterization time of worst-case frames by 2/3 seconds and the 99th percentile frame by half. However, shader preheating is only one source of lag. In previous versions processing asynchronous events from networks, file systems, plug-ins, or other isolates could interrupt animation, which was another source of lag.

In this release, the UI ISOLATE’s event loop scheduling strategy (#25789) was improved so that frames now take precedence over other asynchronous events, thus eliminating the lag caused by this problem in testing.

Another cause of stalling is that the garbage collector (GC) pauses the UI thread to reclaim memory. Previously, the memory of some images was delayed in response to GC execution of the Dart VM. As a solution in earlier versions, the Flutter engine implied that image memory could be recycled through GC collection of the Dart VM, which theoretically enabled more timely memory reclamation. Unfortunately, this also leads to too many major GCS, and sometimes still can’t reclaim memory fast enough.

Therefore, in this release, (#26219, #82883, #84740) solves the problem of unused image memory not being eagerly reclaimed, greatly reducing THE VM GC problem.

For example, in the following test, playing a 20-second animated GIF went from 400 GCS to just 4. Fewer major GCS mean that animations that involve images appearing and disappearing will lag less and consume less CPU and power.Another performance improvement for Flutter 2.5 is the delay when sending messages between Dart and Objective-C/Swift (iOS) or Dart and Java/Kotlin (Android).

Typically, removing unnecessary copies from the message codec as part of messaging can reduce latency by up to 50%, although the exact figure depends on the message size and device (#25988, #26331).

Also, a major update for iOS users comes with this release. Flutter applications built on Apple Silicon M1 Macs are also available on the ARM iOS emulator (# 85642).

This means that there are no Rosetta conversions between Intel X86_64 instructions and ARM, thus improving your iOS application’s performance during testing and allowing you to avoid some subtle Rosetta issues (#74970, #79641), This is a step forward in Apple’s efforts to fully support Flutter.

Dart 2.14: Formats, language features, publishing, and Linting out of the box

This version of Flutter is released with Dart 2.14.

The new version of Dart comes with a new format that makes cascading clearer; The new PUB supports ignoring files, as well as new language features, including regression of the triple shift operator. In addition, Dart 2.14 creates a standard set of Lint that is shared between new Dart and Flutter projects, right out of the box.

Android full screen, Material You & Text editing shortcuts

Starting with (#81303), we fixed a number of Android issues related to full-screen mode. This change also added a way to listen to full-screen changes in other modes. For example, when a user interacts with an application and the system UI returns, developers can now write code to do something else when it returns to full screen.

In this release, we added support for the new Material You (aka V3) specification, including updates to float action button sizes and themes (# 86441), in MaterialState scrolledUnder can use the sample code in the Demo to see the new status of the PR type (# 79999).Another improvement is the addition of Scroll Metrics notifications (# 85221,# 85499), which provides a hint of scrollable areas even if the user does not scroll. For example, the ListView shows a scrollbar based on the size of the list.You don’t have to write any code in this case, but if you want to catch ScrollMetricNotification changes, you can do so by catching this listener.

Another great community contribution is with ScaffoldMessenger. You may recall that beginning with Flutter 2.0 ScaffoldMessenger provides an even more powerful way to display SnackBars at the bottom of the screen to inform users. Now, starting with Flutter 2.5, we can add a banner on the top of that Scaffold that will remain until the user closes it.We can obtain ScaffoldMessenger for this behaviour by calling the showMaterialBanner() method, as shown below.

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(
          title: const Text('The MaterialBanner is below'),
        ),
        body: Center(
          child: ElevatedButton(
            child: const Text('Show MaterialBanner'),
            onPressed: () => ScaffoldMessenger.of(context).showMaterialBanner(
              MaterialBanner(
                content: const Text('Hello, I am a Material Banner'),
                leading: const Icon(Icons.info),
                backgroundColor: Colors.yellow,
                actions: [
                  TextButton(
                    child: const Text('Dismiss'),
                    onPressed: () => ScaffoldMessenger.of(context)
                        .hideCurrentMaterialBanner(),
                  ),
                ],
              ),
            ),
          ),
        ),
      );
}
Copy the code

The Material guidelines specify that a Flutter banner can only be displayed one at a time. To display multiple streamers, multiple showMaterialBanner and ScaffoldMessenger calls will be required. Display a new banner.

Also, in this release, we have added the ability to overwrite text editing keyboard shortcuts (#85381). This is a further optimization of Flutter 2.0 and its new text editing capabilities. For example, we can text select and be able to stop event propagation of a keyboard event after it has been processed.

DefaultTextEditingShortcuts class contains each platform supported on the list of keyboard Shortcuts, if developers want to cover any content, you can use the Flutter of existing Shortcuts will any Shortcuts to map to existing or custom intention, using the reference: DefaultTextEditingShortcuts.

Plugins: Camera, image selector, and Plus plugins

The new version of the camera plug-in, image selector plug-in has been upgraded and optimized, focusing on solving the following problems:

  • #3795 [Camera] Android – Rework part 1: Base classes that support Android camera features
  • #3796 [camera] Android – Rework – Part 2: Android autofocus
  • #3797 [camera] Android – Rework Part 3: Android exposure
  • #3798 [camera] Android – Rework – Part 4: Android flash and zoom features
  • #3799 [camera] Android – Rework – Part 5: Android FPS range, resolution, and sensor orientation
  • #4039 [camera] Android – Rework – Part 6: Android Exposure and focus features
  • #4052 [camera] Android – Rework Part 7: Android noise reduction
  • #4054 [camera] Android – Rework – Part 8: Support modules for the final implementation
  • #4010 [camera] does not trigger device orientation on iOS
  • #4158 [Camera] Fixed coordinate rotation to set focus and exposure on iOS
  • Camera preview does not always rebuild when the direction changes
  • #3992 [camera] prevents crashes when setting unsupported FocusMode
  • #4151 [camera] introduces the CamerA_Web package

The Image_Picker plugin has also been optimized to improve the end-to-end camera experience.

  • #3898 [image_picker] Image picker fixes camera equipment
  • #3956 [image_picker] Changes the storage location captured by the camera to an internal cache on Android to meet the new Google Play storage requirements
  • #4001 [image_picker] removes redundant requests for camera permissions
  • #4019 [image_picker] Fix rotation issues when camera is source

The above optimizations have improved the functionality and robustness of the Android camera and image_picker plug-ins. It also provides basic support for viewing camera previews, taking photos, and using flash and zoom controls on the Web, but is not yet a recognized plug-in, so developers need to explicitly add it in order to use it on the Web.

Outdated API tips

In this version of Flutter, each corresponding plugin provided by the Flutter team comes with a battery-like prompt indicating whether the plugin is obsolete. If these plug-ins are identified as Battery, then we are no longer actively maintained, we recommend using the plus versions of the following plug-ins:

Flutter DevTools: Performance, Widget inspector, and Polish

This time, DevTools added support for using engine updates (#26205, #26233, #26237, #26970, #27074, #26617).

Now, with DevTools, we can better associate trace events with a specific framework, which helps developers analyze problems after they occur.Using DevTools, we can see the page is rendered Frames chart complete rendering process, and can be present when filling in the application to this diagram, select a frame from the chart you can navigate to the frame time line of events, we can use these events to help diagnose the shader compilation caton problems in the application.

DevTools detects when frames are lost due to shader compilation so that it can resolve the stutter problem. This is basically similar to the previous steps for memory analysis using DevTools.

In addition, when tracking CPU performance issues in your application, you may be overwhelmed by analysis data from the Dart and Flutter libraries or engine native code. If you want to turn off other distractions and focus only on your own code, you can do this using the new CPU Profiler feature (#3236). This feature hides analyzer information from these sources.

For any categories that are not filtered out, they are now color-coded (# 3310,# 3324), you can easily see which parts of the system the CPU frame chart is coming from. Color frame diagram for identifying application, native, Dart and Flutter code activity in the application.

Meanwhile, this version of DevTools comes with an update to the Widget Inspector, which allows you to hover over a Widget to get information about evaluation objects, view properties, Widget status, and more.Also, when you select a Widget, you automatically get the Widget’s properties.In addition to the new features, The Widget Inspector has been updated and optimized to make DevTools more useful for debugging Flutter applications.

The optimized and changed contents are shown in the following aspects:

  • Optimized debug toggle buttons: We’ve updated these buttons to better express what they do, and each tooltip is linked to a detailed documentation of that feature.

  • Easier interface analysis and positioning: The widgets commonly used in the Flutter framework all display ICONS in the Widget tree view on the left. They are further color-coded by category, such as layout widgets in blue and content widgets in green.

  • Align the layout explorer and component tree color schemes: It is now easier to identify the same widgets from the layout Explorer and Widget tree. For example, the “column” Widget in the screenshot is on a blue background in the layout browser and has a blue icon in the Widget tree view.

There are currently several versions of DevTools available, and we’d love to hear what you think and use of these updates. Here’s a full list of DevTools features:

  • Flutter DevTools 2.3.2 Release Notes
  • Flutter DevTools 2.4.0 Release Notes
  • Flutter DevTools 2.6.0 Release Notes

IntelliJ/Android Studio: Integration testing, test coverage, and icon preview

Of course, along with the update to Flutter, our IntelliJ/Android Studio plugin has made many improvements in this release. First, the ability to run integration tests (#5459) was added.

Integration tests are a way to test the entire application running on the appliance, with the code in the Integration_test directory and using the same functionality as the testWidgets() unit tests.To add integration tests to your project, follow theInstructions on flutter. DevTo connect tests to IntelliJ or Android Studio, add a run configuration to start integration tests and connect devices for testing. Then, after starting up again, run the tests, including setting breakpoints, stepping, skipping, and so on.

Additionally, The latest IJ/AS plugin for Flutter allows you to view coverage information for unit tests and integration test runs from the button to the right of Debug.The overwrite information is distinguished by red and green bars in the editor’s binding lines. In the example program, lines 9-13 are tested, but lines 3 and 4 are not.The latest version also includes a new ability to preview ICONS used from the pub.dev package, which is built around TrueType font files (# 5504,# 5595,# 5595,# 5704) built just like the Material and Cupertino ICONS support preview.

To enable icon preview, you need to tell the plug-in which packages you are using, and there is a new text field in Settings/Preferences.

Here is more information about the IJ/AS plug-in:

  • Flutter IntelliJ Plugin M57 Release
  • Flutter IntelliJ Plugin M58 Release
  • Flutter IntelliJ Plugin M59 Release
  • Flutter IntelliJ Plugin M60 Release

Visual Studio Code: Dependencies, Fix All, and Test Runner

The Visual Studio Code plugin for Flutter has also been improved and upgraded in this release, with two new commands Dart: Add Dependency and Dart: Add Dev Dependency (# 3306.# 3474).These commands provide functionality similar to Jeroen Meijer’s Pubspec Assist plug-in, with new commands out of the box and a filter list of package types retrieved periodically from pub.dev.

In addition, developers may be interested in the “Fix All” commands (#3445, #3469) that apply to Dart files and can Fix All the same problems as Dart Fix in one step.

Of course, we can also addsource.fixAlleditor.codeActionsOnSaveTo set up to save runtime data, which can also be enableddart.previewVsCodeTestRunnerSet up to test running Dart and Flutter content.

The Visual Studio Code test runner looks slightly different from the current Dart and Flutter test runners in that it retains run results across sessions. The Visual Studio Code test runner also added a new binding line chart that shows the final status of the test, which you can click to run (or right-click to get a context menu).In the upcoming release, the existing Dart and Flutter testing tools will be removed in favor of the new Visual Studio Code testing tools.

Tools: Exceptions, new application templates, and Pigeon 1.0

The debugger has now been upgraded to properly interrupt unhandled exceptions that were previously only caught by the framework (#17007). This improves the debugging experience because the debugger can point directly to the offending line of code.

Since the creation of Flutter, we have used Counter as a template for our applications and it has many advantages:

  • Demonstrates many of the features of the Dart language;
  • Demonstrates several key Flutter concepts, and it is small enough;
  • Can be placed in a single file, even if there are many explanatory comments;

However, we felt that it did not provide a very good template for Flutter development. Therefore, in this release, we provide a new template (#83530) that creates the following command:

flutter create -t skeleton my_app
Copy the code

The skeleton template generates a two-page list view that follows community best practices and provides the following functionality:

  • Coordinate multiple widgets for ChangeNotifier
  • By default, localization is generated using ARB files
  • Include sample images and create 1x, 2X, and 3X folders for image assets
  • Organize with “feature first” folders
  • Shared preferences are supported
  • Supports chiaroscuro themes
  • Supports multi-page navigation

Over time, we will continue to refine the new template until it is better for anyone who wants to learn about it.

On the other hand, we also updated Pigeon and released version 1.0. Pigeon is a code generation tool for generating type-safe interoperable code between Flutter and its host platform. It allows you to define descriptions of plug-in apis, And generate framework code for Dart, Java, and Objective-C (available for Kotlin and Swift, respectively).

Pigeon is currently used in some of the Flutter team’s plugins. In this release it provides more useful error messages, adds support for generics, raw data types as parameters and return types, and multiple parameters. Expect developers to use it more frequently in the future.

other

Other major changes and deprecations to Flutter 2.5 include the following:

  • Drag the scroll device by default
  • Deprecated apis were removed after V2.2
  • Import package: flutter_lints
  • ThemeData’s accent property is deprecated
  • Gesture recognizer cleanup
  • Replace with collate AnimationSheetBuilder. The display
  • Render the platform view in the Web using HTML slots
  • Migrate LogicalKeySet to SingleActivator

Additionally, with the release of Flutter 2.5, we will discontinue support for iOS 8, which was announced in September 2020. Abandoning support for iOS 8, which had less than 1% of the market share, allows the Flutter team to focus on new platforms that are more widely used. The abandonment means that these platforms work, but we will not be making feature updates and plugin support on these platforms.

Reference: Update Flutter 2.5