enum_plus

Last updated:

0 purchases

enum_plus Image
enum_plus Images
Add to Cart

Description:

enum plus

enum_plus #




Simple, extensible and powerful enumeration implementation
Usage #
You must include EnumPlus in your Enum. If you are using enhanced enum. You should return your own value by overriding the toValue method.
import 'package:enum_plus/enum_plus.dart';

enum Animal with EnumPlus {
DOG(0),
CAT(1),
HONEY_BEE(2);

const Animal(this.value);

final int value;

@override
dynamic toValue() => value;
}
copied to clipboard
Enum Methods #

Enum Methods

equal()
notEqual()
inside()
outside()
getFriendlyName()


Enum List Methods

hasName()
hasFriendlyName()
getNames()
getName()
getNamesExcept()
getFriendlyNames()
getFriendlyNamesExcept()
fromNames()
fromFriendlyNames()
fromName()
fromFriendlyName()
toListExcept()
getRandom()
getRandomName()
getRandomFriendlyName()
hasValue()
getValues()
getValue()
getValuesExcept()
fromValue()
fromValues()
coerce()
getRandomValue()




equal #
Checks if this instance is equal to the given enum instance or value.
print(Animal.DOG.equal(Animal.DOG)); // true
print(Animal.DOG.equal(0)); // true
print(Animal.DOG.equal(Animal.CAT)); // false
print(Animal.DOG.equal(1)); // false
copied to clipboard

notEqual #
Checks if this instance is not equal to the given enum instance or value.
print(Animal.DOG.notEqual(Animal.CAT)); // true
print(Animal.DOG.notEqual(1)); // true
print(Animal.DOG.notEqual(Animal.DOG)); // false
print(Animal.DOG.notEqual(0)); // false
copied to clipboard

inside #
Checks if a matching enum instance or value is in the given values.
print(Animal.DOG.inside([Animal.DOG, Animal.CAT])); // true
print(Animal.DOG.inside([0, 1])); // true
print(Animal.DOG.inside([Animal.HONEY_BEE, Animal.CAT])); // false
print(Animal.DOG.inside([1, 2])); // false
copied to clipboard

outside #
Checks if a matching enum instance or value is not in the given values.
print(Animal.DOG.outside([Animal.HONEY_BEE, Animal.CAT])); // true
print(Animal.DOG.outside([1, 2])); // true
print(Animal.DOG.outside([Animal.DOG, Animal.CAT])); // false
print(Animal.DOG.outside([0, 1])); // false
copied to clipboard

getFriendlyName #
Transform the name into a friendly, formatted version.
print(Animal.HONEY_BEE.getFriendlyName()); // Honey Bee
copied to clipboard
Enum List Methods #
hasName #
Check that the enum contains a specific name.
print(Animal.values.hasName('DOG')); // true
print(Animal.values.hasName('FISH')); // false
copied to clipboard

hasFriendlyName #
Check that the enum contains a specific friendly name.
print(Animal.values.hasFriendlyName('Honey Bee')); // true
print(Animal.values.hasFriendlyName('Dog')); // true
print(Animal.values.hasFriendlyName('Fish')); // false
copied to clipboard

getNames #
Get all or a custom set of the enum names.
print(Animal.values.getNames()); // [DOG, CAT, HONEY_BEE]
print(Animal.values.getNames(values: [0, Animal.CAT])); // [DOG, CAT]
copied to clipboard

getName #
Get the name for a single enum value.
print(Animal.values.getName(1)); // CAT
print(Animal.values.getName(100)); //Bad state: No element
copied to clipboard

getNamesExcept #
Return names of all the enums except the given values.
print(Animal.values.getNamesExcept([0, Animal.HONEY_BEE])); // [CAT]
copied to clipboard

getFriendlyNames #
Get all or a custom set of the enum friendly names.
print(Animal.values.getFriendlyNames()); // [Dog, Cat, Honey Bee]
print(Animal.values.getFriendlyNames(values: [0, Animal.HONEY_BEE])); // [Dog, Honey Bee]
copied to clipboard

getFriendlyNamesExcept #
Return friendly names of all the enums except the given values.
print(Animal.values.getFriendlyNamesExcept([Animal.DOG, 1])); // [Honey Bee]
copied to clipboard

fromNames #
Get enums from names.
print(Animal.values.fromNames(['DOG', 'CAT'])); // [Animal.DOG, Animal.CAT]
print(Animal.values.fromNames(['CAT', 'FISH'])); // Bad state: No element
copied to clipboard

fromFriendlyNames #
Get enums from friendly names.
print(Animal.values.fromFriendlyNames(['Honey Bee', 'Cat'])); // [Animal.HONEY_BEE, Animal.CAT]
print(Animal.values.fromFriendlyNames(['Honey Bee', 'Fish'])); // Bad state: No element
copied to clipboard

fromName #
Make an enum instance from a given key.
print(Animal.values.fromName('DOG')); // Animal.DOG
print(Animal.values.fromName('FISH')); // Bad state: No element
copied to clipboard

fromFriendlyName #
Make an enum instance from a given friendly name.
print(Animal.values.fromFriendlyName('Honey Bee')); // Animal.HONEY_BEE
print(Animal.values.fromFriendlyName('Fish')); // Bad state: No element
copied to clipboard

toListExcept #
Return instances of all the enums except the given values.
print(Animal.values.toListExcept([Animal.DOG, 1])); // [Animal.HONEY_BEE]
copied to clipboard

getRandom #
Get a random instance of the enum.
print(Animal.values.getRandom()); // Animal.HONEY_BEE
copied to clipboard

getRandomName #
Get a random name of the enum.
print(Animal.values.getRandomName()); // DOG
copied to clipboard

getRandomFriendlyName #
Get a random friendly name of the enum.
print(Animal.values.getRandomFriendlyName()); // Cat
copied to clipboard

hasValue #
Check that the enum contains a specific value.
print(Animal.values.hasValue(1)); // true
print(Animal.values.hasValue(Animal.CAT)); // true
print(Animal.values.hasValue(100)); // false
copied to clipboard

getValues #
Get all or a custom set of the enum values.
print(Animal.values.getValues()); // [0, 1, 2]
print(Animal.values.getValues(names: ['DOG'])); // [0]
copied to clipboard

getValue #
Get the value for a single enum key.
print(Animal.values.getValue('DOG')); // 0
print(Animal.values.getValue('FISH')); // Bad state: No element
copied to clipboard

getValuesExcept #
Return values of all the enums except the given values.
print(Animal.values.getValuesExcept([Animal.DOG, 1])); // [2]
copied to clipboard

fromValue #
Make a new instance from an enum value.
print(Animal.values.fromValue(1)); // Animal.CAT
print(Animal.values.fromValue(Animal.CAT)); // Animal.CAT
print(Animal.values.fromValue(100)); // Bad state: No element
copied to clipboard

fromValues #
Return instances from enum values.
print(Animal.values.fromValues([0, Animal.CAT])); // [Animal.DOG, Animal.CAT]
copied to clipboard

coerce #
Attempt to instantiate a new Enum using the given key or value.
print(Animal.values.coerce(1)); // Animal.CAT
print(Animal.values.coerce('CAT')); // Animal.CAT
print(Animal.values.coerce(100)); // null
print(Animal.values.coerce('FISH')); // null
copied to clipboard

getRandomValue #
Get a random value of the enum.
print(Animal.values.getRandomValue()); // 1
copied to clipboard

License:

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

Files In This Product:

Customer Reviews

There are no reviews.