Skip to content

Commit 89e049e

Browse files
committed
refactor(dashboard): implement responsive wrapping for summary cards
- Replace fixed layout with a responsive wrap layout for summary cards - Calculate item width dynamically based on available space - Support for wrapping cards into multiple rows on
1 parent 4a561b5 commit 89e049e

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

lib/dashboard/view/dashboard_page.dart

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ class _DashboardPageState extends State<DashboardPage> {
5757
children: [
5858
LayoutBuilder(
5959
builder: (context, constraints) {
60-
const tabletBreakpoint = 800;
61-
final isNarrow = constraints.maxWidth < tabletBreakpoint;
62-
6360
final summaryCards = [
6461
_SummaryCard(
6562
icon: Icons.newspaper_outlined,
@@ -78,27 +75,39 @@ class _DashboardPageState extends State<DashboardPage> {
7875
),
7976
];
8077

81-
if (isNarrow) {
82-
return Column(
83-
crossAxisAlignment: CrossAxisAlignment.stretch,
84-
children: [
85-
summaryCards[0],
86-
const SizedBox(height: AppSpacing.lg),
87-
summaryCards[1],
88-
const SizedBox(height: AppSpacing.lg),
89-
summaryCards[2],
90-
],
91-
);
78+
// Calculate item width for responsive wrapping
79+
// Aim for 3 cards per row on wider screens, 2 on medium, 1 on narrow
80+
final double totalWidth = constraints.maxWidth;
81+
const double minCardWidth =
82+
280; // Minimum readable width for a card
83+
const double spacing = AppSpacing.lg;
84+
85+
// Calculate how many cards can fit in a row
86+
int crossAxisCount = (totalWidth / (minCardWidth + spacing))
87+
.floor();
88+
if (crossAxisCount == 0)
89+
crossAxisCount = 1; // Ensure at least one card
90+
if (crossAxisCount > summaryCards.length) {
91+
crossAxisCount =
92+
summaryCards.length; // Don't exceed number of cards
9293
}
93-
return Row(
94-
crossAxisAlignment: CrossAxisAlignment.start,
95-
children: [
96-
Expanded(child: summaryCards[0]),
97-
const SizedBox(width: AppSpacing.lg),
98-
Expanded(child: summaryCards[1]),
99-
const SizedBox(width: AppSpacing.lg),
100-
Expanded(child: summaryCards[2]),
101-
],
94+
95+
final double itemWidth =
96+
(totalWidth - (spacing * (crossAxisCount - 1))) /
97+
crossAxisCount;
98+
99+
return Wrap(
100+
spacing: spacing, // Horizontal space between cards
101+
runSpacing: spacing, // Vertical space between rows
102+
alignment: WrapAlignment.start,
103+
children: summaryCards
104+
.map(
105+
(card) => SizedBox(
106+
width: itemWidth,
107+
child: card,
108+
),
109+
)
110+
.toList(),
102111
);
103112
},
104113
),

0 commit comments

Comments
 (0)