类型'_InternalLinkedHashMap <string,dynamic =“”>'不是'List <map <string,dynamic =“” >>'类型的子类型

时间:2018-11-30 06:16:36

标签: dart flutter

在某些情况下,我有点受阻。

1)type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<Map<String, dynamic>>'

我的代码。

List<Map<String, dynamic>> arrayOfProductList = List<Map<String, dynamic>>();

调用API

Future<Map<String, dynamic>> _callWebServiceForGetProductList() async{

    String strURL = 'http:xxxxxx/productlist.php';
    Map<String, String> headerDic = {"Authorization": "ff624bc580ab48a3910d4352dxxx712"};
    Map<String, String> paramDic = {"page": "1", "search": "", "term_id": ""};

    http.Response httpRes = await http.post(strURL, headers: headerDic, body: paramDic);
    Map<String, dynamic> responseDic = json.decode(httpRes.body);
    return responseDic;
  }

FutureBuilder小部件和内容

Expanded(
              child: Container(
                child: FutureBuilder(
                    future: _callWebServiceForGetProductList(),
                    builder: (BuildContext context, AsyncSnapshot snap) {
                    if(snap.hasData) {
                      Map<String, dynamic> dicOfData = snap.data;
                      arrayOfProductList = dicOfData["data"] as List<Map<String, dynamic>>;
                      print(arrayOfProductList);
                      _setupProductListView();
                    }
                    else if(snap.hasError) {
                      showDialog(context: context, builder:(_) => AlertDialog(
                        content: Text("Error ${snap.hasError.toString()}"),
                        title: Text("Error"),
                      ));
                    }
                    return Center(child: CircularProgressIndicator());

                    }
                ),
              ),
            )

我最近2个小时仍在搜寻Google,但没有得到任何结果。我要去哪里错了?引导我。

1 个答案:

答案 0 :(得分:0)

dicOfData["data"] as List<Map<String, dynamic>>的强制转换尝试似乎导致了您收到的类型不匹配错误。如果您可以提供有关快照包含的数据的更多详细信息,则可以帮助我们确定导致错误的原因。