当前位置:   article > 正文

flutter 二维数组赋值问题

flutter 二维数组赋值问题
class ExpCellDetailP0J0 {
  int num;//序号
  SizeDetail sizeDetail; //格口尺寸参数
  bool isSelected; //是否选中

  SelectFileData backFillFile;//本地格口规格设置弹窗里填写后的回填中显示用的格口图片、视频文件


  ExpCellDetailP0J0(
      {this.num,
      this.sizeDetail,
      this.isSelected = false,

     // this.backFillFile,
      }) {
    this.sizeDetail = sizeDetail ?? SizeDetail();
  }

  ExpCellDetailP0J0.fromJson(dynamic json) {
    num = json['num'];
    sizeDetail = json['sizeDetail'] != null ? SizeDetail.fromJson(json['sizeDetail']) : null;
  }

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['num'] = num;
    if (sizeDetail != null) {
      map['sizeDetail'] = sizeDetail.toJson();
    }
    return map;
  }
}


class SizeDetail {
  int longSize; //长
  int wideSize; //宽
  int deepSize; //深

  SizeDetail({this.longSize, this.wideSize,this.deepSize});

  SizeDetail.fromJson(dynamic json) {
    longSize = json['longSize'];
    wideSize = json['wideSize'];
    deepSize = json['deepSize'];
  }

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['longSize'] = longSize;
    map['wideSize'] = wideSize;
    map['deepSize'] = deepSize;
    return map;
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
 List<List<ExpCellDetailP0J0>> _expCellSpecsList = [];

//批量设置
  _batchSet(ExpCellDetailP0J0 cellInfo){
    print('批量赋值');
    for (var row in _expCellSpecsList) {
      for (var cell in row) {
        cell.publishStatus = cellInfo.publishStatus;
        cell.row = cellInfo.row;
        cell.column = cellInfo.column;
        cell.buyChargeDetailList = cellInfo.buyChargeDetailList;
        cell.rateChargeDetailList = cellInfo.rateChargeDetailList;
        cell.userCellFileUrlPOJODetail = cellInfo.userCellFileUrlPOJODetail;
        cell.sizeDetail = cellInfo.sizeDetail;
        cell.isSelected = false;
        cell.backFillFile = cellInfo.backFillFile;
      }
    }
    setState(() {});
  }



_singleSet(){
                                        for (var row in _expCellSpecsList) {
                                          for (var cell in row) {
                                            print('cell =${cell.toJson()}');
                                          }
                                        }
                                        print(' row= $row   column= $column');
                                        ExpCellDetailP0J0 resultBean = result;
                                        print('填写前的回填:${_expCellSpecsList[row][column].toJson()}');
                                       // _expCellSpecsList[row][column].sizeDetail = resultBean.sizeDetail;
                                         _expCellSpecsList[row][column].sizeDetail.deepSize = resultBean.sizeDetail.deepSize;
                                         _expCellSpecsList[row][column].sizeDetail.longSize = resultBean.sizeDetail.longSize;
                               
                                      print('填写后的回填:${_expCellSpecsList[row][column].toJson()}');

                                        for (var row in _expCellSpecsList) {
                                          for (var cell in row) {
                                            print('cell2 =${cell.toJson()}');
                                          }
                                        }
                                        _setBackFillFile(row,column);
                                      setState(() {});
                                    }
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47

问题描述:给二维数组批量赋值后,再进行单个对象的深度赋值后_expCellSpecsList[row][column].sizeDetail.deepSize = resultBean.sizeDetail.deepSize;查询二维数组 print('cell2 =${cell.toJson()}');打印出来却是整个数组的deepSize参数都被赋值了;
更改:将赋值方法从_expCellSpecsList[row][column].sizeDetail.longSize = resultBean.sizeDetail.longSize;改为_expCellSpecsList[row][column].sizeDetail = resultBean.sizeDetail;后正常了。

问题原因在哪里?求路过的大神指点一下

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/493911
推荐阅读
相关标签
  

闽ICP备14008679号