Dart's own collection package adopted (in 1.15.0
) several extension methods that were previously covered by Supercharged.
This causes naming conflicts when using both packages.
As a general strategy Supercharged will favour Dart's implementations and rename it's own API.
This document will guide your through the migration process.
In order to keep compile issues as low as possible, Supercharged renamed all affected methods by adding the suffix SC
to the method name:
sortedBy
renamed tosortedBySC
sortedByNum
renamed tosortedByNumSC
sortedByString
renamed tosortedByStringSC
sum
renamed tosumSC
average
renamed toaverageSC
firstOrNull
renamed tofirstOrNullSC
lastOrNull
renamed tolastOrNullSC
forEachIndexed
renamed toforEachIndexedSC
mapIndexed
renamed tomapIndexedSC
In a first step of migration you just need to identify these methods in your code by looking for compile errors. Then add the suffix SC
to the method name. It will solve the compile error and mark the used method as deprecated.
Now you are free to stop here and focus on other issues demanded by the general null-safety migration process.
Once your application compiles just perfectly, you can focus on further adoption of Dart's native methods.
The collection package is implicitly available in Flutter or Dart projects. Make sure to import it using:
import 'package:collection/collection.dart';
Instead of comparing two values inside a function, you just return a value of a single item. You also need to pass in a type, that's implementing a comparator, so it knows the natural order.
[3, 1, 5, 9, 7].sortedBySC((a, b) => a.compareTo(b))
can be migrated into
[3, 1, 5, 9, 7].sorted((a, b) => a.compareTo(b))
or
// for numeric values
[3, 1, 5, 9, 7].sortedBy<num>((a) => a)
// for string values
['b', 'c', 'a'].sortedBy<String>((s) => s)
The dart equivalent is nearly identical. Just remove the parenthesis since Dart uses only a getter method.
[1, 2, 3].sumSC()
[1, 2, 3].averageSC()
can be migrated into
[1, 2, 3].sum
[1, 2, 3].average
The dart equivalent is nearly identical. Just remove the parenthesis since Dart uses only a getter method.
['a', 'b'].firstOrNullSC()
['a', 'b'].lastOrNullSC()
can be migrated into
['a', 'b'].firstOrNull
['a', 'b'].lastOrNull
The method signature of Dart's native method is identical to the one in Supercharged.
[1, 2, 3].forEachIndexed((index, value) {
// ...
});
Be cautious on this one. The name is identical, but the positions of the parameters are swapped.
[1, 2, 3].mapIndexedSC((element, index) => /* ... */)
can be migrated into
[1, 2, 3].mapIndexed((index, element) => /* ... */)