Change passkeys gridview breakpoints

This commit is contained in:
Elias Bonnici 2024-06-17 11:16:14 +02:00
parent 574e63e147
commit 3b8e4571b6
No known key found for this signature in database
GPG Key ID: 5EAC28EA3F980CCF
2 changed files with 40 additions and 2 deletions

View File

@ -589,6 +589,7 @@ class _FidoUnlockedPageState extends ConsumerState<_FidoUnlockedPage> {
selected: _selected == cred,
),
layout: layout,
getItemsPerRow: _getItemsPerRow,
)
],
);
@ -600,6 +601,36 @@ class _FidoUnlockedPageState extends ConsumerState<_FidoUnlockedPage> {
);
}
int _getItemsPerRow(double width) {
int itemsPerRow = 1;
if (width <= 600) {
// single column
itemsPerRow = 1;
} else if (width <= 900) {
// 2 column
itemsPerRow = 2;
} else if (width < 1300) {
// 3 column
itemsPerRow = 3;
} else if (width < 1500) {
// 4 column
itemsPerRow = 4;
} else if (width < 1700) {
// 5 column
itemsPerRow = 5;
} else if (width < 1900) {
// 6 column
itemsPerRow = 6;
} else if (width < 2100) {
// 7 column
itemsPerRow = 7;
} else {
// 8 column
itemsPerRow = 8;
}
return itemsPerRow;
}
Widget _buildLoadingPage(BuildContext context) => AppPage(
title: AppLocalizations.of(context)!.s_passkeys,
capabilities: const [Capability.fido2],

View File

@ -5,17 +5,19 @@ enum FlexLayout { grid, list }
class FlexBox<T> extends StatelessWidget {
final List<T> items;
final Widget Function(T value) itemBuilder;
final int Function(double width)? getItemsPerRow;
final FlexLayout layout;
final double? runSpacing;
const FlexBox({
super.key,
required this.items,
required this.itemBuilder,
this.getItemsPerRow,
this.layout = FlexLayout.list,
this.runSpacing,
});
int getItemsPerRow(double width) {
int _getItemsPerRow(double width) {
int itemsPerRow = 1;
if (layout == FlexLayout.grid) {
if (width <= 420) {
@ -34,10 +36,13 @@ class FlexBox<T> extends StatelessWidget {
// 5 column
itemsPerRow = 5;
} else if (width < 1800) {
// 6 column
itemsPerRow = 6;
} else if (width < 2000) {
// 7 column
itemsPerRow = 7;
} else {
// 8 column
itemsPerRow = 8;
}
}
@ -65,7 +70,9 @@ class FlexBox<T> extends StatelessWidget {
return LayoutBuilder(
builder: (context, constraints) {
final width = constraints.maxWidth;
final itemsPerRow = getItemsPerRow(width);
final itemsPerRow = layout == FlexLayout.grid
? getItemsPerRow?.call(width) ?? _getItemsPerRow(width)
: 1;
final chunks = getChunks(itemsPerRow);
return Column(