Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Raviteja11122 opened this issue Sep 4, 2022 · 4 comments
Labels
question Further information is requested

Comments

@Raviteja11122
Copy link

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
Copy link
Owner

Dev-Owl commented Sep 19, 2022

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.

@Dev-Owl Dev-Owl added the question Further information is requested label Sep 19, 2022
@Raviteja11122
Copy link
Author

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

@tsyahputra
Copy link

tsyahputra commented Nov 4, 2022

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
Copy link

Nikola0111 commented Nov 10, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants