Skip to content

Commit cbb912d

Browse files
committed
docs: update README to include enum creation example and clarify enum parsing
1 parent a003252 commit cbb912d

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ final version = service.read<String, String>(
4242
parseModel: ParsablePrimitiveModel<String>(''),
4343
);
4444
print(version); // "1.0.0"
45+
46+
// Below is an example of enum creation.
47+
final appTheme = service.read<ParsableEnumModel, ParsableEnumModel>(
48+
key: 'app_theme',
49+
parseModel: const ParsableEnumModel(AppTheme.system),
50+
);
51+
52+
print(appTheme.value); // AppTheme.dark
4553
````
4654
4755
### 2. Managing Multiple Remote Items
@@ -102,9 +110,6 @@ final forceUpdate = RemoteItem.forceUpdate.read; // ForceUpdateModel(version: '1
102110
final products = RemoteItem.products.read; // [ProductModel(name: 'Product 1', price: 100.0)]
103111
```
104112

105-
---
106-
107-
108113
## Features
109114
### Abstract Models
110115

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

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

130-
---
131135

132136
## Model Definitions
133137

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

138142
### 2. Enums
139143

144+
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.
140145

141146
```dart
142-
enum TestEnum with IParsableEnum<TestEnum> {
143-
first,
144-
second,
145-
third,
147+
enum AppTheme with IParsableEnum<AppTheme> {
148+
system,
149+
light,
150+
dark,
146151
;
147-
152+
148153
@override
149-
List<TestEnum> get enumValues => values;
154+
List<AppTheme> get enumValues => values;
150155
}
151156
```
152157

@@ -174,8 +179,6 @@ class ForceUpdateModel extends IParsableObjectModel<ForceUpdateModel> {
174179
}
175180
```
176181

177-
---
178-
179182
## Contributing
180183

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

0 commit comments

Comments
 (0)