Dart 2.10 release: one step closer to null-safety

image <img data-lazyloaded="1" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MDAwIiBoZWlnaHQ9IjExOTAiIHZpZXdCb3g9IjAgMCA0MDAwIDExOTAiPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9IiNmZWZlZmYiLz48L3N2Zz4=" width="4000" height="1190" decoding="async" src = "https://habrastorage.org/webt/bx/6z/zo/bx6zzobmc1fbzqkkzocurdk7gsg.jpeg" />‘></p><p></p><div class=

The Dart language team is gradually approaching one of the most major releases – null-safety. Many market leaders have this feature, including Kotlin and TypeScript. For obvious reasons, this release cannot be made in the form of a switch: one day and a simple update. A community that has picked up speed and released a huge number of packages will no longer be able to upgrade to the major version at the click of a finger. Therefore, this process is progressive and not as fast as we would like. Nevertheless, there is no reason to doubt that the language will become much better and more convenient pretty soon!

We at Wrike could not ignore the update to the Dart 2.10 release and are translating the article from the official blog Dartlang.

New, unified dart for all key tasks. And also an update on the null-safety timeline and migration principles.

By Michael Thomsen & Kevin Moore

Today we are announcing the new Dart version 2.10 (two-dot-ten). This release introduces a new unified Dart: a single tool for all possible developer tasks, such as creating projects, analyzing and formatting code, testing and compiling applications. We have updated information on the milestones for null-safety, as well as guidelines for migrating existing code.

New Unified Dart Developer Tool

Dart is at the heart of the Flutter SDK: it not only provides the language and runtime used in Flutter applications, but also supports many basic developer tasks such as formatting, parsing, and testing code. However, while Flutter has always had one universal developer tool (team flutter), Dart has historically had many small tools (like dartfmt and dartanalyzer). Dart 2.10 has got a new, unified developer tool dartvery similar to the tool flutter… This new tool supports all basic tasks such as creating new projects and packages, parsing and formatting code, and running, compiling, and testing projects. To use this tool, just run the command dart:

Flutter includes the new Dart in the Flutter SDK. From version Flutter 1.22 SDK, directory <flutter-sdk>/bin (which is most often found in PATH) contains commands and flutterand dart… If you are developing on both Flutter and Dart, you get the power of both from the same package Flutter SDK without having to install anything else.

If you want to download and install a different Dart SDK (if you require a different version), make sure the SDK of the tool dartwhich you want to use by default is at the beginning of the environment variable PATH

In the next stable releases, we plan to expand the functionality of the tool dart and gradually abandon smaller instruments (dartdoc, dartfmt, dartanalyzer etc.). In 2021, we plan to release the Dart SDK, containing exclusively the tool dart… We recommend that you switch to the new tool when running Dart commands now, whether manually in the terminal or on build systems (CI), and tell usif something is missing or not working as it should.

About null-safety

We’ve done a good job with null-safety since we launched first technical preview… In total null-safety, we see a tool to prevent hard-to-find null errors, as well as an added bonus to improving performance. If you want to know more, we recommend our new page Understanding null safety… If you prefer a short video, watch the null safety video from the event Flutter daywhich took place several months ago.

When will null-safety be ready for use? Here’s our prediction:

  1. Flutter work with technical preview 2: We’ve successfully ported most of Flutter. We expect that soon – probably within the next month – the Flutter environment will be fully ported, and thus we will be ready to experiment with Flutter. You will be able to try null-safety in Flutter and do a trial migration of your Flutter apps and packages. You will need to use experimental flag… Do not use experimental features in production and do not publish ported packages.

  2. Early package migration with beta: later this year, we will finalize the performance improvement and provide enough tests to ensure that the feature works as expected and that backward compatibility is reliable. By then we will publish the beta version of this feature and you will not need to pass the experimental flag. Hopefully the owners of the packages will start migrating them to null-safety, thereby making a final round of testing to see if this feature is ready for stable release.

  3. Use in production stable: depending on feedback from the beta launch, we will fix any remaining issues and then publish them to stable. It is difficult to name a specific date, but we are thinking about the beginning of next year. As soon as this feature becomes stable, we hope for widespread adoption of null safety by applications published in stores, and by many of the packages published in pub.dev in stable versions.

Principles for the transition to null-safety

We would like to share our guiding principles for null-safety migration.

Move when you’re ready

Null-safety is a fundamental change to the Dart system. This changes the basics of declaring variables because we decided make variables non-null by default:

Such a fundamental change would be devastating if we insisted on a forced transition. We want you to pick the right timing yourself, so null-safety is an optional feature: you can use the latest versions of Dart and Flutter without having to enable null-safety. You can even have a dependency between packages that have null-safety enabled and apps or packages that haven’t enabled it yet.

Proceed gradually, in order

We strongly recommend moving the code in order, starting with the leaves of the dependency graph. For example, if C depends on B, which depends on A, first move A to null-safety, then B, then C. This order applies regardless of whether A, B, and C are libraries, packages, or applications.

Why is order so important? You may have some success migrating your code before migrating your dependencies, but you run the risk of having to re-migrate if your dependencies change their APIs during the migration process. We will provide tools to help you find out which dependencies were successfully ported. If you are the author of a package, then to avoid the risk of breaking the API, wait until all your dependencies have been migrated before publishing the null-safe version.

Use automated tools to reduce migration costs

When your dependencies are ready and you decide to migrate, you can use our migration tool. It works by examining all of your existing code, looking for which declarations can be non-nullable (they remain unchanged) and which must be nullable (need a token ? null in the declaration).

The migration tool is interactive, so you can view the properties it has defined. If you disagree with any of the tool’s conclusions, you can add null hints to change the output. For example, if you want to make the API non-nullable, even if some refactoring is required, you can tell the tool about it and rerun the migration analysis. Adding just a few migration tips can have a huge impact on the quality of the transition.

Get the full benefit when fully utilized

Once whole your code – and the packages it depends on – will be ported, it can run with guaranteed null-safety. Up to this point, your code will run and compile just like it does now, but absolute null-safety will ensure full runtime verification and compiler optimizations. Running tests with full null-safety can avoid runtime null assignment problems, and compiling applications with null-safety ensures that you get optimizations immediately and in the future, such as smaller compiled output and faster execution.

Further actions

New developer tool dart available today in Dart SDK 2.10 and in Flutter SDK 1.22. If you already have the Flutter SDK, you can get the Dart SDK using the command dartby simply running flutter upgrade; this will give you the Flutter 1.22 SDK which has Dart 2.10 built in. We recommend that you switch to a new instrument immediately. dart and to contact usif something is missing or not working properly.

We’ll have more news on null-safety soon. Most likely within the next month, when our friends on the Flutter team will have a null-safety-enabled Flutter framework ready to experiment. Follow the blog updates Flutter… Until then, you can experiment with null-safe Dart code with DartPad with null-safety and learn more about function design in null-safety documentation

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *