Discussion:
[dart-misc] Support Dart 1 and 2 with dart2_constant
'Natalie Weizenbaum' via Dart Misc
2018-04-02 23:08:47 UTC
Permalink
Hey folks,

As Leaf announced last month
<https://groups.google.com/a/dartlang.org/forum/#!topic/misc/l0oYjyyFD7c>,
SCREAMING_CAPS constants are deprecated in Dart 2 in favor of camelCase
names, and will be removed entirely in an upcoming release. Unfortunately,
this means that capitalized constants won't be usable in Dart 1 and
camel-case constants won't be usable in Dart 2.

For packages that want to continue supporting both Dart 1 and Dart 2, I've
just released a utility package called dart2_constant
<https://pub.dartlang.org/packages/dart2_constant>. It contains a library
for each dart: library that provides camel-case constants with the same
names as that dart: library's Dart 2 constants. However, it's compatible
with both Dart 1 *and* Dart 2, so it can be used to polyfill the new
constant names on old Dart implementations. These libraries should be
imported using a prefix so as to avoid colliding with core library names:

import 'package:dart2_constant/convert.dart' as convert;
String decodeUtf8(List<int> bytes) => convert.utf8.decode(bytes);


Note that dart2_constant even supports constants that haven't yet migrated
in the core libraries, such as those in dart:io and dart:html. These are
provided for compatibility with future SDK changes.

Enjoy!
- Natalie
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CAKDS1k79nQ8EZQ8%3D5ycuC8719L04kPFfQOvWgT%2BWy8w27qZdmg%40mail.gmail.com.
Rob Becker
2018-04-03 03:36:00 UTC
Permalink
Hey! That's great. Thanks!
Post by 'Natalie Weizenbaum' via Dart Misc
Hey folks,
As Leaf announced last month
<https://groups.google.com/a/dartlang.org/forum/#!topic/misc/l0oYjyyFD7c>,
SCREAMING_CAPS constants are deprecated in Dart 2 in favor of camelCase
names, and will be removed entirely in an upcoming release. Unfortunately,
this means that capitalized constants won't be usable in Dart 1 and
camel-case constants won't be usable in Dart 2.
For packages that want to continue supporting both Dart 1 and Dart 2, I've
just released a utility package called dart2_constant
<https://pub.dartlang.org/packages/dart2_constant>. It contains a library
for each dart: library that provides camel-case constants with the same
names as that dart: library's Dart 2 constants. However, it's compatible
with both Dart 1 *and* Dart 2, so it can be used to polyfill the new
constant names on old Dart implementations. These libraries should be
import 'package:dart2_constant/convert.dart' as convert;
String decodeUtf8(List<int> bytes) => convert.utf8.decode(bytes);
Note that dart2_constant even supports constants that haven't yet
migrated in the core libraries, such as those in dart:io and dart:html.
These are provided for compatibility with future SDK changes.
Enjoy!
- Natalie
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/62b4fd65-3f67-42e5-b988-9e478a3c272a%40dartlang.org.
John Ryan
2018-06-14 17:44:04 UTC
Permalink
Natatlie,

Would this approach also work with other parts of the Dart SDK? (I'm
imagining the new `tryParse` functions in particular.)

I think this method could also be useful for cases where parts of the Dart
SDK are missing. Flutter removes the dart:js package from it's version of
the dart SDK, so `allowInterop` and other dart:js utilities show up as
analyzer warnings in Web + Flutter projects.
Post by 'Natalie Weizenbaum' via Dart Misc
Hey folks,
As Leaf announced last month
<https://groups.google.com/a/dartlang.org/forum/#!topic/misc/l0oYjyyFD7c>,
SCREAMING_CAPS constants are deprecated in Dart 2 in favor of camelCase
names, and will be removed entirely in an upcoming release. Unfortunately,
this means that capitalized constants won't be usable in Dart 1 and
camel-case constants won't be usable in Dart 2.
For packages that want to continue supporting both Dart 1 and Dart 2, I've
just released a utility package called dart2_constant
<https://pub.dartlang.org/packages/dart2_constant>. It contains a library
for each dart: library that provides camel-case constants with the same
names as that dart: library's Dart 2 constants. However, it's compatible
with both Dart 1 *and* Dart 2, so it can be used to polyfill the new
constant names on old Dart implementations. These libraries should be
import 'package:dart2_constant/convert.dart' as convert;
String decodeUtf8(List<int> bytes) => convert.utf8.decode(bytes);
Note that dart2_constant even supports constants that haven't yet
migrated in the core libraries, such as those in dart:io and dart:html.
These are provided for compatibility with future SDK changes.
Enjoy!
- Natalie
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/a1cc3afb-9aa3-46b7-b9e2-7b5f68a18664%40dartlang.org.
'Natalie Weizenbaum' via Dart Misc
2018-06-14 21:39:11 UTC
Permalink
It's certainly possible to write packages that polyfill new features in
Dart 2. Polyfilling differences between SDKs is more difficult; you can't
rely on the version solver to give your users different code on Flutter
than they get in the web because any given chunk of code may be used in
either or both contexts.
Post by John Ryan
Natatlie,
Would this approach also work with other parts of the Dart SDK? (I'm
imagining the new `tryParse` functions in particular.)
I think this method could also be useful for cases where parts of the Dart
SDK are missing. Flutter removes the dart:js package from it's version of
the dart SDK, so `allowInterop` and other dart:js utilities show up as
analyzer warnings in Web + Flutter projects.
Post by 'Natalie Weizenbaum' via Dart Misc
Hey folks,
As Leaf announced last month
<https://groups.google.com/a/dartlang.org/forum/#!topic/misc/l0oYjyyFD7c>,
SCREAMING_CAPS constants are deprecated in Dart 2 in favor of camelCase
names, and will be removed entirely in an upcoming release. Unfortunately,
this means that capitalized constants won't be usable in Dart 1 and
camel-case constants won't be usable in Dart 2.
For packages that want to continue supporting both Dart 1 and Dart 2,
I've just released a utility package called dart2_constant
<https://pub.dartlang.org/packages/dart2_constant>. It contains a
library for each dart: library that provides camel-case constants with
the same names as that dart: library's Dart 2 constants. However, it's
compatible with both Dart 1 *and* Dart 2, so it can be used to polyfill
the new constant names on old Dart implementations. These libraries should
import 'package:dart2_constant/convert.dart' as convert;
String decodeUtf8(List<int> bytes) => convert.utf8.decode(bytes);
Note that dart2_constant even supports constants that haven't yet
migrated in the core libraries, such as those in dart:io and dart:html.
These are provided for compatibility with future SDK changes.
Enjoy!
- Natalie
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/a/dartlang.org/d/msgid/misc/a1cc3afb-9aa3-46b7-b9e2-7b5f68a18664%40dartlang.org
<https://groups.google.com/a/dartlang.org/d/msgid/misc/a1cc3afb-9aa3-46b7-b9e2-7b5f68a18664%40dartlang.org?utm_medium=email&utm_source=footer>
.
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CAKDS1k6n0zV2yyy_9-dhXQmT4zNu-fLuEQocgW%3Dww4mO%3D7F8Qg%40mail.gmail.com.
John Ryan
2018-06-14 21:54:42 UTC
Permalink
Thanks for the clarification!

