Skip to content

Commit 21a66d2

Browse files
committed
added update for the env-plugin section
1 parent c32210e commit 21a66d2

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

src/content/docs/guides/using-plugins.mdx

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ container or the scoped container.
300300
Here is an example of the TMDB feature that uses the `init()` to register some
301301
feature-level dependencies:
302302

303-
```dart {8-10}
303+
```dart {8-10} title="feature_tmdb/feature.dart"
304304
final feature = FeatureDescriptor(
305305
name: 'tmdb',
306306
title: 'TMDB',
@@ -327,7 +327,44 @@ TBD
327327

328328
## Using the `EnvPlugin`
329329

330-
TBD
330+
The env plugin is useful for loading environment settings from a `.env` file. We
331+
use the `flutter_dotenv` package from _pub.dev_ to load these settings. The
332+
env-plugin makes it convenient for us to load it up automatically and make it
333+
available on `vyuh.env`.
334+
335+
The plugin assumes that you have a `.env` file in your application package which
336+
is loaded automatically at runtime. Also, make sure to include it in your assets
337+
section of `pubspec.yaml`.
338+
339+
```yaml {4} title="pubspec.yaml"
340+
flutter:
341+
uses-material-design: true
342+
assets:
343+
- .env
344+
- assets/app-icon.png
345+
```
346+
347+
As an example, notice how the TMDB feature uses the env plugin to load the
348+
`TMDB_ API_KEY` in the `init()` method.
349+
350+
```dart {8} title="feature_tmdb/feature.dart"
351+
final feature = FeatureDescriptor(
352+
name: 'tmdb',
353+
title: 'TMDB',
354+
description:
355+
'Uses the TMDB API to show details of movies with ability to favorite and add to watchlists',
356+
icon: Icons.movie_creation_outlined,
357+
init: () async {
358+
final apiKey = vyuh.env.get('TMDB_API_KEY');
359+
360+
vyuh.di.register(TMDBClient(apiKey));
361+
362+
// Rest of the init
363+
},
364+
365+
// rest of the feature config
366+
);
367+
```
331368

332369
## Using the `EventPlugin`
333370

0 commit comments

Comments
 (0)