@@ -6,6 +6,7 @@ import 'package:ht_dashboard/content_management/bloc/content_management_bloc.dar
66import 'package:ht_dashboard/l10n/app_localizations.dart' ;
77import 'package:ht_dashboard/l10n/l10n.dart' ;
88import 'package:ht_dashboard/router/routes.dart' ;
9+ import 'package:ht_dashboard/shared/constants/pagination_constants.dart' ;
910import 'package:ht_dashboard/shared/constants/app_spacing.dart' ;
1011import 'package:ht_dashboard/shared/widgets/failure_state_widget.dart' ;
1112import 'package:ht_dashboard/shared/widgets/loading_state_widget.dart' ;
@@ -23,13 +24,11 @@ class SourcesPage extends StatefulWidget {
2324}
2425
2526class _SourcesPageState extends State <SourcesPage > {
26- static const int _rowsPerPage = 10 ;
27-
2827 @override
2928 void initState () {
3029 super .initState ();
3130 context.read <ContentManagementBloc >().add (
32- const LoadSourcesRequested (limit: _rowsPerPage ),
31+ const LoadSourcesRequested (limit: kDefaultRowsPerPage ),
3332 );
3433 }
3534
@@ -53,7 +52,7 @@ class _SourcesPageState extends State<SourcesPage> {
5352 return FailureStateWidget (
5453 message: state.errorMessage ?? l10n.unknownError,
5554 onRetry: () => context.read <ContentManagementBloc >().add (
56- const LoadSourcesRequested (limit: _rowsPerPage ),
55+ const LoadSourcesRequested (limit: kDefaultRowsPerPage ),
5756 ),
5857 );
5958 }
@@ -86,17 +85,18 @@ class _SourcesPageState extends State<SourcesPage> {
8685 source: _SourcesDataSource (
8786 context: context,
8887 sources: state.sources,
88+ hasMore: state.sourcesHasMore,
8989 l10n: l10n,
9090 ),
91- rowsPerPage: _rowsPerPage ,
92- availableRowsPerPage: const [_rowsPerPage ],
91+ rowsPerPage: kDefaultRowsPerPage ,
92+ availableRowsPerPage: const [kDefaultRowsPerPage ],
9393 onPageChanged: (pageIndex) {
94- final newOffset = pageIndex * _rowsPerPage ;
94+ final newOffset = pageIndex * kDefaultRowsPerPage ;
9595 if (newOffset >= state.sources.length && state.sourcesHasMore) {
9696 context.read <ContentManagementBloc >().add (
9797 LoadSourcesRequested (
9898 startAfterId: state.sourcesCursor,
99- limit: _rowsPerPage ,
99+ limit: kDefaultRowsPerPage ,
100100 ),
101101 );
102102 }
@@ -120,16 +120,22 @@ class _SourcesDataSource extends DataTableSource {
120120 _SourcesDataSource ({
121121 required this .context,
122122 required this .sources,
123+ required this .hasMore,
123124 required this .l10n,
124125 });
125126
126127 final BuildContext context;
127128 final List <Source > sources;
129+ final bool hasMore;
128130 final AppLocalizations l10n;
129131
130132 @override
131133 DataRow ? getRow (int index) {
132134 if (index >= sources.length) {
135+ // This can happen if hasMore is true and the user is on the last page.
136+ // The table will try to build one extra row that is out of bounds.
137+ // We return null to signify the end of the available data.
138+ // The onPageChanged callback will handle fetching more data.
133139 return null ;
134140 }
135141 final source = sources[index];
@@ -168,10 +174,18 @@ class _SourcesDataSource extends DataTableSource {
168174 }
169175
170176 @override
171- bool get isRowCountApproximate => false ;
177+ bool get isRowCountApproximate => true ;
172178
173179 @override
174- int get rowCount => sources.length;
180+ int get rowCount {
181+ // If we have more items to fetch, we add 1 to the current length.
182+ // This signals to PaginatedDataTable2 that there is at least one more page,
183+ // which enables the 'next page' button.
184+ if (hasMore) {
185+ return sources.length + 1 ;
186+ }
187+ return sources.length;
188+ }
175189
176190 @override
177191 int get selectedRowCount => 0 ;
0 commit comments