Dart
Published in

Dart

Announcing Dart 2.15

Fast concurrency, constructor tear-offs, improved enums, and more

Graphic listing new 2.15 features

Fast concurrency with worker isolates

New language feature: Constructor tear-offs

class Greeter {
final String name;
Greeter(this.name);

void greet(String who) {
print('$name says: Hello $who!');
}
}
void main() {
final m = Greeter('Michael');
final g = m.greet; // g holds a function pointer to m.greet.
g('Leaf'); // Invokes and prints "Michael says: Hello Leaf!"
}
final m = Greeter('Michael');['Lasse', 'Bob', 'Erik'].forEach(m.greet);// Prints "Michael says: Hello Lasse!", "Michael says: Hello Bob!",
// "Michael says: Hello Erik!"
class FruitWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: ['Apple', 'Orange'].map(Text.new).toList());
}
}

Related language changes

T id<T>(T value) => value;
var intId = id<int>; // New in 2.15.
int Function(int) intId = id; // Pre-2.15 workaround.
const fo = id; // Tear off `id`, creating a function object.
const c1 = fo<int>; // New in 2.15; error before.
var y = List; // Already supported.
var z = List<int>; // New in 2.15.
var z = typeOf<List<int>>(); // Pre-2.15 workaround.

Improved enums in the dart:core library

enum MyEnum {
one, two, three
}
void main() {
print(MyEnum.one.name); // Prints "one".
}
print(MyEnum.values.byName('two') == MyEnum.two);  // Prints "true".
final map = MyEnum.values.asNameMap(); 
print(map['three'] == MyEnum.three); // Prints "true".

Compressed pointers

Dart DevTools included in the Dart SDK

New pub features for package publishers

Publishing my_package 1.0.0 to https://pub.dartlang.org:
Package validation found the following errors:
* line 1, column 1 of lib/key.pem: Potential leak of Private Key detected.

1 │ ┌ - - -BEGIN PRIVATE KEY - - -
2 │ │ H0M6xpM2q+53wmsN/eYLdgtjgBd3DBmHtPilCkiFICXyaA8z9LkJ
3 │ └ - - -END PRIVATE KEY - - -

* line 2, column 23 of lib/my_package.dart: Potential leak of Google OAuth Refresh Token detected.

2 │ final refreshToken = "1//042ys8uoFwZrkCgYIARAAGAQSNwF-L9IrXmFYE-sfKefSpoCnyqEcsHX97Y90KY-p8TPYPPnY2IPgRXdy0QeVw7URuF5u9oUeIF0";
Screenshot of the package retraction UI
$ dart pub get
Resolving dependencies…
mypkg 0.0.181-buggy (retracted, 0.0.182-fixed available)
Got dependencies!

Security analysis for detecting bidirectional Unicode characters (CVE-2021–22567)

main() {
final accessLevel = 'user';
if (accessLevel == 'user‮ .⁦// Check if admin⁩ ⁦') {
print('You are a regular user.');
} else {
print('You are an admin.');
}
}
$ dart analyze
Analyzing cvetest... 2.6s
info • bin/cvetest.dart:4:27 • The Unicode code point 'U+202E'
changes the appearance of text from how it's interpreted
by the compiler. Try removing the code point or using the
Unicode escape sequence '\u202E'. •
text_direction_code_point_in_literal
// ignore: text_direction_code_point_in_literal

Pub.dev credentials vulnerability when using third-party pub servers (CVE-2021–22568)

Closing comments

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Michael Thomsen

Product Manager working on Dart and Flutter. Helping developers is my passion!