core_extras

Provides a set of additional types, utilities and extensions to Dart core packages Some examples are provided below.

Map Extensions

valueOf

Returns the value of the given key, if it exists, and adds it if it doesn't

final animalRatings = { "aardvark": 1, "baboon": 2 };
final aardvarkRating = animalRatings.valueOf("aardvark", initialValue: 0); // Returns existing value of 1
final baboonRating = animalRatings.valueOf("baboon", initialValue: 2); // Adds baboon and returns the value of 2

notContainsKey

Whether this map does not contain the given key

final animalRatings = { "aardvark": 1, "baboon": 2 };
final notContainsAardvark = animalRatings.notContainsKey("aardvark"); // false
final notContainsCat = animalRatings.notContainsKey("cat"); // true

Rect Extensions

inflateBySize

Returns a new rectangle with all edges moved outwards by the given size

final rect = Offset.zero & const Size.square(100);
final inflated = rect.inflateBySize(const Size(50, 100));
// inflated.left = -50
// inflated.top = -100
// inflated.right = 150
// inflated.bottom = 200

expandBySize

Returns a new rectangle with only the right and bottom edges moved outwards by the given size

final rect = Offset.zero & const Size.square(100);
final expanded = rect.inflateBySize(const Size.square(50));
// expanded.left = 0
// expanded.top = 0
// expanded.right = 200
// expanded.bottom = 200