• 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;后正常了。

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

  • 相关阅读:
    请求地址‘/operlog‘,发生未知异常
    10.网络编程套接字Socket
    linux系统配置之单一网卡配置多个不同网段IP(centos)
    MySQL四种备份表的方式
    Asp .Net Core 系列:集成 Consul 实现 服务注册与健康检查
    CentOS 7搭建Yunzai-Bot原神机器人
    群晖synology DSM 7.2设置钉钉Webhooks通知
    2022新版Python+大数据学习路线图,附视频教程
    IDEA中maven jar下载失败问题处理
    WebFlux如何编写异步的代码
  • 原文地址:https://blog.csdn.net/androidhyf/article/details/137952179