Dart 2 Core Library Deprecation: SCREAMING CAPS CONSTANTS

334 views
Skip to first unread message

Leaf Petersen

unread,
Mar 7, 2018, 8:15:25 PM3/7/18
to Flutter Dev
What's being deprecated?

Top level constants in the Dart 1 core libraries were named using an all caps naming convention:

const JsonCodec JSON = const JsonCodec();

This is inconsistent with standard Dart style.  In Dart 2, we have (already) added camel case versions of constants to the library, and we are now deprecating the old constants.

const JsonCodec json = const JsonCodec();
@Deprecated("Use json instead")
const JsonCodec JSON = json;

What will break?

Nothing, but you may get new deprecation warnings from the analyzer if you use the old constant names.

info: 'JSON' is deprecated and shouldn't be used. (deprecated_member_use at scratch.dart:12)

How do I get rid of the deprecation warnings?

Use the new constant names (generally just the camel case version of the old name).  

The library documentation for the old name shows the new name to use.

You can also use "go to definition" in the IDE to go to the definition of the old constant, which references the new name.  

Why is this change being made?

SCREAMING CAPS ARE INCONSISTENT WITH STANDARD DART STYLE, AND DON'T LOOK VERY GOOD EITHER.

When will the old constants go away?

We hope to remove the old constants in a future release, but because of the very breaking nature of this change we do not anticipate doing this for the Dart 2 release.  We plan to continue to work towards removal of the old constants in a future release, possibly with automated tooling to help with the migration.

This has landed in bleeding edge, and will be released in the next Dart SDK version (probably 2.0.0-dev.34.0) and rolled into Flutter bleeding edge shortly thereafter.

As usual, please reach out to me here or offline with any concerns, and/or with help resolving any issues after this change has landed.

thanks,
-leaf



Leaf Petersen

unread,
Mar 29, 2018, 7:35:43 PM3/29/18
to Flutter Dev
TLDR: Please run the dart2_fix tool on your flutter projects and dart packages ASAP to prepare your code for the removal of the Dart 1 deprecated constants.

Thanks to quick work by Devon Carew to implement tooling to support this change, we are planning to land the removal of the deprecated Dart 1 constants sometime between Dart Beta 3 (April 12) and Beta 4 (May 15).  This change will roll into flutter sometime after Dart Beta 4 is released.  You can run dart2_fix right now to ensure that your code won't break when this change rolls out.

To upgrade your flutter code, you can (and should!) do the following:

Activate the upgrade package:
  flutter packages pub global activate dart2_fix

Run the tool to see what changes will be made:
  flutter packages pub global run dart2_fix

Apply the fixes to your package:
  flutter packages pub global run dart2_fix --apply

Run the analyzer to check for remaining deprecations or new errors:
  flutter analyze

In most cases, the migration tool will eliminate all of the deprecation warnings from your code.  There are a few cases which are not handled by the tool, and in some (hopefully rare) cases, some subsequent fixup of the code might be required (usually because of a conflict between a local variable or field and one of the new constant names).

See the documentation for dart2_fix for more information and details.  And as always, please follow up here with any problems or issues.

thanks,
-leaf

Ian Hickson

unread,
May 4, 2018, 2:13:44 PM5/4/18
to Flutter Dev
An update on this change:

As far as we're aware, all the constants that are going to get renamed are now deprecated on Flutter's master branch. We encourage you to run the script mentioned below and report your findings. Right now we expect the next beta-branch release to still include the deprecated constants and the beta-branch release after that to probably have them removed, though the precise timing is still in the air as we try to update packages in the ecosystem to use the lowercase constants.

Please don't hesitate to reach out if you run into any issues here.

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

--
Ian Hickson

😸

Leaf Petersen

unread,
Jul 18, 2018, 1:02:55 PM7/18/18
to Flutter Dev
The patch removing the deprecated constants has landed in the Dart SDK bleeding edge and will be included in the next roll of the Dart SDK into Flutter (I would expect within a few days).  If you haven't done so already, please update your code and ensure that all of your package dependencies have been updated. 

-leaf
Reply all
Reply to author
Forward
0 new messages