@@ -27,8 +27,8 @@ class _TopicPageState extends State<TopicPage> {
27
27
void initState () {
28
28
super .initState ();
29
29
context.read <ContentManagementBloc >().add (
30
- const LoadTopicsRequested (limit: kDefaultRowsPerPage),
31
- );
30
+ const LoadTopicsRequested (limit: kDefaultRowsPerPage),
31
+ );
32
32
}
33
33
34
34
@override
@@ -51,56 +51,70 @@ class _TopicPageState extends State<TopicPage> {
51
51
return FailureStateWidget (
52
52
exception: state.exception! ,
53
53
onRetry: () => context.read <ContentManagementBloc >().add (
54
- const LoadTopicsRequested (limit: kDefaultRowsPerPage),
55
- ),
54
+ const LoadTopicsRequested (limit: kDefaultRowsPerPage),
55
+ ),
56
56
);
57
57
}
58
58
59
59
if (state.topics.isEmpty) {
60
60
return Center (child: Text (l10n.noTopicsFound));
61
61
}
62
62
63
- return PaginatedDataTable2 (
64
- columns: [
65
- DataColumn2 (label: Text (l10n.topicName), size: ColumnSize .L ),
66
- DataColumn2 (label: Text (l10n.status), size: ColumnSize .S ),
67
- DataColumn2 (label: Text (l10n.lastUpdated), size: ColumnSize .M ),
68
- DataColumn2 (
69
- label: Text (l10n.actions),
70
- size: ColumnSize .S ,
71
- fixedWidth: 120 ,
63
+ return Column (
64
+ children: [
65
+ if (state.topicsStatus == ContentManagementStatus .loading &&
66
+ state.topics.isNotEmpty)
67
+ const LinearProgressIndicator (),
68
+ Expanded (
69
+ child: PaginatedDataTable2 (
70
+ columns: [
71
+ DataColumn2 (
72
+ label: Text (l10n.topicName),
73
+ size: ColumnSize .L ,
74
+ ),
75
+ DataColumn2 (label: Text (l10n.status), size: ColumnSize .S ),
76
+ DataColumn2 (
77
+ label: Text (l10n.lastUpdated),
78
+ size: ColumnSize .M ,
79
+ ),
80
+ DataColumn2 (
81
+ label: Text (l10n.actions),
82
+ size: ColumnSize .S ,
83
+ fixedWidth: 120 ,
84
+ ),
85
+ ],
86
+ source: _TopicsDataSource (
87
+ context: context,
88
+ topics: state.topics,
89
+ hasMore: state.topicsHasMore,
90
+ l10n: l10n,
91
+ ),
92
+ rowsPerPage: kDefaultRowsPerPage,
93
+ availableRowsPerPage: const [kDefaultRowsPerPage],
94
+ onPageChanged: (pageIndex) {
95
+ final newOffset = pageIndex * kDefaultRowsPerPage;
96
+ if (newOffset >= state.topics.length &&
97
+ state.topicsHasMore &&
98
+ state.topicsStatus != ContentManagementStatus .loading) {
99
+ context.read <ContentManagementBloc >().add (
100
+ LoadTopicsRequested (
101
+ startAfterId: state.topicsCursor,
102
+ limit: kDefaultRowsPerPage,
103
+ ),
104
+ );
105
+ }
106
+ },
107
+ empty: Center (child: Text (l10n.noTopicsFound)),
108
+ showCheckboxColumn: false ,
109
+ showFirstLastButtons: true ,
110
+ fit: FlexFit .tight,
111
+ headingRowHeight: 56 ,
112
+ dataRowHeight: 56 ,
113
+ columnSpacing: AppSpacing .md,
114
+ horizontalMargin: AppSpacing .md,
115
+ ),
72
116
),
73
117
],
74
- source: _TopicsDataSource (
75
- context: context,
76
- topics: state.topics,
77
- isLoading: state.topicsStatus == ContentManagementStatus .loading,
78
- hasMore: state.topicsHasMore,
79
- l10n: l10n,
80
- ),
81
- rowsPerPage: kDefaultRowsPerPage,
82
- availableRowsPerPage: const [kDefaultRowsPerPage],
83
- onPageChanged: (pageIndex) {
84
- final newOffset = pageIndex * kDefaultRowsPerPage;
85
- if (newOffset >= state.topics.length &&
86
- state.topicsHasMore &&
87
- state.topicsStatus != ContentManagementStatus .loading) {
88
- context.read <ContentManagementBloc >().add (
89
- LoadTopicsRequested (
90
- startAfterId: state.topicsCursor,
91
- limit: kDefaultRowsPerPage,
92
- ),
93
- );
94
- }
95
- },
96
- empty: Center (child: Text (l10n.noTopicsFound)),
97
- showCheckboxColumn: false ,
98
- showFirstLastButtons: true ,
99
- fit: FlexFit .tight,
100
- headingRowHeight: 56 ,
101
- dataRowHeight: 56 ,
102
- columnSpacing: AppSpacing .md,
103
- horizontalMargin: AppSpacing .md,
104
118
);
105
119
},
106
120
),
@@ -112,30 +126,18 @@ class _TopicsDataSource extends DataTableSource {
112
126
_TopicsDataSource ({
113
127
required this .context,
114
128
required this .topics,
115
- required this .isLoading,
116
129
required this .hasMore,
117
130
required this .l10n,
118
131
});
119
132
120
133
final BuildContext context;
121
134
final List <Topic > topics;
122
- final bool isLoading;
123
135
final bool hasMore;
124
136
final AppLocalizations l10n;
125
137
126
138
@override
127
139
DataRow ? getRow (int index) {
128
140
if (index >= topics.length) {
129
- // This can happen if hasMore is true and the user is on the last page.
130
- // If we are loading, show a spinner. Otherwise, we've reached the end.
131
- if (isLoading) {
132
- return DataRow2 (
133
- cells: List .generate (
134
- 4 ,
135
- (_) => const DataCell (Center (child: CircularProgressIndicator ())),
136
- ),
137
- );
138
- }
139
141
return null ;
140
142
}
141
143
final topic = topics[index];
@@ -182,8 +184,8 @@ class _TopicsDataSource extends DataTableSource {
182
184
onPressed: () {
183
185
// Dispatch delete event
184
186
context.read <ContentManagementBloc >().add (
185
- ArchiveTopicRequested (topic.id),
186
- );
187
+ ArchiveTopicRequested (topic.id),
188
+ );
187
189
},
188
190
),
189
191
],
@@ -198,16 +200,6 @@ class _TopicsDataSource extends DataTableSource {
198
200
199
201
@override
200
202
int get rowCount {
201
- // If we have more items to fetch, we add 1 to the current length.
202
- // This signals to PaginatedDataTable2 that there is at least one more page,
203
- // which enables the 'next page' button.
204
- if (hasMore) {
205
- // When loading, we show an extra row for the spinner.
206
- // Otherwise, we just indicate that there are more rows.
207
- return isLoading
208
- ? topics.length + 1
209
- : topics.length + kDefaultRowsPerPage;
210
- }
211
203
return topics.length;
212
204
}
213
205
0 commit comments