title: Flutter Map In Data Table
body: <p>I get this error where I want to <code>.map</code> out some <code>Data Row</code> in a data table.</p>
  <p><a href="https://i.stack.imgur.com/Pn5Zq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Pn5Zq.png" alt="enter image description here" /></a></p>
  <p>I've achieved this earlier in a previous situation and I understood how to do it, but it seems in this situation, things are different and seem to understand how to define the the method 'map'. I want to achieve things like on the picture below, where the Columns headings are static and the rows are mapped out.</p>
  <p><a href="https://i.stack.imgur.com/cn5sD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cn5sD.png" alt="enter image description here" /></a></p>
  <p>Here is the code:</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:provider/provider.dart';
  import 'package:providerrest/helpers/apihelper.dart';
  import 'package:providerrest/models/post.dart';
  import 'package:providerrest/provider/homepageprovider.dart';
  
  class HomePage extends StatefulWidget {
    @override
    _HomePageState createState() =&gt; _HomePageState();
  }
  
  class _HomePageState extends State&lt;HomePage&gt; {
    GlobalKey&lt;ScaffoldState&gt; _globalKey = GlobalKey();
  
    _getPosts() async {
      var provider = Provider.of&lt;HomePageProvider&gt;(context, listen: false);
  
      var postsResponse = await getPosts();
      if (postsResponse.isSuccessful) {
        provider.setPostsList(postsResponse.data, notify: false);
      } else {
        provider.mergePostsList(postsResponse.data, notify: false);
      }
  
      provider.setIsHomePageProcessing(false);
    }
  
    @override
    void initState() {
      super.initState();
      _getPosts();
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        key: _globalKey,
        appBar: AppBar(
          title: Text('Provider REST'),
        ),
        body: Consumer&lt;HomePageProvider&gt;(
          builder: (_, provider, __) {
            return ListView.builder(
              itemBuilder: (_, index) {
                Post post = provider.getPostByIndex(index);
                return DataTable(
                  columnSpacing: 50,
                  columns: &lt;DataColumn&gt;[
                    DataColumn(
                      label: Text(
                        'Friendly Name',
                        style: TextStyle(fontStyle: FontStyle.italic),
                      ),
                    ),
                    DataColumn(
                      label: Text(
                        'Licence Plate',
                        style: TextStyle(fontStyle: FontStyle.italic),
                      ),
                    ),
                    DataColumn(
                      label: Text(
                        'Delete',
                        style: TextStyle(fontStyle: FontStyle.italic),
                      ),
                    ),
                  ],
                  rows: post.map&lt;DataRow&gt;((e) {
                    return DataRow(
                      cells: &lt;DataCell&gt;[
                        DataCell(
                          Text('${e.friendlyName}'),
                        ),
                        DataCell(
                          Text('${e.licencePlate}'),
                        ),
                        DataCell(
                          Icon(Icons.delete),
                        ),
                      ],
                    );
                  }).toList(),
                );
              },
              itemCount: provider.postsListLength,
            );
          },
        ),
      );
    }
  }
  
  </code></pre>
  <p>Post Model</p>
  <pre><code>class Post {
    int capacity;
    String id;
    String friendlyName;
    String licencePlate;
  
    Post({this.capacity, this.id, this.friendlyName, this.licencePlate});
  
    Post.fromJson(Map&lt;String, dynamic&gt; json) {
      capacity = json['capacity'];
      id = json['id'];
      friendlyName = json['friendlyName'];
      licencePlate = json['licencePlate'];
    }
  
    Map&lt;String, dynamic&gt; toJson() {
      final Map&lt;String, dynamic&gt; data = new Map&lt;String, dynamic&gt;();
      data['capacity'] = this.capacity;
      data['id'] = this.id;
      data['friendlyName'] = this.friendlyName;
      data['licencePlate'] = this.licencePlate;
      return data;
    }
  }
  
  </code></pre>
  <p>The API call</p>
  <pre><code>import 'dart:convert';
  
  import 'package:http/http.dart';
  import 'package:providerrest/models/httpresponse.dart';
  import 'package:providerrest/models/post.dart';
  
  Future&lt;HTTPResponse&lt;List&lt;Post&gt;&gt;&gt; getPosts() async {
    final response =
        await get('https://run.mocky.io/v3/d7a00528-176c-402f-850e-76567de3c68d');
    if (response.statusCode == 200) {
      var body = jsonDecode(response.body)['data'];
      List&lt;Post&gt; posts = [];
      body.forEach((e) {
        Post post = Post.fromJson(e);
        posts.add(post);
      });
      return HTTPResponse&lt;List&lt;Post&gt;&gt;(
        true,
        posts,
        message: 'Request Successful',
        statusCode: response.statusCode,
      );
    } else {
      return HTTPResponse&lt;List&lt;Post&gt;&gt;(
        false,
        null,
        message:
            'Invalid data received from the server! Please try again in a moment.',
        statusCode: response.statusCode,
      );
    }
  }
  
  </code></pre>
  <p>and the Provider:</p>
  <pre><code>import 'package:flutter/foundation.dart';
  import 'package:providerrest/models/post.dart';
  
  class HomePageProvider extends ChangeNotifier {
    bool _isHomePageProcessing = true;
    List&lt;Post&gt; _postsList = [];
  
    bool get isHomePageProcessing =&gt; _isHomePageProcessing;
  
    setIsHomePageProcessing(bool value) {
      _isHomePageProcessing = value;
      notifyListeners();
    }
  
    List&lt;Post&gt; get postsList =&gt; _postsList;
  
    setPostsList(List&lt;Post&gt; list, {bool notify = true}) {
      _postsList = list;
      if (notify) notifyListeners();
    }
  
    mergePostsList(List&lt;Post&gt; list, {bool notify = true}) {
      _postsList.addAll(list);
      if (notify) notifyListeners();
    }
  
    deletePost(Post list) {
      _postsList.remove(list);
  
      notifyListeners();
    }
  
    addPost(Post post, {bool notify = true}) {
      _postsList.add(post);
      if (notify) notifyListeners();
    }
  
    Post getPostByIndex(int index) =&gt; _postsList[index];
  
    int get postsListLength =&gt; _postsList.length;
  }
  
  </code></pre>
  <p>I thought I achieved this by making a <code>Map toJson()</code>method in the Post model, but it seems I'm wrong.</p>
  <p>Thank you in advance for the help!</p>