Skip to content

Conversation

@sushil7271
Copy link

@sushil7271 sushil7271 commented Mar 18, 2025

Title: Implement "No Data" Handling and View in PagedDataTable Widget

Description

Problem:

Previously, the table widget did not have a clear way to handle situations where no data was available to display. This could lead to an empty or confusing UI for the user.

Solution:

This pull request introduces robust support for "no data" scenarios in the PagedDataTable widget by:

  1. New noDataView Widget Parameter:
    • Added a new optional widget parameter called noDataView to the PagedDataTable widget.
    • This parameter allows developers to provide a custom widget to display when the table has no data.
    • If this parameter is not set, the code will use a SizedBox.shrink().
  2. Conditional "No Data" View Display:
    • Implemented a conditional check within the table widget to detect "no data" situations.
    • The condition is as follows: if (tableController._state == _TableState.noData && tableController._currentDataset.isEmpty).
    • When this condition is met, the table will display the noDataView widget (if provided) instead of the empty table.
  3. New _TableState.noData State:
    • Added a new state, _TableState.noData, to the _TableState enum.
    • This state specifically represents the "no data" condition of the table.
  4. Triggering Notification Listeners:
    • Ensured that the notification listeners are correctly triggered when the table enters the _TableState.noData state. This ensures that the UI updates appropriately.
    • The notifyListeners method was called in the correct place.

Impact:

  • Improved User Experience: Users will now see a clear and informative message or custom view when no data is available in the table.
  • Flexibility: Developers can customize the "no data" view to match the design and requirements of their application.
  • Robustness: The table widget is now more robust in handling empty data scenarios.
  • Readability: the code is now more readable.

Files Changed:

  • controller.dart: Modified to add the new state, the conditional check, and trigger the notification.
  • paged_datatable.dart: (If present) Added the noDataView parameter to the Table widget and conditional check.

How to Test:

  1. Simulate No Data: Modify your data fetching logic or filters to simulate a scenario where the pagedDataTable receives no data.
  2. Verify No Data View: Check that the noDataView widget (if provided) is displayed in the table area.
  3. Verify Empty Space: If you don't use noDataView, ensure that an empty space is displayed.
  4. Verify state: Check that the state changes correctly.
  5. Verify notification: Check that the listeners are called.
Screenshot 2025-03-18 at 4 57 33 PM CC: @tomasweigenast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant