Skip to content

Commit

Permalink
docs: update README to include enum creation example and clarify enum…
Browse files Browse the repository at this point in the history
… parsing
  • Loading branch information
mysCod3r committed Jan 25, 2025
1 parent a003252 commit cbb912d
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ final version = service.read<String, String>(
parseModel: ParsablePrimitiveModel<String>(''),
);
print(version); // "1.0.0"
// Below is an example of enum creation.
final appTheme = service.read<ParsableEnumModel, ParsableEnumModel>(
key: 'app_theme',
parseModel: const ParsableEnumModel(AppTheme.system),
);
print(appTheme.value); // AppTheme.dark
````
### 2. Managing Multiple Remote Items
Expand Down Expand Up @@ -102,9 +110,6 @@ final forceUpdate = RemoteItem.forceUpdate.read; // ForceUpdateModel(version: '1
final products = RemoteItem.products.read; // [ProductModel(name: 'Product 1', price: 100.0)]
```

---


## Features
### Abstract Models

Expand All @@ -127,7 +132,6 @@ final products = RemoteItem.products.read; // [ProductModel(name: 'Product 1', p

- `IParsableService`: Provides a parsing mechanism for models, supporting single objects and lists.

---

## Model Definitions

Expand All @@ -137,16 +141,17 @@ You can use the ready-made models for `String`, `int`, `double`, and `bool`, or

### 2. Enums

First, the enum class to be parsed should inherit from the `IParsableEnum` interface. This interface should include a method that returns all values of the enum class. Then, using the `IParsableEnumModel` class, the enum class can be made parsable.

```dart
enum TestEnum with IParsableEnum<TestEnum> {
first,
second,
third,
enum AppTheme with IParsableEnum<AppTheme> {
system,
light,
dark,
;
@override
List<TestEnum> get enumValues => values;
List<AppTheme> get enumValues => values;
}
```

Expand Down Expand Up @@ -174,8 +179,6 @@ class ForceUpdateModel extends IParsableObjectModel<ForceUpdateModel> {
}
```

---

## Contributing

Contributions are welcome! Feel free to submit a pull request or open an issue to suggest improvements
Expand Down

0 comments on commit cbb912d

Please sign in to comment.