Performance improvements, DevTools updates, new Material You support, new application templates, and much more
Original address: medium.com/flutter/wha…
Original author: medium.com/csells_180…
Published: September 8, 2021-18 minutes to read
Hello, welcome to Flutter 2.5! This is a big release, with the second highest statistics in Flutter’s release history. 4,600 questions were closed and 3,932 PR were consolidated from 252 contributors and 216 reviewers. If we look back at last year, we saw 21,072 PR created by 1,337 contributors, of which 15,172 were merged. While the “What’s New with Flutter” blog post focuses on new features, our primary job with Flutter is to always make sure you have the features you need and achieve the highest level of quality possible.
In fact, this release continues with some important performance and tooling improvements to track performance issues in your own applications. There are also some new features, including full screen support for Android, more Material You (also called V3) support, updated text editing to support swappable keyboard shortcuts, a more detailed look at your widgets in the Widget Inspector, Add new support for dependencies in the Visual Studio Code project, new support for getting coverage information from IntelliJ/Android Studio test runs, and a brand new application template as a better foundation for your real-world Flutter applications. This release is full of exciting new updates, so let’s get started.
Performance: iOS shader warm-up, asynchronous tasks, GC, and messaging
This release has several performance improvements. The first is a PR for connecting metal shaders pre-compiled from offline training runs (#25644), which (as our benchmark shows) reduces the worst case frame rasterization time by 2/3 and the 99th percentile frame by half. We continue to make progress in reducing iOS interference and this is another step along that path. However, shader preheating is only one source of interference. Previously, processing asynchronous events from the network, file systems, plug-ins, or other isolators that might interrupt the animation was another source of interference. The UI isolator event loop scheduling policy (#25789) has been improved in this release so that frame processing now takes precedence over processing of other asynchronous events, eliminating interference from this source in our tests.
Frame lag as a result of processing asynchronous events before and after
Another cause of lag is when the garbage collector (GC) pauses the UI thread to reclaim memory. Previously, some image memory would only be lazily reclaimed during GC in the Dart virtual machine. In earlier versions, as a workaround, the Flutter engine would suggest to the Dart VM that image memory could be recycled through GC, which in theory could lead to more timely memory reclamation. Unfortunately, in practice, this leads to too many major GCS, and memory still sometimes cannot be reclaimed quickly enough to avoid low memory situations on devices with limited memory. In this release, unused image memory is eagerly reclaimed (#26219, #82883, #84740), greatly reducing the GCs.
Add pre – and post-repair GC to eagerly reclaim unused large image memory
For example, in one of our tests, playing a 20-second GIF animation went from needing more than 400 GCs to just four. Fewer major GCs means that animations that involve images appearing and disappearing will have less interference and consume less CPU and power.
Another performance improvement for Flutter 2.5 is the delay issue when sending messages between Dart and Objective-C/Swift (iOS) or Dart and Java/Kotlin (Android). As part of tuning the message channel, unnecessary copies are removed from the message codec and latency can be reduced by up to 50% (#25988, #26331) depending on the size and device of the message.
IOS message latency before and after
You can read more details about this work in Aaron Clarke’s blog improving Platform Channel Performance in Flutter.
If you’re aiming for iOS, there’s one last performance update. In this release, the Flutter application built on Apple’s Silicon M1 Macs runs natively on the ARM iOS emulator (#pull/85642). This means there is no Rosetta translation between Intel X86_64 instructions and ARM, which improves performance in your iOS app testing and allows you to avoid some subtle Rosetta issues (#74970, #79641). This is another step on the road to fully supporting Apple silicon in Flutter. Stay tuned for more information.
Dart 2.14: Formatting, language features, PUB, and Linting out of the box
Of course, a Flutter is not a Flutter without the Dart language and runtime, it is based on the Dart language and runtime. Dart 2.14 is included in this version of Flutter. The new version of Dart comes with new formatting to make cascading clearer, new PUB support for ignoring files, and new language features, including the legendary three-step shift operator regression. In addition, and one of the best things about Dart 2.14, this release creates a new set of standard rows shared between Dart and the Flutter project, right out of the box.
The Flutter Create comes out of the box with an analysis_options. yaml file prepopulated with the recommended flutter threads.
Not only do you get these pads when you create a new Dart or Flutter project, but in just a few steps, you can also add the same analysis to your existing application. For details on these pads, new language features and more, check out the Dart 2.14 release announcement.
Framework. Android full screen, Material You and Text editing shortcuts
Flutter version 2.5 includes several fixes and improvements to the framework. Starting with Android, we fixed a set of related issues around full-screen mode with nearly 100 thumbs between them. The names of the modes themselves make this one of our favorite new features: Back, stickiness, Sticky immersion, edge to edge. This change also adds a way to listen to full-screen changes in other modes. For example, if the user participates in the application, developers can now write code to return to full screen or do other things when the system UI comes back.
New Android edge-to-edge mode: normal mode (left), edge-to-edge mode (middle), edge-to-edge with custom SystemUIOverlayStyle (right).
In this version, we continue to build the new Material You (v3) specification, including the floating action button size and theme updates (# 86441), and a new MaterialState. ScrolledUnder state, You can see it in action with the sample code in PR (#79999).
New Material You FAB size
The operation of the new MaterialState. ScrolledUnder state situation
While we’re talking about scrolling, another improvement is the addition of a scroll indicator notification (#85221, #85499), which provides a scrollable area notification even if the user doesn’t scroll. For example, the scroll bar appears or disappears appropriately depending on the underlying size of the ListView.
The new scroll indicator notification makes the scroll bar automatically appear and disappear without scrolling
In this case, you don’t need to write any code, but if you want to catch changes to the ScrollMetricNotification, you can. Special thanks to community contributor Xu-Baolin who did a lot of work on this and came up with a good solution.
Another outstanding contribution from the community is the addition of material banner support for ScaffoldMessenger. You may remember the ScaffoldMessenger announcement for Flutter 2.0, which is a more powerful way to display SnackBars at the bottom of the screen to provide users with notifications. In Flutter 2.5, you can now add a banner to the top of your scaffold and keep it in place until the user removes it.
Your application can obtain this behavior by calling ScaffoldMessenger’s showMaterialBanner method.
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 on banners states that your application should only display one at a time, so if your application calls showMaterialBanner multiple times, ScaffoldMessenger will maintain a queue to display each new banner if the previous banner is rejected. Thanks to Calamity210 for this great addition to material support in Flutter
Building on Flutter 2.0 and its new text editing features, such as text selection fulcrum and the ability to stop propagation after keyboard events are processed, in this version we added the ability to make text editing keyboard shortcuts overwrite (#85381). If you want CtrL-A to do something custom instead of selecting all the text, you can do this. DefaultTextEditingShortcuts class contains a Flutter on each platform supported by each list of keyboard shortcuts. If you want to overwrite anything, use the existing Shortcuts widget of Flutter to remap any Shortcuts to existing or custom intentions. You can place the widget where you want to overlay it in your widget tree. See the API reference for some examples.
Plug-ins: camera, image picker, and add-on plug-ins
Another plugin that has undergone a lot of improvement is the camera plugin.
- 3795 [Camera] Android – Rework Part 1: Basic classes that support Android camera features
- 3796 [Camera] Android – Rework Part 2: Android auto focus function
- 3797 [Camera] Android – Rework Part 3: Android Exposure related features
- 3798 [Camera] Android – Rework – Part 4: Android flash and zoom
- Part 5: Android FPS range, resolution and sensor orientation features
- 4039 [Camera] Android – Rework Part 6: Android Exposure and Focus features
- 4052 [Camera]Android- Rework Part 7: Android noise reduction features
- 4054 [Camera] Android – Rework Part 8. Support modules for the final implementation
- 4010 [Camera] Do not trigger flat device orientation on iOS
- 4158 [Camera] Fixed rotation of focus and exposure points on iOS
- 4197 [Camera] Fixed issue where camera preview does not always rebuild when direction changes
- 3992 [Camera] prevents crashes when setting unsupported FocusMode
- 4151 [Camera] introduces the CamerA_Web package
A lot of work has also been done on the Image_Picker plug-in, which focuses on the end-to-end camera experience.
- [image_picker] Image collector repair camera equipment
- 3956 [image_picker] On Android, change the storage location of camera capture to internal cache to meet the new Google Play storage requirements.
- 4001 [image_picker] removes redundant camera permission requests
- 4019 [image_picker] Fix rotation when the camera is a source.
This work improves the functionality and robustness of Android’s camera and image_Picker plug-ins. In addition, you’ll notice that an early version of the camera plugin has network support (#4151). This preview provides basic support for viewing camera previews, taking photos, and using flash and zoom controls, all over the web. It is not yet a recognized plug-in, so you need to explicitly add it for use in your web applications.
The initial Android camera rewrite was contributed by Acoutts. The camera and image collector work was done by Baseflow, a consulting firm specializing in Flutter, known for its software package on Pub.dev. Camera_ Web’s work was primarily done by Very Good Ventures, a US-BASED Flutter consulting firm. Thank you all so much for your contribution to the Flutter community!
Another valuable community contribution is made by the Community organization Flutter, known for its “Plus” plugin. With the release of this version of Flutter, each corresponding plugin from the Flutter team now carries a recommendation, like this recommendation battery.
Also, since these plug-ins are no longer actively maintained, they are no longer marked as Flutter favorites. If you haven’t already done so, we recommend you switch to the plus version of the plugin below.
Flutter DevTools: Performance, Widget Inspector, and Polish
This version of Flutter includes many improvements to Flutter DevTools. The first is the addition of support for engine updates in DevTools (#26205, #26233, #26237, #26970, #27074, #26617). One set of updates enables Flutter to better associate tracking events with specific frames, which helps developers determine why a frame might be over budget. You can see this reflected in the DevTools framework chart, which has been reconstructed to “live”; When frames are rendered in your application, they are filled in to the diagram. Select a frame from this diagram to navigate to the timeline events for that frame.
The Flutter engine can now also recognize shader compilation events in the timeline. Flutter DevTools uses these events to help you diagnose shader compilation defects in your application.
DevTools detects frames lost due to shader compilation
With this new feature, DevTools can detect frames that you have lost due to shader compilation so that you can fix the problem. To run your application as if it were the first time (before your shader cache is filled, just like any user), use the flutter run with the –purge-persistent-cache flag. This clears the cache to ensure that you recreate the environment that the user saw when they “first ran” or “re-opened” (iOS). This feature is still under development, so please document any problems you find or any improvements we can make to help debug shader compiled garbage.
In addition, when you track CPU performance issues in your application, you may have been swamped with profiling data from native code in Dart and Flutter libraries and/or engines. If you want to turn any of these off to focus on your own code, you can do so with the new CPU profiler feature (#3236), which enables you to hide profiler information from any of these sources.
For any categories you don’t filter out, they are now color-coded (#3310, #3324) so you can easily see which parts of the CPU block diagram come from which parts of the system.
Use color frame diagrams to identify code activity for Dart and Flutter within your application and native applications
Performance isn’t the only thing you have to debug. This version of DevTools comes with an update to the Widget Inspector, which allows you to hover over a Widget to evaluate the object, view properties, Widget status, and more.
Also, when you select a Widget, it automatically pops up in the new Widget Inspector Console, where you can explore the Widget’s properties.
You can also evaluate the expression from the console while pausing at the breakpoint.
In addition to new features, Widget Inspector gets a facelift. In order to make DevTools a more useful destination for understanding and debugging Flutter applications, we worked with Finland’s creative technology agency Codemate to make some updates.
The Flutter DevTools is polished for a user experience that is easier to use
In this screenshot, you can see the following changes.
- Better communicate what debug toggle buttons do — they have new ICONS, task-oriented labels, and rich tooltips that describe what they do and when to use them. Each tooltip is further linked to detailed documentation of that feature.
- Easier to scan and locate gadgets of interest – Frequently used gadgets in the Flutter framework now display ICONS in the gadget tree view to the left of the inspector. They are further color-coded according to their category. For example, layout widgets are shown in blue and content widgets are shown in 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 widget from layout explorer and widget tree. For example, the “column” widget in the screenshot below has a blue background in layout Explorer and a blue icon in the Widget tree view.
We’d love to hear your thoughts on any issues these updates have created, or any other improvements we can make to make sure DevTools works great. These highlights are just the beginning. For all the new DevTools content in This version of Flutter, see the release notes.
- Description of Flutter DevTools version 2.3.2
- Release notes for Flutter DevTools 2.4.0
- Release notes for Flutter DevTools 2.6.0
IntelliJ/Android Studio: Integration testing, test coverage, and icon preview
The IntelliJ/Android Studio plugin for Flutter has also made some improvements in this release, starting with the ability to run integration tests (#5459). Integration tests are full application tests that run on the device, under the Integration_test directory, and use the same testWidgets() functionality as in widget unit tests.
Integrate test your Flutter application in IntelliJ/Android Studio
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 to start integration tests and connect a device for testing. Run configuration allows you to run tests, including setting breakpoints, stepping, and so on.
Additionally, The latest IJ/AS plugin for Flutter allows you to see coverage information for unit test and integration test runs. You can access this information through the toolbar button next to the Debug button.
Coverage information is shown in red and green bars in the editor’s grooves. In this example, lines 9-13 are tested, but lines 3 and 4 are not.
The latest release also includes a new ability to preview ICONS used in packages from Pub.dev, which are built around TrueType font files (#5504, #5595, #5677, #5704), just as Material and Cupertino ICONS support preview.
Icon preview in IntelliJ/Android Studio
To enable icon preview, you need to tell the plugin which packages you are using. There is a new text field in the plug-in’s Settings/preferences page.
Note that this applies to ICONS defined as static constants in a class, as shown in the sample code in the screen capture. It does not work on expressions such as lineicons.addressbook () or lineicons.values [‘code’]. If you are the author of an icon pack that does not apply to this feature, create a question.
There are also many updates to the IntelliJ/Android Studio plugin for Flutter, which you can read about in the release notes.
- The Flutter IntelliJ Plugin M57 is released
- Release of the Flutter IntelliJ Plugin M58
- Release of the Flutter IntelliJ Plugin M59
- The Flutter IntelliJ Plugin M60 is released
Visual Studio Code: Dependencies, full fixes, and test runner
The Visual Studio Code plugin for Flutter has also been improved in this release, starting with two new commands “Dart: Add Dependency” and “Dart: Add Dev Dependency” (#3306, #3474).
Add the Dart dependency in Visual Studio Code
These commands provide functionality similar to what the Jeroen Meijer’s Pubspec Assist plug-in has provided for some time. Out of the box, these new commands provide a list of package types to filters that are periodically retrieved from pub.dev. You may also be interested in the “Fix All” commands (#3445, #3469), which are available for Dart files and can fix all the same problems as the Dart fix in one step for the currently open file.
Use the Flutter repair rules to fix all known problems in your code
This can also be set to run on save time by adding source.fixAll in the editor. CodeActionsOnSave VS Code Settings.
Or, if you want to try the preview function, you can enable the dart. PreviewVsCodeTestRunner Settings, see the dart and Flutter test by new Visual Studio Code running test runner.
Test your Dart and Flutter Code using the new Visual Studio Code test runner
The Visual Studio Code test runner looks a little different from the current Dart and Flutter test runners and will persist the results in a different session. The Visual Studio Code Test runner also added a new groove icon that shows the final status of the test, which can be clicked to run the test (or right-click on the context menu).
In future releases, the existing Dart and Flutter test runners will be removed in favor of the new Visual Studio Code test runners.
This is just the tip of the iceberg of new features and fixes for Visual Studio Code. For all the details, check out the release notes.
- V3.26 VS Code test runner integration, Flutter creation Settings…
- V3.25 Additional dependency management improvements, fix all at file/save time,…
- V3.24 dependency tree improvements, easier launch configuration, editor improvements
- V3.23 Configuration file mode improvements, improved dependency tree, improved LSP
Tools: Exceptions, new application templates, and Pigeon 1.0
In previous versions of Flutter, you might get frustrated with some exceptions that you expected to be unhandled so that you could trigger the debugger and find out where they came from, only to find that the Flutter framework did not let the exception through to trigger the “unhandled expectation” handler in the debugger. In this release, the debugger can now correctly interrupt unhandled exceptions that were previously just caught by the framework (#17007). This improves the debugging experience because your debugger can now point directly to throw trips in their code, rather than to a random line deep in the frame. A related new feature enables you to determine whether FutureBuilder should rethrow or swallow errors (#84308). This should give you a lot of extra exceptions to help you track down problems in the Flutter app.
The Counter application template has been available since the creation of Flutter and has many advantages: it demonstrates many features of the Dart language, demonstrates several key Flutter concepts, and is small enough to fit into a single file even with many explanatory comments. What it does not do, however, is provide a particularly good springboard for real-world applications of Flutter. In this release, a new template (#83530) is available with the following command.
$ flutter create -t skeleton my_app
Running new Flutter skeleton template
The skeleton template generates a two-page list view of the Flutter application (with detailed view), following community best practices. It was developed with extensive internal and external review to provide a better foundation to build a production-quality application and support the following features.
- Use ChangeNotifier to coordinate multiple widgets
- By default, localization information is generated using arB files
- Include a sample image and create 1x, 2X, and 3X folders for the image asset
- Use a “feature first” folder organization
- Support for sharing preferences
- Support light and dark themes
- Supports navigation between multiple pages
As Flutter best practices evolve over time, hopefully this new template will evolve as well.
If, at the other end of the spectrum, you’re developing a plug-in rather than an app, you might be interested in Pigeon version 1.0. Pigeon is a code generation tool for generating type-safe interop code between Flutter and its host platform. It allows you to define your plug-in’s API description and generate skeleton code for Dart, Java, and Objective-C (available for Kotlin and Swift, respectively).
A sample of generated Pigeon code
Pigeon has been used in some of the Flutter team’s plug-ins. This release provides more useful error messages, adds support for generics, primitive data types as parameter and return types, and multiple parameters, which is expected to be used more in the future. If you want to use Pigeon in your own plugin or in projects added to your app, you can find more information on the Pigeon Plugin page.
Breakthrough change and obsolescence
Here are the breakthrough changes in Flutter 2.5.
- Default drag scroll device
- Deprecated apis have been removed since v2.2
- Importing software package: Flutter_lints
- The accent property of ThemeData is deprecated
- Clean up the gesture recognizer
- Collate to replace AnimationSheetBuilder. The display
- Render platform views in the network using HTML slots
- Migrate LogicalKeySet to SingleActivator
For a full list of breakthrough changes since version 1.17, see flutter. Dev.
As we continue to update Flutter Fix (available in your IDE and via the Dart Fix command), we have a total of 157 rules that will automatically migrate your code affected by these or past breakthrough changes and any deprecations. As always, we are grateful to the community for providing tests that helped us identify these breakthrough changes. To learn more, check out our Breakthrough Change Policy.
In addition, with the release of Flutter 2.5, we will drop support for iOS 8, as announced in September 2020. Ditching support for iOS 8, which had less than 1% of the market, allowed the Flutter team to focus on a wider range of new platforms. Deprecation means that these platforms may work, but we will not be testing new versions of Flutter or plug-ins on these platforms. You can see a list of currently supported Flutter platforms on flutter. Dev.
conclusion
Finally, as always, thanks to the Flutter community around the world for making this possible. To the hundreds of developers who contributed and reviewed over 1,000 PR in this update, cheers to each and every one of you for your efforts. We’re working together to transform the application development process for developers around the world, so you can deploy more, faster, and more from one code base to the platforms you care about.
Stay tuned for more updates from our Flutter team at Google. The year is not over yet!
www.deepl.com translation