Extension methods
Extension methods, introduced in Dart 2.7,are a way to add functionality to existing libraries.You might use extension methods without even knowing it.For example, when you use code completion in an IDE,it suggests extension methods alongside regular methods.
Here’s an example of using an extension method on String
named parseInt()
that’s defined in string_apis.dart
:
import string_apis.dart';
...
print('42'.padLeft(5)); // Use a String method.
print('42'.parseInt()); // Use an extension method.
For details of using and implementing extension methods, see theextension methods page.