Dev-Owl / advanced_datatable

Advanced Datatable uses the Fultter PaginatedDataTable Widget and adds a few more functions to it
BSD 3-Clause "New" or "Revised" License
16 stars 16 forks source link

Getting null error when using "lastDetails" in getRow and in "customFooter" aswell #26

Open Raviteja11122 opened 2 years ago

Raviteja11122 commented 2 years ago

class ExampleSource extends AdvancedDataTableSource<HelpRequestModel> {
  final data = List<HelpRequestModel>.generate(
    100,
    (index) => HelpRequestModel(
      concernType: lorem(paragraphs: 1, words: 2),
      concernSubType: lorem(paragraphs: 1, words: 3),
      issueIdentifier: lorem(paragraphs: 1, words: 5),
      summaryDetails: lorem(paragraphs: 1, words: 10),
      date: "20/11/2021",
      time: "15:54.34",
      status: lorem(paragraphs: 1, words: 2)
    )
  );

  @override
  DataRow? getRow(int index) {
    final currentRowData = lastDetails!.rows[index];
    return DataRow(
      cells: [
        DataCell(Text((index + 1).toString(), style: TextStyle(fontSize: 12.sp))),
        DataCell(Text(currentRowData.concernType ?? "", style: TextStyle(fontSize: 12.sp))),
        DataCell(Text(currentRowData.concernSubType ?? "", style: TextStyle(fontSize: 12.sp))),
        DataCell(Text(currentRowData.issueIdentifier ?? "", style: TextStyle(fontSize: 12.sp))),
        DataCell(Text(currentRowData.summaryDetails ?? "", style: TextStyle(fontSize: 12.sp))),
        DataCell(Text(currentRowData.date ?? "", style: TextStyle(fontSize: 12.sp))),
        DataCell(Text(currentRowData.time ?? "", style: TextStyle(fontSize: 12.sp))),
        DataCell(Text(currentRowData.status ?? "", style: TextStyle(fontSize: 12.sp))),
        DataCell(
          Row(
            children: [
              Container(
                width: 30,
                height: 30,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  borderRadius: const BorderRadius.all(Radius.circular(15)).r,
                  border: Border.all(color: ColorName.performanceProgressBgColor, width: 1),
                ),
                child: Icon(Icons.visibility_outlined, size: 18.r)
              ),
              13.72.horizontalSpace,
              Icon(Icons.delete_outlined, size: 20.r, color: ColorName.defaultFontColor)
            ]
          )
        ),
      ],
    );
  }

  @override
  int get selectedRowCount => 0;

  @override
  Future<RemoteDataSourceDetails<HelpRequestModel>> getNextPage(
      NextPageRequest pageRequest) async {
    return RemoteDataSourceDetails(
      data.length,
      data
          .skip(pageRequest.offset)
          .take(pageRequest.pageSize)
          .toList(), //again in a real world example you would only get the right amount of rows
    );
  }
}

AdvancedPaginatedDataTable(
                addEmptyRows: false,
                source: model.source,
                showHorizontalScrollbarAlways: true,
                rowsPerPage: model.rowsPerPage,
                //availableRowsPerPage: const [10, 20, 30, 50],
                onRowsPerPageChanged: model.setRowsPerPage,
                columns: [
                  DataColumn(
                    label: Text('Sl No.', style: Theme.of(context).textTheme.caption!.copyWith(
                      color: ColorName.primary
                    )),
                    numeric: true,
                  ),
                  DataColumn(
                    label: Text('Concern Type', style: Theme.of(context).textTheme.caption!.copyWith(
                        color: ColorName.primary
                    )),
                  ),
                  DataColumn(
                    label: Text('Concern Sub Type', style: Theme.of(context).textTheme.caption!.copyWith(
                        color: ColorName.primary
                    )),
                  ),
                  DataColumn(
                    label: Text('Issue Identifier', style: Theme.of(context).textTheme.caption!.copyWith(
                        color: ColorName.primary
                    )),
                  ),
                  DataColumn(
                    label: Text('Summary Details', style: Theme.of(context).textTheme.caption!.copyWith(
                        color: ColorName.primary
                    )),
                  ),
                  DataColumn(
                    label: Text('Date', style: Theme.of(context).textTheme.caption!.copyWith(
                        color: ColorName.primary
                    )),
                  ),
                  DataColumn(
                    label: Text('Time', style: Theme.of(context).textTheme.caption!.copyWith(
                        color: ColorName.primary
                    )),
                  ),
                  DataColumn(
                    label: Text('Status', style: Theme.of(context).textTheme.caption!.copyWith(
                        color: ColorName.primary
                    )),
                  ),
                  DataColumn(
                    label: Text('Action', style: Theme.of(context).textTheme.caption!.copyWith(
                        color: ColorName.primary
                    )),
                  ),
                ],
              )```
Dev-Owl commented 2 years ago

lastDetails is nullable and can be null if no data was requested from the server or if there was an error in the communication. You can't use the field before the first successful request.

Raviteja11122 commented 2 years ago

I was generating dummy data in the above example there is no api call involved

tsyahputra commented 1 year ago

Me too. i've got same error message "Unexpected null value" when changing rows per page in Flutter web.

I've got solution for my case by calling notifyListeners() inside onRowsPerPageChanged. Thx.

Nikola0111 commented 1 year ago

Same as @Raviteja11122 , im using dummy data. When first showing the page the exception is thrown, solved it by wrapping everything with check if lastDetails is not null