Skip to content

Commit 7556d2f

Browse files
committed
feat(user_management): optimize users table for mobile view
- Add LayoutBuilder to determine screen width - Implement conditional rendering of subscription column based on device type - Improve table styling and responsiveness
1 parent 3d0e8f1 commit 7556d2f

File tree

1 file changed

+67
-57
lines changed

1 file changed

+67
-57
lines changed

lib/user_management/view/users_page.dart

Lines changed: 67 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -120,64 +120,71 @@ class _UsersPageState extends State<UsersPage> {
120120
state.users.isNotEmpty)
121121
const LinearProgressIndicator(),
122122
Expanded(
123-
child: PaginatedDataTable2(
124-
columns: [
125-
DataColumn2(
126-
label: Text(l10n.email),
127-
size: ColumnSize.L,
128-
),
129-
DataColumn2(
130-
label: Text(l10n.authentication),
131-
size: ColumnSize.S,
132-
),
133-
DataColumn2(
134-
label: Text(l10n.subscription),
135-
size: ColumnSize.S,
136-
),
137-
DataColumn2(
138-
label: Text(l10n.createdAt),
139-
size: ColumnSize.S,
140-
),
141-
DataColumn2(
142-
label: Text(l10n.actions),
143-
size: ColumnSize.S,
144-
),
145-
],
146-
source: _UsersDataSource(
147-
context: context,
148-
users: state.users,
149-
hasMore: state.hasMore,
150-
l10n: l10n,
151-
),
152-
rowsPerPage: kDefaultRowsPerPage,
153-
availableRowsPerPage: const [kDefaultRowsPerPage],
154-
onPageChanged: (pageIndex) {
155-
// Handle pagination: fetch next page if needed.
156-
final newOffset = pageIndex * kDefaultRowsPerPage;
157-
if (newOffset >= state.users.length &&
158-
state.hasMore &&
159-
state.status != UserManagementStatus.loading) {
160-
context.read<UserManagementBloc>().add(
161-
LoadUsersRequested(
162-
startAfterId: state.cursor,
163-
limit: kDefaultRowsPerPage,
164-
filter: context
165-
.read<UserManagementBloc>()
166-
.buildUsersFilterMap(
167-
context.read<UserFilterBloc>().state,
168-
),
123+
child: LayoutBuilder(
124+
builder: (context, constraints) {
125+
final isMobile = constraints.maxWidth < 600;
126+
return PaginatedDataTable2(
127+
columns: [
128+
DataColumn2(
129+
label: Text(l10n.email),
130+
size: ColumnSize.L,
169131
),
170-
);
171-
}
132+
DataColumn2(
133+
label: Text(l10n.authentication),
134+
size: ColumnSize.S,
135+
),
136+
if (!isMobile)
137+
DataColumn2(
138+
label: Text(l10n.subscription),
139+
size: ColumnSize.S,
140+
),
141+
DataColumn2(
142+
label: Text(l10n.createdAt),
143+
size: ColumnSize.S,
144+
),
145+
DataColumn2(
146+
label: Text(l10n.actions),
147+
size: ColumnSize.S,
148+
),
149+
],
150+
source: _UsersDataSource(
151+
context: context,
152+
users: state.users,
153+
hasMore: state.hasMore,
154+
l10n: l10n,
155+
isMobile: isMobile,
156+
),
157+
rowsPerPage: kDefaultRowsPerPage,
158+
availableRowsPerPage: const [kDefaultRowsPerPage],
159+
onPageChanged: (pageIndex) {
160+
// Handle pagination: fetch next page if needed.
161+
final newOffset = pageIndex * kDefaultRowsPerPage;
162+
if (newOffset >= state.users.length &&
163+
state.hasMore &&
164+
state.status != UserManagementStatus.loading) {
165+
context.read<UserManagementBloc>().add(
166+
LoadUsersRequested(
167+
startAfterId: state.cursor,
168+
limit: kDefaultRowsPerPage,
169+
filter: context
170+
.read<UserManagementBloc>()
171+
.buildUsersFilterMap(
172+
context.read<UserFilterBloc>().state,
173+
),
174+
),
175+
);
176+
}
177+
},
178+
empty: Center(child: Text(l10n.noUsersFound)),
179+
showCheckboxColumn: false,
180+
showFirstLastButtons: true,
181+
fit: FlexFit.tight,
182+
headingRowHeight: 56,
183+
dataRowHeight: 56,
184+
columnSpacing: AppSpacing.sm,
185+
horizontalMargin: AppSpacing.sm,
186+
);
172187
},
173-
empty: Center(child: Text(l10n.noUsersFound)),
174-
showCheckboxColumn: false,
175-
showFirstLastButtons: true,
176-
fit: FlexFit.tight,
177-
headingRowHeight: 56,
178-
dataRowHeight: 56,
179-
columnSpacing: AppSpacing.sm,
180-
horizontalMargin: AppSpacing.sm,
181188
),
182189
),
183190
],
@@ -195,12 +202,14 @@ class _UsersDataSource extends DataTableSource {
195202
required this.users,
196203
required this.hasMore,
197204
required this.l10n,
205+
required this.isMobile,
198206
});
199207

200208
final BuildContext context;
201209
final List<User> users;
202210
final bool hasMore;
203211
final AppLocalizations l10n;
212+
final bool isMobile;
204213

205214
@override
206215
DataRow? getRow(int index) {
@@ -227,7 +236,8 @@ class _UsersDataSource extends DataTableSource {
227236
),
228237
),
229238
DataCell(Text(user.appRole.authenticationStatusL10n(context))),
230-
DataCell(Text(user.appRole.subscriptionStatusL10n(context))),
239+
if (!isMobile)
240+
DataCell(Text(user.appRole.subscriptionStatusL10n(context))),
231241
DataCell(
232242
Text(
233243
DateFormat('dd-MM-yyyy').format(user.createdAt.toLocal()),

0 commit comments

Comments
 (0)