Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何插入列表<;类别>;进入地图<;字符串,动态>;用飞镖?_Flutter_Dart - Fatal编程技术网

Flutter 如何插入列表<;类别>;进入地图<;字符串,动态>;用飞镖?

Flutter 如何插入列表<;类别>;进入地图<;字符串,动态>;用飞镖?,flutter,dart,Flutter,Dart,我的问题是,我有一个以下类的列表: class ingreso_Egreso_Dummy{ int tipo; String monto; String moneda; String descripcion; } 然后,我想将数据插入到一个映射中,该映射稍后将转换为json,我创建的映射如下: Map<String, dynamic> body; body = { "Cod_Prom": "01", "

我的问题是,我有一个以下类的列表:

class ingreso_Egreso_Dummy{
  int tipo;
  String monto;
  String moneda;
  String descripcion;
}
然后,我想将数据插入到一个映射中,该映射稍后将转换为json,我创建的映射如下:

    Map<String, dynamic> body;
        body = {
          "Cod_Prom": "01",
          "CodCli": "003526",
          "Status": _index_status.toString(),
          "NOMBRE": controller_nombre.text,
          "APELLIDOS": controller_apellidos.text,
          "solicitud":[{
            "Cod_Solicit": 1.toString(),
            "Fecha": DateFormat("y-d-M").format(DateTime.now()),
            "Status_Solicit": "E",}],
          "prestamo":[{
            "Monto_Solicit":controller_monto_solic.text,
            "Plazo":controller_plazo.text,
            "Cod_TipoPlazo":_index_tipoplazo.toString(),
            "Nombre_Resp":controller_nombreresp.text,
            "Telf_Resp":controller_telefonoresp.text,}],
          "Ingresos": [{
    //// here I want create a loop that returns a map for each value
   //// of the list like this:

   //// "Descripcion": Listaingresos[i].descripcion;

            })
          }]
        };
图体;
正文={
“Cod_Prom”:“01”,
“CodCli”:“003526”,
“状态”:_index_Status.toString(),
“NOMBRE”:controller_NOMBRE.text,
“APELLIDOS”:controller_APELLIDOS.text,
“请求”:[{
“Cod_request”:1.toString(),
“Fecha”:DateFormat(“y-d-M”).format(DateTime.now()),
“状态请求”:“E”,}],
“普雷斯塔莫”:[{
“Monto_征求”:controller_Monto_solic.text,
“Plazo”:控制器_Plazo.text,
“Cod_TipoPlazo”:_index_TipoPlazo.toString(),
“Nombre_Resp”:控制器Nombre Resp.text,
“Telf_Resp”:控制器_telefonoresp.text,}],
“安格鲁斯”:[{
////这里我想创建一个循环,为每个值返回一个映射
////在列表中,如下所示:
////“描述”:Listaingresos[i]。描述;
})
}]
};
非常感谢您的帮助。

//camelCaseStyle是Dart类名称的标准
// camelCaseStyle is a standard for class names for Dart     
class IngresoEgresoDummy { 
  int tipo;
  String monto;
  String moneda;
  String descripcion;
  Map<String, dynamic> toJson(){
    return {
      'tipo': tipo,
      'monto': monto,
      'monedo': moneda,
      'descripcion': descripcion
    };
  }
}
类Ingregressodummy{ 国际提波; 弦蒙托; 弦莫奈达; 字符串描述; 映射到JSON(){ 返回{ "tipo":tipo,, “蒙托”:蒙托, “莫奈多”:莫奈达, “描述离子”:描述离子 }; } }
然后呢

List<IngresoEgresoDummy> listaingresos= List();

Map<String, dynamic> body = {
// all your params
  "Ingresos": listaingresos.map((ingreso) => ingreso.toJson()).toList()
// all your params
};
List listaingresos=List();
地图正文={
//你所有的情人
“Ingreos”:listaingresos.map((Ingreo)=>Ingreo.toJson()).toList()
//你所有的情人
};

看看地图。fromIterable()我试过了,但它返回了一个列表实例。我已经找到了一个方法,但是你的看起来更干净了。我把它放在这里:
“白鹭”:[对于(白鹭中的入口白鹭假人I){“tipo”:I.tipo.toString(),“monto”:I.monto,“moneda”:I.moneda,“description”:i.descripion}],
谢谢你的回答,只需编辑一封信,用“monedo”写的不好,有一个“a”,但我会接受你的回答