Search⌘ K
AI Features

Challenge: Extension Methods

Explore how to create and apply extension methods in Dart by implementing convertMilesTokms() on double values. This lesson helps you enhance Dart data types with custom functionality to solve real-world conversion challenges.

We'll cover the following...

Problem Statement

Implement an extension method convertMilesTokms() on data type double to convert miles into kilometers.

Dart
extension on double {
//CHALLENGE #1: Add extenstion method `convertMileToKm()`
//Hint: 1 Mile = 1.6 KM
}
void main() {
double mile = 2;
//CHALLENGE #2: Print kms equivalent for given `mile` above using `convertMileToKm()` extension method.
double kms = 0;
print(kms);
}

Check out the solution in the next lesson.