The collection
package, that is maintained by the Dart team, adopted (1.15.0-nullsafety.4
) several extension methods that causes problems with Supercharged extension methods.
The release 2.x.x
of supercharged
(or supercharged_dart
) addresses these changes. This document will guide you 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.
You need to import the collection
package that is maintained by the Dart team:
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].sortedBy<num>((a) => a)
Working with Strings is quite the same:
['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].mapIndexedSC((index, element) => /* ... */)