Skip to content

Commit

Permalink
docs: version 2.0.0 document
Browse files Browse the repository at this point in the history
  • Loading branch information
dungngminh committed Nov 27, 2024
1 parent fe9f1e2 commit 1536053
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,43 +90,67 @@ await remoteConfig.initilize(configUrl: configUrl);

### Get data from remote

`SimpleRemoteConfig` fetchs data in JSON format, data is returned in key-value format, you can `key` to get `value` via `get` function and type `T` you need (`dynamic` by default). `SimpleRemoteConfig` will return `value` from `key` that you pass and correct type `T`.
`SimpleRemoteConfig` fetchs data in JSON format, data is returned in key-value format, you can `key` to get `value` via
get functions, currently `SimpleRemoteConfig` supports `String`, `int`, `double`, `bool`, `Map`.

````dart
Example JSON format:
```json
{
"key1": true, // boolean
"key2": 10, // int
"key3": "value from key 3" // string
"key3": "value from key 3", // string,
"key4": {
"key4_1": "value from key 4_1",
"key4_2": 20
}, // map
"key5": 10.5 // double
}
```
````

And `get` data:
And get data:

```dart
final valueKey1 = remoteConfig.get<bool>('key1');
final valueKey1 = remoteConfig.getBool('key1');
print(valueKey1); // true
final valueKey2 = remoteConfig.get<int>('key2');
final valueKey2 = remoteConfig.getInt('key2');
print(valueKey2); // 10
final valueKey3 = remoteConfig.get<String>('key3');
final valueKey3 = remoteConfig.getString('key3');
print(valueKey3); // value from key 3
final valueKey4 = remoteConfig.getMap('key4');
print(valueKey4); // {key4_1: value from key 4_1, key4_2: 20}
final valueKey5 = remoteConfig.getDouble('key5');
print(valueKey5); // 10.5
```

If provided `key` is not found or provided `T` is incorrect, get functions will return `null`.

```dart
final valueKey7 = remoteConfig.getString('key7');
print(valueKey7); // null
```

If provided `key` is not found or provided `T` is incorrect, `get` will return `null`.
You can pass `defaultValue` when get functions returns `null`.

```dart
final valueKey4 = remoteConfig.get<String>('key4');
print(valueKey4); // null
final valueKey7 = remoteConfig.getString('key7', defaultValue: 'this is default value');
print(valueKey7); // this is default value
```

You can pass `defaultValue` when `get` returns `null`.
## Get all data from remote

`SimpleRemoteConfig` provides `getAll` function to get all data from remote.

```dart
final valueKey4 = remoteConfig.get<String>('key4', defaultValue: 'this is default value');
print(valueKey4); // this is default value
final allData = remoteConfig.getAll();
print(allData); /// {key1: true, key2: 10, key3: value from key 3, key4: {key4_1: value from key 4_1, key4_2: 20}, key5: 10.5}
```

## Happy coding
Expand Down

0 comments on commit 1536053

Please sign in to comment.