handy_extensions

Creator: coderz1093

Last updated:

Add to Cart

Description:

handy extensions

HandyExtensions #
Developed with πŸ’™ by Ngonidzashe Mangudya







Handy Extension is just a simple library with extensions to the core libraries to make them more handy and quicker to use.

I don't know how "deadly" this is but I just use it anyway.

Extensions On: #

BuildContext
String
int
List
DateTime
Num
Map
Iterable
Nullable String (probably useless πŸ˜‚ but it's there)

Getting started #
Add as a dependency #
dependencies:
handy_extensions: <version>
copied to clipboard
Usage #
BuildContext #
Navigate To A Page
context.goTo(page: const Home());
copied to clipboard
Navigate To A Page Replacing The Current Page
context.goTo(page: const Home(), replace: true);
copied to clipboard
Go Back To The Previous Page
context.goBack();
copied to clipboard
Navigate To A Page And Remove History
context.goToRefresh(page: const Login());
copied to clipboard
Notify The User Using A SnackBar
context.notify(message: 'Hello World', isError: false); // You can pass the isError argument or leave it, it will default to false
copied to clipboard
Get Screen Size (based on MediaQuery)
// Height
context.height;
// Width
context.width;
copied to clipboard
String #
Country Emoji
String country = 'ZW';
String emoji = country.countryEmoji; // => πŸ‡ΏπŸ‡Ό (String)
copied to clipboard
Title Case
String title = 'hello world';
String titleCase = title.titleCase; // => Hello world
copied to clipboard
Heading Case
String heading = 'hello world';
String headingCase = heading.headingCase; // => Hello World
copied to clipboard
doubleOrNull
String? number = '1';
double? doubleNumber = number.doubleOrNull; // => 1.0 (double) or null (null)
copied to clipboard
intOrNull
String? number = '1';
int? intNumber = number.intOrNull; // => 1 (int) or null (null)
copied to clipboard
Map #
swap
Map<String, int> map = {'a': 1, 'b': 2};
map.swap; // {1: 'a', 2: 'b'}
copied to clipboard
copy
Map<String, int> map = {'a': 1, 'b': 2};
map.copy; // {'a': 1, 'b': 2}
copied to clipboard
removeNulls
Map<String, int?> map = {'a': 1, 'b': null};
map.removeNulls; // {'a': 1}
copied to clipboard
adjustOrder
Map<String, int> map = {'a': 1, 'b': 2};
map.adjustOrder(1, 0); // {'b': 2, 'a': 1}
copied to clipboard
List #
Partition into chunks
[1,2,3,4,5,6].partition(chunkSize: 3); // => [[1,2,3],[4,5,6]] (List<List<int>>). By default it will partition into chunks of 2
copied to clipboard
Random Item
// Will return a random item from the list of type T
["Hello", "World", "iAMNGONI"].randomItem();
copied to clipboard
Random Items
// Will return a list of random items from the list of type T. By default this may return a
// list with only one item
["Hello", "World", "iAMNGONI"].randomItems(count: 2);
copied to clipboard
firstWhereOrNull
List<String> list = ['a', 'b', 'c'];
String? character = list.firstWhereOrNull( (String item) => item == 'a'); // => 'a' (String) or null (null)
copied to clipboard
groupBy
[1,2,3,4,5,6].groupBy((i) => i % 2 == 0); // {true: [2, 4, 6], false: [1, 3, 5]}
copied to clipboard
swap
List<int> list = [1, 2, 3, 4, 5];
list.swap(0, 4); // [5, 2, 3, 4, 1]
copied to clipboard
swapRange
List<int> list = [1, 2, 3, 4, 5];
list.swapRange(0, 2, 3); // [4, 5, 3, 1, 2]
copied to clipboard
hasDuplicates
List<int> list = [1, 2, 3, 4, 5, 1];
list.hasDuplicates; // true
copied to clipboard
intersperse
List<int> list = [1, 2, 3, 4, 5, 1];
list.intersperse(100);
// [1, 100, 2, 100, 3, 100, 4, 100, 5, 100, 1]
copied to clipboard
Int #
microsecond
Duration microsecond = 1.microsecond; // => 1
copied to clipboard
milliseconds
Duration milliseconds = 1.milliseconds; // => 1
copied to clipboard
seconds
Duration seconds = 1.seconds; // => 1
copied to clipboard
minutes
Duration minutes = 1.minutes; // => 1
copied to clipboard
hours
Duration hours = 1.hours; // => 1
copied to clipboard
days
Duration days = 1.days; // => 1
copied to clipboard
weeks
Duration weeks = 1.weeks; // => 1
copied to clipboard
Example usage of the above duration items
Duration duration = 1.weeks + 2.days + 3.hours + 4.minutes + 5.seconds + 6.milliseconds + 7.microseconds;
copied to clipboard
General #
Check if variable is null
String? name = null;
name.isNull; // => true (bool)
copied to clipboard
Nullable Int #
isInt
int? number = 1;
number.isInt; // => true (bool)
copied to clipboard
int? number = null;
number.isInt; // => false (bool)
copied to clipboard
Nullable String #
isString
String? name = 'Ngoni';
name.isString; // => true (bool)
copied to clipboard
String? name = null;
name.isString; // => false (bool)
copied to clipboard
orEmpty #
String? name = null;
name.orEmpty; // => '' (String)
copied to clipboard
String? name = 'Ngoni';
name.orEmpty; // => 'Ngoni' (String)
copied to clipboard
isNotReallyEmpty #
String? name = null;
name.isNotReallyEmpty; // => false (bool)
copied to clipboard
String? name = ' ';
name.isNotReallyEmpty; // => false (bool)
copied to clipboard
String? name = 'Ngoni';
name.isNotReallyEmpty; // => true (bool)
copied to clipboard
Additional information #
You can add in more extensions of your own -> share with the rest of the world.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files:

Customer Reviews

There are no reviews.