title: Unable to get id by fetching data from API
body: <p>Im having an issue with fetching Data into my app from an API</p>
  
  <p>here is how the id looks in the databse:</p>
  
  <pre><code> "id": 127,
  </code></pre>
  
  <p>here is how my fetch code looks:</p>
  
  <pre><code>Future&lt;void&gt; fetchAndSetCars() async {
      const url =
          "my API link";
      try {
        final response = await http.get(url);
        final extractedData = json.decode(response.body) as Map&lt;int, dynamic&gt;;
        List&lt;AddCar&gt; loadedCars = [];
  
        extractedData.forEach((carId, carData) {
          loadedCars.add(AddCar(
            id: carId,
            name: carData['adTitle'],
            price: carData['AdPrice'],
            date: carData['adDate'],
            model: carData['brandModel'],
            year: carData['modelYear'],
            distanceCovered: carData['kilometer'],
            transmission: carData['gearType'],
            oilT: carData['fuelType'],
            image: File(carData['image']),
          ));
        });
        _cars = loadedCars;
        print(json.decode(response.body));
        notifyListeners();
      } catch (error) {
        throw (error);
      }
    }
  </code></pre>
  
  <p>here is my provider code: </p>
  
  <pre><code>import 'dart:io';
  
  class AddCar {
    int id;
    String name;
    double price;
    String date;
    String model;
    String year;
    double distanceCovered;
    String transmission;
    String oilT;
    File image;
  
    AddCar({
      this.id,
      this.name,
      this.price,
      this.date,
      this.model,
      this.year,
      this.distanceCovered,
      this.transmission,
      this.oilT,
      this.image,
    });
  }
  </code></pre>
  
  <p>here is my CarItem "where the data is displayed":</p>
  
  <pre><code>class CarItem extends StatelessWidget {
    final int id;
    final File image;
    final String name;
    final String model;
    final String currencyT;
    final double price;
    final double distanceCovered;
    final String transmission;
    final String oilT;
    final String year;
    final String date;
  
    CarItem(
      this.id,
      this.image,
      this.name,
      this.model,
      this.currencyT,
      this.price,
      this.distanceCovered,
      this.transmission,
      this.oilT,
      this.year,
      this.date,
    );
  
    @override
    Widget build(BuildContext context) {
      return Container(),
  </code></pre>
  
  <p>and here is my <code>ListView.builder</code> with my fetch code:</p>
  
  <pre><code>@override
    void didChangeDependencies() {
      if (_isInit) {
        setState(() {
          _isLoading = true;
        });
        Provider.of&lt;Cars&gt;(context).fetchAndSetCars().then((_) {
          setState(() {
            _isLoading = false;
          });
        });
      }
      _isInit = false;
      super.didChangeDependencies();
    }
  
  ListView.builder(
                      physics: NeverScrollableScrollPhysics(),
                      itemCount: car.length = 1,
                      shrinkWrap: true,
                      itemBuilder: (ctx, i) =&gt; CarItem(
                        car[i].id,
                        car[i].image,
                        car[i].name,
                        car[i].model,
                        car[i].currencyT,
                        car[i].price,
                        car[i].distanceCovered,
                        car[i].transmission,
                        car[i].oilT,
                        car[i].year,
                        car[i].date,
                      ),
                    )
  </code></pre>
  
  <p>and here is the error im getting on run time:</p>
  
  <pre><code>I/flutter (  968): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
  I/flutter (  968): The following NoSuchMethodError was thrown building:
  I/flutter (  968): The getter 'id' was called on null.
  I/flutter (  968): Receiver: null
  I/flutter (  968): Tried calling: id
  </code></pre>
  
  <p>and another error too:</p>
  
  <pre><code>E/flutter (  968): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type '_InternalLinkedHashMap&lt;String, dynamic&gt;' is not a subtype of type 'Map&lt;int, dynamic&gt;' in type cast
  E/flutter (  968): #0      Cars.fetchAndSetCars 
  package:flutter_app/providers/car_provider.dart:61
  E/flutter (  968): &lt;asynchronous suspension&gt;
  E/flutter (  968): #1      _CarAreaState.didChangeDependencies
  </code></pre>