title: Could not find the correct Provider above this Widget - Flutter
body: <p>I am new to Flutter and I am using Provider in my Flutter App and my main.dart file looks like this :</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:provider_practice/screens/first_screen.dart';
  import 'package:provider_practice/screens/second_screen.dart';
  import 'package:provider/provider.dart';
  import 'package:provider_practice/counter.dart';
  
  void main() {
    runApp(MaterialApp(
  
      home: ChangeNotifierProvider&lt;Counter&gt;(
        create: (context) =&gt; Counter(),
        child: FirstScreen(),
      ),
  
      routes: {
        &quot;/first&quot; : (context) =&gt; FirstScreen(),
        &quot;/second&quot; : (context) =&gt; SecondScreen(),
      },
    ));
  }
  </code></pre>
  <p>My code works fine on FirstScreen() but when I navigate to SecondScreen() (by using Navigator.pushNamed()), I get the following error :</p>
  <pre><code>The following ProviderNotFoundException was thrown building SecondScreen(dirty):
  Error: Could not find the correct Provider&lt;Counter&gt; above this SecondScreen Widget
  </code></pre>
  <p>Is there anyway to fix this ? I am using Provider version ^5.0.0</p>
  <p>first_screen.dart :-</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:provider/provider.dart';
  import 'package:provider_practice/counter.dart';
  
  class FirstScreen extends StatelessWidget {
  
    @override
    Widget build(BuildContext context) {
  
      final counter = Provider.of&lt;Counter&gt;(context , listen: false);
  
      return Scaffold(
        appBar: AppBar(
          title: Text(&quot;First Screen&quot;),
        ),
  
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Consumer&lt;Counter&gt;(
                    builder: (_ , counter , __) =&gt; Text(&quot;You pressed the button 
  ${counter.firstCounter} times.&quot;)
                ),
                SizedBox(height: 20),
                RaisedButton(
                  onPressed: counter.firstIncrement,
                  child: Text(&quot;Click Me&quot;),
                ),
                SizedBox(height: 20),
                RaisedButton(
                  onPressed: () {
                    Navigator.pushNamed(context, &quot;/second&quot;);
                  },
                  child: Text(&quot;Go to Second&quot;),
                ),
              ],
            ),
          ),
        ),
      );
    }
  }
  </code></pre>
  <p>second_screen.dart :-</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:provider/provider.dart';
  import 'package:provider_practice/counter.dart';
  
  class SecondScreen extends StatelessWidget {
  
    @override
    Widget build(BuildContext context) {
  
      final counter = Provider.of&lt;Counter&gt;(context , listen: false);
  
      return Scaffold(
        appBar: AppBar(
          title: Text(&quot;Second Screen&quot;),
        ),
  
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Consumer&lt;Counter&gt;(
                    builder: (_ , counter , __) =&gt; Text(&quot;You pressed the button 
  ${counter.secondCounter} times.&quot;)
                ),
                SizedBox(height: 20),
                RaisedButton(
                  onPressed: counter.secondIncrement,
                  child: Text(&quot;Click Me&quot;),
                ),
                SizedBox(height: 20),
                RaisedButton(
                  onPressed: () {
                    //Navigator.maybePop(context);
                    Navigator.pushNamed(context, &quot;/first&quot;);
                    //Navigator.pop(context);
                  },
                  child: Text(&quot;Go to First&quot;),
                ),
              ],
            ),
          ),
        ),
      );
    }
  }
  </code></pre>
  <p>counter.dart :-</p>
  <pre><code>import 'package:flutter/foundation.dart';
  
  class Counter with ChangeNotifier {
    int firstCounter = 0;
    int secondCounter = 0;
  
    void firstIncrement() {
      firstCounter++;
      notifyListeners();
    }
  
    void secondIncrement() {
      secondCounter++;
      notifyListeners();
    }
  }
  </code></pre>