title: How to call an async method using ProxyProvider?
body: <p>One of my services, <code>UserService</code>, has an async <code>init</code> method (as it calls <code>Hive.openBox</code>).</p>
  
  <p>I need this initialization to complete in order to inject this dependency into <code>ChatService</code>.</p>
  
  <pre class="lang-dart prettyprint-override"><code>main() {
    runApp(MultiProvider(
      providers: [
          Provider&lt;Api&gt;.value(value: Api()),
          ProxyProvider&lt;Api, UserService&gt;(update: (_, api, __) async {
            var service = UserService(api);
            await service.init();
            return service;
          }),
          ChangeNotifierProxyProvider&lt;UserService, ChatService&gt;(
            create: (_) =&gt; ChatService(),
            update: (_, userService, chatService) =&gt; chatService..userService = userService
          ),
        ],
        child: MyApp(),
    ));
  }
  </code></pre>
  
  <p>Of course, attempting to make create <code>async</code> gives the following error because of the type mismatch:</p>
  
  <pre><code>The argument type 'Future&lt;UserService&gt; Function(BuildContext, Api, UserService)' can't be assigned to the parameter type 'UserService Function(BuildContext, Api, UserService)'.dart(argument_type_not_assignable)
  </code></pre>
  
  <p>How can I await this method using <code>ProxyProvider</code>?</p>
  
  <p>Is <code>get_it</code> a better tool for what I'm trying to do?</p>
  
  <p><strong>EDIT AFTER REMI'S ANSWER</strong></p>
  
  <p>I'm using <code>FutureProvider</code> now but it's still unclear how to feed the initialized <code>UserService</code> dependency into the next dependant <code>ChatService</code> when it's immutable:</p>
  
  <pre class="lang-dart prettyprint-override"><code>      providers: [
          Provider&lt;Api&gt;(create: (_) =&gt; Api()),
          FutureProvider&lt;UserService&gt;(
            lazy: false,
            create: (context) async {
              var service = UserService(Provider.of(context, listen: false));
              await service.init();
              return service;
            }
          ),
          ChangeNotifierProvider&lt;ChatService&gt;(
            create: (context) =&gt; ChatService(Provider.of&lt;UserService&gt;(context, listen: false)), // UserService is null
          )
        ],
  </code></pre>
  
  <p><code>UserService</code> is <code>null</code> by the time <code>create</code> is called.</p>
  
  <p>Using a <code>ChangeNotifierProxyProvider</code>'s <code>update</code> that wouldn't work either <code>UserService</code> is a constructor dependency.</p>