From 545b40c196f3690f723694f971be0ea2b253d556 Mon Sep 17 00:00:00 2001 From: Alexandru Mariuti Date: Wed, 29 Jan 2025 17:27:59 +0100 Subject: [PATCH] docs: enhancement (#15) --- docs/src/content/docs/examples/basic.mdx | 6 ------ docs/src/content/docs/index.mdx | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/docs/src/content/docs/examples/basic.mdx b/docs/src/content/docs/examples/basic.mdx index 6d92b65..78db39c 100644 --- a/docs/src/content/docs/examples/basic.mdx +++ b/docs/src/content/docs/examples/basic.mdx @@ -13,9 +13,6 @@ In particular, it shows how to create a provider, how to scope it, how to use it import 'package:disco/disco.dart'; import 'package:flutter/material.dart'; -/// --- -/// Model -/// --- abstract class Model extends ChangeNotifier { void incrementCounter(); @@ -35,9 +32,6 @@ class ModelImplementation extends Model { } } -/// --- -/// Provider -/// --- final modelProvider = Provider((context) => ModelImplementation()); void main() { diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx index 49e8d26..815f7ca 100644 --- a/docs/src/content/docs/index.mdx +++ b/docs/src/content/docs/index.mdx @@ -7,6 +7,30 @@ description: Official documentation for Disco, a modern and simple library for s Disco is a library introducing a new concept of providers that operate differently from those already present in the Flutter ecosystem. It was developed to overcome the challenges and limitations in the context of dependency injection. +## Usage + +### Creating a provider + +```dart +final modelProvider = Provider((context) => Model()); +``` + +### Providing a provider + +```dart +ProviderScope( + providers: [modelProvider], + child: MyWidget(), +) +``` + +### Retrieving a provider +```dart +final model = modelProvider.of(context); +``` + +You can retrieve a provider from any widget in the subtree of the `ProviderScope` where the provider has been provided. + To get straight to the point, pros and cons are summarized below. ### Pros