0 purchases
useful extensions
About this package #
This package contains extensions that you may find useful in your projects. Developers familiar with the Kotlin language will find many familiar things for themselves, since the package contains many methods from this language and not only😊 Flutter extensions will be added in next versions.
Contributing #
Please, consider contributing👍
Add new feature
Fix a bug
Participate in discussions
Provide documentation
Create pull request
Dart #
Custom classes #
Pair #
final Pair<int, int> x = Pair(2, 2);
copied to clipboard
Bool extensions #
.not() #
if(email.isEmpty.not()){
checkEmailIsValid(email);
}
copied to clipboard
.and() #
if(isEmailValid.and(isPasswordValid)){
register(email, password);
}
copied to clipboard
.or() #
if(hasGoodMarks.or(hasBenefits)){
// Action()
}
copied to clipboard
Object extensions #
Logging #
Just use indside your custom class methods
logInfo(String message, [dynamic error]);
// or
logError(String message, [dynamic error]);
// or
logDebug(String message, [dynamic error]);
// or
logWarning(String message, [dynamic error]);
// or
logWtf(String message, [dynamic error]);
copied to clipboard
Scope functions #
final String? nullableString = null;
nullableString?.let((it) {
// Do something if string isn't null
});
copied to clipboard
final List<int> list = [1, 2, 3];
list.also((self) => print('List length ${self.length}'));
copied to clipboard
Iterable extensions #
.elementAtOrNull() #
final List<int> numbers = [1, 2, 3, 4, 5];
numbers.elementAtOrNull(numbers.length) // null
copied to clipboard
.find() #
final List<int> numbers = [1, 2, 3, 4, 5];
numbers.find((e) => e >= 3) // 3
copied to clipboard
.getRandom() #
final List<int> numbers = [1, 2, 3, 4, 5];
numbers.getRandom() // returns number from 1 to 5
copied to clipboard
.zip() #
final List<int> firstList = [1, 2, 3];
final List<double> secondList = [1.0, 2.0, 3.0];
final List<Pair<int, double>> zipRes = firstList.zip(secondList).toList();
copied to clipboard
.mapIndexed() #
final List<int> firstList = [1, 2, 3, 4, 5];
final List<int> secondList = [1, 2, 3, 4, 5];
firstList.mapIndexed((index, item) => item + secondList[index]);
copied to clipboard
.filter() #
final List<Person> people = [Person('John', 14), Person('Max', 22)];
people.filter((e) => e.age > 18); // [Person('Max', 22)]
copied to clipboard
.filterNot() #
final List<Person> people = [Person('John', 14), Person('Max', 22)];
people.filterNot((e) => e.age > 18); // [Person('John', 14)]
copied to clipboard
.filterNotNull() #
final List<Person?> people = [Person('John', 14), null, Person('Max', 22)];
people.filterNotNull(); // [Person('John', 14), Person('Max', 22)]
copied to clipboard
.forEachIndexed() #
final List<int> numbers = [1, 2, 3, 4, 5];
numbers.forEachIndexed((index, item) => print(index)});
copied to clipboard
List extensions #
.plus() #
final List<int> numbers = [1, 2, 3];
numbers.plus(1); // [2, 3, 4]
copied to clipboard
.minus() #
final List<int> numbers = [1, 2, 3];
numbers.minus(1); // [0, 1, 2]
copied to clipboard
.multiply() #
final List<int> numbers = [1, 2, 3];
numbers.multiply(2); // [2, 4, 6]
copied to clipboard
.divide() #
Only available for list of doubles
final List<double> numbers = [2.0, 4.0, 3.0];
numbers.divide(2); // [1.0, 2.0, 1.5]
copied to clipboard
Full list of extensions #
Custom classes #
Pair
Bool extensions #
.not()
.and(other)
.or(other)
Object extensions #
Logging #
logInfo(message, [error])
logError(message, [error])
logDebug(message, [error])
logWarning(message, [error])
logWtf(message, [error])
Scope functions #
.let()
.also()
Iterable extensions #
.elementAtOrNull(index)
.find(predicate)
.getRandom()
.zip(collection)
.mapIndexed()
.forEachIndexed()
.filter(predicate)
.filterNot(predicate)
.filterNotNull()
List extensions #
.plus(number)
.minus(number)
.multiply(number)
.divide(number)
String extensions #
.isNullOrEmpty
.isNotBlank
.last
.isAlphabetOnly()
.isEmailValid([pattern])
.isPasswordLengthLonger()
.anyChar(predicate)
.toInt()
.toIntOrNull()
.toDouble()
.toDoubleOrNull()
.capitalizeFirst()
.removeAllWhiteSpace()
.reversed()
.replaceAfter(delimiter, replacement, [defaultValue])
.replaceBefore(delimiter, replacement, [defaultValue])
DateTime extensions #
.isToday
.isYesterday
.isTomorrow
.date
.isSameDay(dateTime)
.isAtSameYearAs(dateTime)
.isAtSameMonthAs(dateTime)
.isAtSameDayAs(dateTime)
.isAtSameHourAs(dateTime)
.isAtSameMinuteAs(dateTime)
.isAtSameSecondAs(dateTime)
.copyWith(year, month, day, hour, minute, second, millisecond, microsecond)
.min(dateTime)
.max(dateTime)
.differenceInDays(dateTime)
.differenceInHours(dateTime)
.differenceInMinutes(dateTime)
.differenceInSeconds(dateTime)
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.