For those who use a mono-repo with Dart 1 and Dart 2 packages, we've
published a polyfill package for tryParse here:
https://pub.dartlang.org/packages/dart2_tryparse and a package for
flutter's missing dart:js issue:
https://pub.dartlang.org/packages/flutter_js_polyfill. Now our
multi-module setup in IntelliJ has zero warnings. Here's a description of
how we set up multiple IntelliJ modules for those who are curious:
https://github.com/apptreesoftware/letsvote#intellj-multi-module-setup

fair warning: flutter_js_polyfill only covers a small subset of the dart:js
api.

On Thu, Jun 14, 2018 at 2:39 PM 'Natalie Weizenbaum' via Dart Misc <
Post by 'Natalie Weizenbaum' via Dart Misc
It's certainly possible to write packages that polyfill new features in
Dart 2. Polyfilling differences between SDKs is more difficult; you can't
rely on the version solver to give your users different code on Flutter
than they get in the web because any given chunk of code may be used in
either or both contexts.
Post by John Ryan
Natatlie,
Would this approach also work with other parts of the Dart SDK? (I'm
imagining the new `tryParse` functions in particular.)
I think this method could also be useful for cases where parts of the
Dart SDK are missing. Flutter removes the dart:js package from it's
version of the dart SDK, so `allowInterop` and other dart:js utilities show
up as analyzer warnings in Web + Flutter projects.
Post by 'Natalie Weizenbaum' via Dart Misc
Hey folks,
As Leaf announced last month
<https://groups.google.com/a/dartlang.org/forum/#!topic/misc/l0oYjyyFD7c>,
SCREAMING_CAPS constants are deprecated in Dart 2 in favor of camelCase
names, and will be removed entirely in an upcoming release. Unfortunately,
this means that capitalized constants won't be usable in Dart 1 and
camel-case constants won't be usable in Dart 2.
For packages that want to continue supporting both Dart 1 and Dart 2,
I've just released a utility package called dart2_constant
<https://pub.dartlang.org/packages/dart2_constant>. It contains a
library for each dart: library that provides camel-case constants with
the same names as that dart: library's Dart 2 constants. However, it's
compatible with both Dart 1 *and* Dart 2, so it can be used to polyfill
the new constant names on old Dart implementations. These libraries should
import 'package:dart2_constant/convert.dart' as convert;
String decodeUtf8(List<int> bytes) => convert.utf8.decode(bytes);
Note that dart2_constant even supports constants that haven't yet
migrated in the core libraries, such as those in dart:io and dart:html.
These are provided for compatibility with future SDK changes.
Enjoy!
- Natalie
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups
Post by John Ryan
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/a/dartlang.org/d/msgid/misc/a1cc3afb-9aa3-46b7-b9e2-7b5f68a18664%40dartlang.org
<https://groups.google.com/a/dartlang.org/d/msgid/misc/a1cc3afb-9aa3-46b7-b9e2-7b5f68a18664%40dartlang.org?utm_medium=email&utm_source=footer>
.
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to a topic in the
Google Groups "Dart Misc" group.
To unsubscribe from this topic, visit
https://groups.google.com/a/dartlang.org/d/topic/misc/yYJIiNHwZpk/unsubscribe
.
To unsubscribe from this group and all its topics, send an email to
To view this discussion on the web visit
https://groups.google.com/a/dartlang.org/d/msgid/misc/CAKDS1k6n0zV2yyy_9-dhXQmT4zNu-fLuEQocgW%3Dww4mO%3D7F8Qg%40mail.gmail.com
<https://groups.google.com/a/dartlang.org/d/msgid/misc/CAKDS1k6n0zV2yyy_9-dhXQmT4zNu-fLuEQocgW%3Dww4mO%3D7F8Qg%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
--
John Ryan
***@gmail.com
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CAPZZe1yf8-u2aziHQh10ob7gFaryM36fiKufPNhb%3DeBmBNXYnQ%40mail.gmail.com.
Loading...