For this recipe, first, we will separate the functions we have created in the area.dart file into two separate files using the part and part of keywords. Then, for the dependency, we will use a Git repository instead of a package inside the project's folder:
- In your package's lib folder, create a new file, called rectangle.dart.
- Create another file, called triangle.dart.
- In the rectangle.dart file, at the top of the file, specify that this is part of the area package:
part of area;
- Under the part of statement, paste the method to calculate the area of the rectangle and remove it from area.dart. You will see an error on the NumberFormat method; this is expected, and we will solve this shortly:
String calculateAreaRect(double width, double height) {
double result = width * height;
final formatter = NumberFormat('#.####');
return formatter.format(result);
}
- Repeat the process for the triangle.dart file. The code for the triangle...