@@ -6,6 +6,7 @@ import 'package:ht_dashboard/content_management/bloc/content_management_bloc.dar
6
6
import 'package:ht_dashboard/l10n/app_localizations.dart' ;
7
7
import 'package:ht_dashboard/l10n/l10n.dart' ;
8
8
import 'package:ht_dashboard/router/routes.dart' ;
9
+ import 'package:ht_dashboard/shared/constants/pagination_constants.dart' ;
9
10
import 'package:ht_dashboard/shared/constants/app_spacing.dart' ;
10
11
import 'package:ht_dashboard/shared/widgets/failure_state_widget.dart' ;
11
12
import 'package:ht_dashboard/shared/widgets/loading_state_widget.dart' ;
@@ -23,13 +24,11 @@ class SourcesPage extends StatefulWidget {
23
24
}
24
25
25
26
class _SourcesPageState extends State <SourcesPage > {
26
- static const int _rowsPerPage = 10 ;
27
-
28
27
@override
29
28
void initState () {
30
29
super .initState ();
31
30
context.read <ContentManagementBloc >().add (
32
- const LoadSourcesRequested (limit: _rowsPerPage ),
31
+ const LoadSourcesRequested (limit: kDefaultRowsPerPage ),
33
32
);
34
33
}
35
34
@@ -53,7 +52,7 @@ class _SourcesPageState extends State<SourcesPage> {
53
52
return FailureStateWidget (
54
53
message: state.errorMessage ?? l10n.unknownError,
55
54
onRetry: () => context.read <ContentManagementBloc >().add (
56
- const LoadSourcesRequested (limit: _rowsPerPage ),
55
+ const LoadSourcesRequested (limit: kDefaultRowsPerPage ),
57
56
),
58
57
);
59
58
}
@@ -86,17 +85,18 @@ class _SourcesPageState extends State<SourcesPage> {
86
85
source: _SourcesDataSource (
87
86
context: context,
88
87
sources: state.sources,
88
+ hasMore: state.sourcesHasMore,
89
89
l10n: l10n,
90
90
),
91
- rowsPerPage: _rowsPerPage ,
92
- availableRowsPerPage: const [_rowsPerPage ],
91
+ rowsPerPage: kDefaultRowsPerPage ,
92
+ availableRowsPerPage: const [kDefaultRowsPerPage ],
93
93
onPageChanged: (pageIndex) {
94
- final newOffset = pageIndex * _rowsPerPage ;
94
+ final newOffset = pageIndex * kDefaultRowsPerPage ;
95
95
if (newOffset >= state.sources.length && state.sourcesHasMore) {
96
96
context.read <ContentManagementBloc >().add (
97
97
LoadSourcesRequested (
98
98
startAfterId: state.sourcesCursor,
99
- limit: _rowsPerPage ,
99
+ limit: kDefaultRowsPerPage ,
100
100
),
101
101
);
102
102
}
@@ -120,16 +120,22 @@ class _SourcesDataSource extends DataTableSource {
120
120
_SourcesDataSource ({
121
121
required this .context,
122
122
required this .sources,
123
+ required this .hasMore,
123
124
required this .l10n,
124
125
});
125
126
126
127
final BuildContext context;
127
128
final List <Source > sources;
129
+ final bool hasMore;
128
130
final AppLocalizations l10n;
129
131
130
132
@override
131
133
DataRow ? getRow (int index) {
132
134
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.
133
139
return null ;
134
140
}
135
141
final source = sources[index];
@@ -168,10 +174,18 @@ class _SourcesDataSource extends DataTableSource {
168
174
}
169
175
170
176
@override
171
- bool get isRowCountApproximate => false ;
177
+ bool get isRowCountApproximate => true ;
172
178
173
179
@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
+ }
175
189
176
190
@override
177
191
int get selectedRowCount => 0 ;
0 commit comments