Original link medium.com/flutter/wha…

Flutter 2.5 is the second major update to Flutter in its history.

  • Closed 4,600 issues;
  • 3,932 PR from 252 Ficolin-3 and 216 reviewers combined;

Looking back over the past year, we saw 1,337 ficolin-3 creating a whopping 21,072 PR, with 15,172 of those consolidating.

In fact, this release is still full of performance and development tools improvements, as well as many new features, including:

  • Full screen support for Android, more Material You (also known as V3) support;
  • Update text editing to support swappable keyboard shortcuts;
  • The Widget Inspector provides more details.
  • New support for adding dependencies in Visual Studio Code projects
  • IntelliJ/Android Studio added test runs to get coverage information;
  • A new application template that provides a better foundation for Flutter application development;

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

The first PR in #25644 is to run Metal shader precompilation for offline training, which, as shown in benchmark tests, reduces the worst case frame rasterization time 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.

So #25789 improved the scheduling strategy. In this version of the ISOLATE UI event loop, frame processing now takes precedence over other asynchronous events, thus eliminating this kind of lag 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 memory still can’t be reclaimed fast enough to avoid low memory situations on memory-constrained devices, while memory for unused images in this release is eagerly reclaimed (#26219, #82883, #84740), greatly reducing THE GC.

In one test case, for example, playing a 20-second animated GIF went from more than 400 GCS to just 4. Fewer major GCS meant that animations involving images appearing and disappearing would 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 as part of channeling a message, removing unnecessary copies from a message codec can reduce latency by up to 50%, depending on the message size and device (#25988, #26331).

You can find more information about platform channel performance at medium.com/flutter/imp…

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, new PUB support for ignoring files, and 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.

Not only will developers get these Lint when they create a new Dart or Flutter project, but they can add the same analysis to existing applications in just a few steps.

Dev /docs/releas…

For more information about these Lint, new language features, and more, see medium.com/dartlang/an…

Framework: 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.

New Android full-screen modes: Normal mode (left), edge-to-edge mode (middle), edge-to-edge mode with custom SystemUIOverlayStyle (right)

In this release, we added support for the new Material You (aka V3) specification, including an update to the floating action button size and theme (#86441), In MaterialState. ScrolledUnder can use the sample code in the Demo to see the new status of the PR type (# 79999).

New MaterialState. ScrolledUnder state at work

Another improvement is the addition of Scroll Metrics notifications (#85221, #85499), which will provide notifications of scrollable areas even if the user is not scrolling, such as the following showing the ListView appearing or disappearing scroll bars appropriately according to the base size:

You don’t have to write any code in this case, but if you want to catch ScrollMetricNotification changes, you can do so through this listener.

Special thanks to community contributor Xu-Baoolin who put in the effort and came up with a great solution.

Another great community contribution is for ScaffoldMessenger. You may recall that Flutter 2.0 began ScaffoldMessenger as an even more powerful way to display SnackBars, providing users with notifications at the bottom of the screen, With Flutter 2.5, a banner can now be added to the top of that Scaffold until the user closes it.

Applications can obtain this action ScaffoldMessenger by calling the showMaterialBanner method 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 guide states that developers can only display one application banner at a time, so if you call showMaterialBanner multiple times, ScaffoldMessenger will maintain a queue to display a new banner after the previous banner has been closed.

Thanks to Calamity210 for making such an excellent addition to the Material support in Flutter!

This builds on Flutter 2.0 and its new text editing features, such as text selection and the ability to stop its propagation after handling keyboard events.

If you want CtrL-A to perform some custom actions instead of selecting all the text.

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 intentions.

API reference: API. Flutter. Dev/flutter/wid…

Plugins: Camera, image selector, and Plus plugins

Another plugin with many improvements is the camera plugin:

  • #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 plug-in also does a lot of work, focusing on 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 when camera is source

This work improves the functionality and robustness of Android’s camera and image_picker plug-ins.

Also you’ll notice that early versions of the camera plugin are available for network support (#4151).

This preview provides basic support for viewing camera previews, taking photos, using flash, and scaling controls on the Web. It is not yet a recognized plug-in, so you need to explicitly add it to use it on the Web.

Pub. dev/packages/ca…

In this version of Flutter, each corresponding plugin for the Flutter team now comes with a battery-like suggestion:

Also, since these plug-ins are no longer actively maintained and they are no longer marked as Flutter’s favorite plug-ins, we recommend using the plus versions of the following plug-ins:

Flutter DevTools: Performance, Widget inspector, and Polish

First and foremost, DevTools adds support for using engine updates (#26205, #26233, #26237, #26970, #27074, #26617).

One set of updates enables Flutter to better associate trace events with a particular framework, which helps developers determine why the framework might be over budget.

You can see this in the DevTools Frames chart, which has been rebuilt to “live” and can be filled in when the application renders, by selecting a frame from the chart to navigate to the timeline events for that frame:

The Flutter engine can now also recognize shader compilation events in the timeline, which Flutter DevTools uses to help diagnose shader compilation stutter in applications.

With this new feature, DevTools detects when a frame is lost due to a shader compilation so that it can solve the stutter problem.

When flutter Run is used with the — Purge -persistent-cache flag, this clears the cache to ensure that the environment seen by the user in the “first run” or “re-open” (iOS) experience is reproduced.

This feature is still in development, if you have any questions, you can refer to: b.corp.google.com/issues/new?…

In addition, tracking CPU performance issues in applications can be overwhelmed by analysis data from the Dart and Flutter libraries or engine native code. If you want to turn either of these off to focus on your own code, you can do so 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) so that 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

Performance is not the only factor in debugging. This version of DevTools comes with an update to the Widget Inspector, which allows you to evaluate objects, view properties, Widget state, and more while hovering over a Widget.

When a Widget is selected, it is automatically populated in the new Widget inspector console, where you can browse the Widget’s properties.

Expressions can also be evaluated from the console while paused at a breakpoint.

In addition to new features, The Widget Inspector has received a facelift. In order to make DevTools more useful for understanding and debugging Flutter applications, some updates have been made in collaboration with Codemate, a Creative technology agency based in Finland.

You can see the following changes in this screen capture:

  • Better communicate what debug toggle buttons do — these buttons have new ICONS, task-oriented labels, and rich tooltips that describe what they do and when to use them, each of which is further linked to detailed documentation of the functionality.

  • Easier to scan and locate Widgets of interest — Widgets commonly used in the Flutter framework now display ICONS in the Widget tree view to the left of the inspector. They are further color-coded by category, for example, layout Widgets are blue and content Widgets are green. In addition, each text Widget now displays a preview of its content.

  • Align layout Explorer and Widget 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.

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

The IntelliJ/Android Studio plugin for Flutter also has a number of improvements in this release, starting with the ability to run integration tests (#5459).

Integration tests are full application tests that run on the appliance, in the Integration_test directory, and use the same functionality as the testWidgets() unit tests.

To add integration tests to your project, follow the instructions on flutter. Dev. To connect tests to IntelliJ or Android Studio, add a run configuration that starts integration tests and connects devices for testing. This includes setting breakpoints and stepping.

Additionally, The latest IJ/AS plugin for Flutter allows you to view coverage information for unit tests and integration test runs, which can be accessed from the toolbar button next to the Debug button:

The overwrite information is displayed in red and green bars in the editor’s binding lines, in this example 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, #5677, #5704), just as 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:

Note that this setting only applies to ICONS defined as static constants in a class, as shown in the sample code in the screen capture. It does not apply to expressions, such as lineicons.addressbook () or lineicons.values [‘code’].

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

The Visual Studio Code plugin for Flutter has also been improved 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.

Developers may also 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.

This can also be set to run on save by adding source.fixAll to the VS Code setting of editor.codeActionsOnSave, or if you want to try the preview feature, Can enable the dart. PreviewVsCodeTestRunner Settings and see through the new Visual Studio Code test run of the dart and Flutter test.

The Visual Studio Code test runner looks slightly different from the current Dart and Flutter test runners in that it will retain 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, existing Dart and Flutter test runners will be removed in favor of the new Visual Studio Code test runner.

Tools: Exceptions, new application templates, and Pigeon 1.0

In this release, the debugger can now correctly interrupt on unhandled exceptions that were previously caught by the Framework (#17007).

This improves the debugging experience because debuggers can now point directly to their throw trips in code, rather than to random lines deep in the frame.

A related new feature enables developers to determine whether FutureBuilder should rethrow or swallow errors (#84308), which should provide developers with a number of additional exceptions to help track down problems in Flutter applications.

Since the creation of Flutter, there has been a Counter application template that has many advantages:

  • It 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, it does not provide a particularly good starting point for the Flutter application. In this release, a new template is provided with the following command (#83530) :

$ flutter create -t skeleton my_app

The skeleton template generates a two-page list view that follows community best practices, was developed with extensive internal and external review, provides a better foundation for building production-quality applications, and supports the following capabilities:

  • Used forChangeNotifierCoordinating multiple widgets
  • 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

This new template is expected to evolve over time as Flutter best practices evolve.

On the other hand, if you’re developing plug-ins rather than applications, you might be interested in Pigeon’s 1.0 release.

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 already used in some of the Flutter team’s plug-ins. In this release it provides more useful error messages, adds support for generics, raw data types as parameters and return types, and multiple parameters, and is expected to be used more frequently by developers in the future.

Major changes and deprecations

Here are the major changes in Flutter 2.5:

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

As you continue to update the Flutter Fix (available in your IDE and through the Dart Fix command), there are a total of 157 rules to automatically migrate code affected by these or past major changes and any deprecations.

Additionally, with the release of Flutter 2.5, we will discontinue support for iOS 8, which was announced in September 2020. Dropping support for iOS 8, which had a market share of less than 1%, 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 testing new versions or plug-ins for Flutter on these platforms.

You can view the list of supported Flutter platforms on flutter. Dev: flutter. Dev /docs/develo…