title: Error: Could not find the correct Provider<TodoModel> above this Builder Widget
body: <p>I am developing a tiny to-do list app and I am new to the <code>Provider</code> package. I get this error:</p>
  <blockquote>
  <p>Error: Could not find the correct Provider above this
  Builder Widget. This happens because you used a 'BuildContext' that
  does not include the provider of your choice.</p>
  </blockquote>
  <pre><code>When the exception was thrown, this was the stack: 
  #0      Provider._inheritedElementOf (package:provider/src/provider.dart:332:7)
  #1      Provider.of (package:provider/src/provider.dart:284:30)
  #2      HomePage.build.&lt;anonymous closure&gt;.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (package:mytodolist/main.dart:57:36)
  #3      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:994:20)
  #4      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
  ...
  Handler: &quot;onTap&quot;
  Recognizer: TapGestureRecognizer#9540a
    debugOwner: GestureDetector
    state: possible
    won arena
    finalPosition: Offset(308.6, 425.5)
    finalLocalPosition: Offset(34.8, 20.3)
    button: 1
    sent tap down
  </code></pre>
  <p>Here's my <code>main.dart</code>:</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:provider/provider.dart';
  import 'package:mytodolist/TodoModel.dart';
  import 'package:firebase_core/firebase_core.dart';
  import 'package:cloud_firestore/cloud_firestore.dart';
  
  Future&lt;void&gt; main() async {
    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
    runApp(MyApp());
  }
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            brightness: Brightness.light,
            primaryColor: Colors.blue,
            accentColor: Colors.orange,
          ),
          home: ChangeNotifierProvider(
            create: (context) =&gt; TodoModel(),
            child: HomePage(),
          )
      );
    }
  }
  
  
  class HomePage extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(&quot;mytodos&quot;),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            showDialog(
                context: context,
                builder: (BuildContext context) {
                  return AlertDialog(
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(8)),
                    title: Text(&quot;Add Todolist&quot;),
                    content: TextField(
                      onChanged: (String value) {
                        Provider.of&lt;TodoModel&gt;(context, listen: false)
                            .addTitle(value);
                      },
                    ),
                    actions: &lt;Widget&gt;[
                      TextButton(
                          onPressed: () {
                            Provider.of&lt;TodoModel&gt;(context, listen: false)
                                .createTodos();
                            Navigator.of(context).pop();
                          },
                          child: Text(&quot;Add&quot;))
                    ],
                  );
                });
          },
          child: Icon(
            Icons.add,
            color: Colors.white,
          ),
        ),
        body: StreamBuilder(
            stream: FirebaseFirestore.instance.collection(&quot;MyTodos&quot;).snapshots(),
            builder: (context, snapshots) {
              if (snapshots.data == null) return CircularProgressIndicator();
              return Consumer&lt;TodoModel&gt;(builder: (context, todo, child) {
                return ListView.builder(
                    shrinkWrap: true,
                    itemCount: snapshots.data.docs.length,
                    itemBuilder: (context, index) {
                      DocumentSnapshot documentSnapshot =
                          snapshots.data.docs[index];
                      return Dismissible(
                          onDismissed: (direction) {
                            Provider.of&lt;TodoModel&gt;(context, listen: false)
                                .deleteTodos(documentSnapshot[&quot;todoTitle&quot;]);
                          },
                          key: Key(documentSnapshot[&quot;todoTitle&quot;]),
                          child: Card(
                            elevation: 4,
                            margin: EdgeInsets.all(8),
                            shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(8)),
                            child: ListTile(
                              title: Text(documentSnapshot[&quot;todoTitle&quot;]),
                              trailing: IconButton(
                                icon: Icon(Icons.delete),
                                color: Colors.red,
                                onPressed: () {
                                  /*setState(() {
                                  todos.removeAt(index);
                                });*/
                                  Provider.of&lt;TodoModel&gt;(context, listen: false)
                                      .deleteTodos(documentSnapshot[&quot;todoTitle&quot;]);
                                },
                              ),
                            ),
                          ));
                    });
              });
            }),
      );
    }
  }
  </code></pre>
  <p>And here's my TodoModel.dart:</p>
  <pre><code>import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:flutter/cupertino.dart';
  
  class TodoModel extends ChangeNotifier {
    // List todos = [];
    String todoTitle = &quot;&quot;;
  
    createTodos() {
      DocumentReference documentReference =
      FirebaseFirestore.instance.collection(&quot;MyTodos&quot;).doc(todoTitle);
      // Map
      Map&lt;String, String&gt; todos = {&quot;todoTitle&quot;: todoTitle};
      documentReference.set(todos).whenComplete(() =&gt;
          print(&quot;$todoTitle created&quot;));
    }
  
    deleteTodos(item) {
      DocumentReference documentReference =
      FirebaseFirestore.instance.collection(&quot;MyTodos&quot;).doc(item);
      documentReference.delete().whenComplete(() =&gt; print(&quot;$item deleted&quot;));
    }
  
    addTitle(String title) {
      todoTitle = title;
    }
  }
  </code></pre>
  <p>In <code>main.dart</code>, I believe I have lifted up the <code>ChangeNotifierProvider</code> high enough to make its child, <code>HomePage</code> class, use <code>Provider.of&lt;TodoModel&gt;(content).xxx</code>. Why does it still popping up the error of not finding the correct Provider above the Builder Widget?</p>