handy_extensions 0.1.5+3 copy "handy_extensions: ^0.1.5+3" to clipboard
handy_extensions: ^0.1.5+3 copied to clipboard

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

HandyExtensions #

Developed with πŸ’™ by Ngonidzashe Mangudya

![coverage][coverage_badge] style: very good analysis License: MIT


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: #

Getting started #

Add as a dependency #

dependencies:
  handy_extensions: <version>

Usage #

BuildContext #

context.goTo(page: const Home());
context.goTo(page: const Home(), replace: true);

Go Back To The Previous Page

context.goBack();
context.goToRefresh(page: const Login());

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

Get Screen Size (based on MediaQuery)

// Height
context.height;
// Width
context.width;

String #

Country Emoji

String country = 'ZW';
String emoji = country.countryEmoji; // => πŸ‡ΏπŸ‡Ό (String)

Title Case

String title = 'hello world';
String titleCase = title.titleCase; // => Hello world

Heading Case

String heading = 'hello world';
String headingCase = heading.headingCase; // => Hello World

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

Random Item

// Will return a random item from the list of type T
["Hello", "World", "iAMNGONI"].randomItem();

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);

firstWhereOrNull

List<String> list = ['a', 'b', 'c'];
String? character = list.firstWhereOrNull( (String item) => item == 'a'); // => 'a' (String) or null (null)

groupBy

[1,2,3,4,5,6].groupBy((i) => i % 2 == 0); // {true: [2, 4, 6], false: [1, 3, 5]}

swap

List<int> list = [1, 2, 3, 4, 5];
list.swap(0, 4); // [5, 2, 3, 4, 1]

swapRange

List<int> list = [1, 2, 3, 4, 5];
list.swapRange(0, 2, 3); // [4, 5, 3, 1, 2]

hasDuplicates

List<int> list = [1, 2, 3, 4, 5, 1];
list.hasDuplicates; // true

Int #

microsecond

Duration microsecond = 1.microsecond; // => 1

milliseconds

Duration milliseconds = 1.milliseconds; // => 1

seconds

Duration seconds = 1.seconds; // => 1

minutes

Duration minutes = 1.minutes; // => 1

hours

Duration hours = 1.hours; // => 1

days

Duration days = 1.days; // => 1

weeks

Duration weeks = 1.weeks; // => 1

Example usage of the above duration items

Duration duration = 1.weeks + 2.days + 3.hours + 4.minutes + 5.seconds + 6.milliseconds + 7.microseconds;

General #

Check if variable is null

String? name = null;
name.isNull; // => true (bool)

Additional information #

You can add in more extensions of your own -> share with the rest of the world.


5
likes
0
pub points
72%
popularity

Publisher

verified publisheriamngoni.co.zw

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

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on handy_extensions