title: Flutter RiverPod: How to add post process which is run every time to FutureProvider?
body: <p>In my app, I'm using <a href="https://pub.dev/packages/riverpod" rel="nofollow noreferrer">riverpod</a> and <a href="https://pub.dev/packages/flutter_tts" rel="nofollow noreferrer">flutter_tts</a> package to read aloud http response.
  Firstly, I added it after fetching the data in FutureProvider like this:</p>
  <pre class="lang-dart prettyprint-override"><code>final futureProvider = FutureProvider.family&lt;String, String&gt;((ref, itemId) async {
    // fetch data from server
    final result = await Future.delayed(Duration(seconds: 1)).then((value) =&gt; &quot;$itemId&quot;);
    await SpeakResult(result); // speak here
    return result;
  });
  </code></pre>
  <p>but it was read aloud ONLY first time even if FutureProvider was called multiple times with same itemId.</p>
  <p>Secondly, I added it in <code>build</code> method, but it was ALWAYS read aloud when rebuild the widget.</p>
  <pre class="lang-dart prettyprint-override"><code>useProvider(futureProvider(&quot;item id&quot;)).when(
    loading: () =&gt; CircularProgressIndicator(),
    error: (error, stackTrace) =&gt; Text(&quot;$error&quot;),
    data: (value) async {
      await SpeakResult(value);
      return Text(&quot;$value&quot;);
    },
  );
  </code></pre>
  <p>Are there any idea to solve this?</p>
  <p>Full code is here:</p>
  <pre class="lang-dart prettyprint-override"><code>
  final futureProvider = FutureProvider.autoDispose.family&lt;String, String&gt;((ref, id) async {
    ref.onDispose(() =&gt; print(&quot;disposed&quot;));
    // fetch data from server
    final result = Future.delayed(Duration(seconds: 1)).then((value) =&gt; &quot;$id&quot;);
    // await SpeakResult(result);
    return result;
  });
  
  final asyncListProvider = StateNotifierProvider((_) =&gt; AsyncList());
  
  class AsyncList extends StateNotifier&lt;List&lt;AutoDisposeFutureProvider&lt;String&gt;&gt;&gt; {
    AsyncList() : super([]);
  
    void add(String id) {
      /*
        //I want to do something like this:
        final asyncValue = futureProvider(id).whenData((value) async {
          await SpeakResult(result);
          return value;
        });
      */
      final asyncValue = futureProvider(id);
      state = [asyncValue, ...state];
    }
  }
  
  class MyHomePage extends HookWidget {
    const MyHomePage({Key key}) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      final list = useProvider(asyncListProvider.state);
      return ListView(
        children: [
          RaisedButton(
            child: Text(&quot;Add data&quot;),
            onPressed: () {
              context.read(asyncListProvider).add(&quot;item id&quot;);
            },
          ),
          for (final item in list)
            useProvider(item).when(
              loading: () =&gt; ListTile(
                title: Center(child: CircularProgressIndicator()),
              ),
              error: (error, stackTrace) =&gt; Text(&quot;$error&quot;),
              data: (value) {
                // await SpeakResult(value);
                return Text(&quot;$value&quot;);
              },
            ),
        ],
      );
    }
  }
  </code></pre>