https://github.com/dimibe/enumerated
Dart package with utilities around dart enums
https://github.com/dimibe/enumerated
dart enum flutter package
Last synced: about 1 month ago
JSON representation
Dart package with utilities around dart enums
- Host: GitHub
- URL: https://github.com/dimibe/enumerated
- Owner: Dimibe
- License: mit
- Created: 2022-06-20T20:12:04.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-10-14T11:28:00.000Z (over 3 years ago)
- Last Synced: 2024-11-19T09:02:01.662Z (over 1 year ago)
- Topics: dart, enum, flutter, package
- Language: Dart
- Homepage: https://pub.dev/packages/enumerated
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pub.dev/packages/enumerated)
[](https://pub.dev/packages/enumerated)

The enumerated package adds additional functionality around dart enums.
One main aspect of this package is the `EnumSet`.
## Features
* EnumSet - A `Set` implementation especially for enums.
* EnumSet provides additional functionalities and more efficient implementations for specific set operations.
## Getting started
Add the package to your pubspec.yaml:
```yaml
enumerated: ^0.1.1
```
In your dart file, import the library:
```Dart
import 'package:enumerated/enumerated.dart';
```
## Usage
#### Creating an EnumSet:
In order to create an `EnumSet` you can choose from one of the following factory methods:
* `EnumSet.of(List, Iterable)`: Creates an `EnumSet` with the given values.
* `EnumSet.noneOf(List)`: Creates an empty `EnumSet`.
* `EnumSet.allOf(List)`: Creates an `EnumSet` with all values of the given enum.
* `EnumSet.complementOf(EnumSet)`: Creates an `EnumSet` with all values which are not contained in the other `EnumSet`
```dart
enum Numbers {one, two, three;}
var set1 = EnumSet.of(Numbers.values, [Numbers.one]);
var set2 = EnumSet.noneOf(Numbers.values);
var set3 = EnumSet.allOf(Numbers.values);
var set4 = EnumSet.complementOf(set1);
```
Note that for every factory method other than `complementOf` you need to provide the full list of possible enum values as first parameter.
#### Adding and removing data:
```dart
set1.add(Numbers.two);
set1.addAll(set3);
set1.remove(Numbers.one);
set1.removeAll(set3);
```
#### Other useful functionalities:
* fill(): Will add all enum values to the set.
```dart
set1.fill();
```
* complement(): Will return a new `EnumSet` with all values which are not contained in the current set.
```dart
set1.complement();
```
* copy(): Creates a exact copy of the current set.
```dart
set1.copy();
```
## Additional information
If you have ideas for this package or want to help develop it yourself,
don't hesitate to open an issue or create a pull request. I am grateful for any help!