title: Why there is an error on "context" on Provider.of?
body: <p>I wish to seek your help in solving a synatx error.  An error is shown on the &quot;context&quot; as shown below.</p>
  <p>However, exacly the same code has no error when it is embedded in a class within another file.</p>
  <p>Thank you in advance for your help.</p>
  <p><a href="https://i.stack.imgur.com/7BSGk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7BSGk.png" alt="Error in &quot;context&quot;" /></a></p>
  <p>readfromFirebase.dart</p>
  <pre><code>Future readFromFirebase() async {
    Carpark thisCarpark;
  
    // await FirebaseFirestore.instance
    await FirebaseFirestore.instance
        .collection('carpark')
        .get()
        .then((QuerySnapshot snapshot) {
  
      snapshot.docs.forEach(
        (DocumentSnapshot cp) {
          thisCarpark = Carpark(
            cp.get('name'),
            cp.get('district'),
          );
          Provider.of&lt;CarparksProvider&gt;(context, listen: false)
              .addCarpark(thisCarpark);
        },
      );
    });
    var carparkList =
        Provider.of&lt;CarparksProvider&gt;(context, listen: false).carparks;
    return carparkList;
  }
  
  </code></pre>
  <p>carparks_provider.dart</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'carpark.dart';
  
  class CarparksProvider extends ChangeNotifier {
    List&lt;Carpark&gt; _carparks = [];
  
    List&lt;Carpark&gt; get carparks =&gt; _carparks;
  
    void addCarpark(Carpark carpark) {
      _carparks.add(carpark);
      notifyListeners();
    }
  }
  </code></pre>
  <p>parkingFee_screen.dart</p>
  <pre><code>import 'package:carpark_v012/services/carpark.dart';
  ....
  
  class ParkingFeeScreen extends StatefulWidget {
  
    @override
    _ParkingFeeScreen createState() =&gt; _ParkingFeeScreen();
  }
  
  class _ParkingFeeScreen extends State&lt;ParkingFeeScreen&gt; {
    List&lt;Carpark&gt; carparkList = []; //List for storing carparks
  
    void initState() {
      super.initState();
    }
  
    Future readFromFirebase() async {
      Carpark thisCarpark;
      ......
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: .........
        body: FutureBuilder(
          future: readFromFirebase(context),
          builder: (BuildContext context, AsyncSnapshot snapshot) {
            print(snapshot.data);
  .........
  
  
  </code></pre>