title: Using BLoC in a dialog: Could not find the correct Provider
body: <p>I am attempting to use a bloc to manage the content of a dialog.  I am fairly new to flutter.</p>
  <p>The page is defined as:</p>
  <pre><code>@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(&quot;Business Region Manager&quot;),
      ),
      body: MultiBlocProvider(
        providers: [
          BlocProvider(
            create: (context) =&gt;
                EntityModifyBloc(repository: widget.repository),
          ),
          BlocProvider(
            create: (context) =&gt; EntityBloc(
                repository: widget.repository,
                modifyBloc: BlocProvider.of&lt;EntityModifyBloc&gt;(context)),
          ),
          BlocProvider(
            create: (context) =&gt; BusinessRegionBloc(repository: widget.repository),
          ),
        ],
        child: Center(
          child: BusinessRegionPage(widget.business),
        ),
      ));
  }
  </code></pre>
  <p>Inside BusinessRegionPage I make use of EntityBloc and EntityModifyBloc and, I at least think I have that correct.
  The page has a callback that when fired calls a method:</p>
  <pre><code>void onAddBusinessRegion(){
    showDialog(context: context,
      barrierDismissible: false,
      builder: (BuildContext context){
        return BusinessRegionDialog(
          positiveText: &quot;Ok&quot;,
          onPositive: onPositive,
          negativeText: 'Cancel',
          onNegative: onNegative,
          businessId: widget.business.id,
        );
      });
  }
  </code></pre>
  <p>BusinessRegionDialog is a stateful widget and the state implementation build is:</p>
  <pre><code>@override
  Widget build(BuildContext context) {
    return BlocBuilder&lt;BusinessRegionBloc, BusinessRegionState&gt;(builder: (context, state) {
      if (state is BusinessRegionEmpty) {
        BlocProvider.of&lt;BusinessRegionBloc&gt;(context).add(GetBusinessRegions(widget.businessId));
      }
      if (state is BusinessRegionError) {
        return Center(
          child: Text('Busines Region Error'),
        );
      }
      if (state is BusinessRegionLoaded) {
        return Center(
          child: Text('BusinessRegionLoaded'),
        );
      }
      return Center(
        child: CircularProgressIndicator(),
      );
    });
  </code></pre>
  <p>when the callback is fired, I get the message:</p>
  <p>Error: Could not find the correct Provider above this BlocBuilder&lt;BusinessRegionBloc, BusinessRegionState&gt; Widget</p>
  <p>This likely happens because you used a <code>BuildContext</code> that does not include the provider
  of your choice.</p>
  <p>I made the assumption that in the call to ShowDialog(context), the context is the same one as the one passed into build?  I checked this assumption by printing the hashCode of the context before the showDialog call and after the build implementation on the BusinessRegionPage,</p>
  <p>One of the sugestions in the error message was:</p>
  <pre><code>Widget build(BuildContext context) {
    return Provider&lt;Example&gt;(
      create: (_) =&gt; Example(),
      builder: (context) {
        return Text(context.watch&lt;Example&gt;()),
      }
    ),
  }
  </code></pre>
  <p>so I tried:</p>
  <pre><code>void onAddBusinessRegion() {
    print(&quot;OnAddCallback: &quot; + context.hashCode.toString());
    BusinessRegionClient brClient = BusinessRegionClient(client: http.Client());
    BusinessRegionRepository brRepository =
        BusinessRegionRepository(client: brClient);
  
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return Provider&lt;BusinessRegionBloc&gt;(
            create: (_) =&gt; BusinessRegionBloc(repository: brRepository),
            builder: (context) {
              return BusinessRegionDialog(
                positiveText: &quot;Ok&quot;,
                onPositive: onPositive,
                negativeText: 'Cancel',
                onNegative: onNegative,
                businessId: widget.business.id,
              );
            });
      });
  }
  </code></pre>
  <p>The IDE tells me:
  The argument type 'BusinessRegionDialog Function(BuildContext)' can't be assigned to the parameter type 'Widget Function(BuildContext, Widget)'.</p>
  <p>I clearly don't understand something.  All I want to do is fill a dialog with information from a Future from my repository.  Any guidance will be appreciated.</p>