Skip to content

Commit a13e9d2

Browse files
committed
feat(dashboard): make summary cards responsive
Replaces the `Wrap` widget for the summary cards with a `LayoutBuilder`. This allows the layout to switch from a `Row` on wider screens to a `Column` on narrower screens, ensuring the cards utilize the available space effectively and stack vertically when needed.
1 parent b714841 commit a13e9d2

File tree

1 file changed

+46
-20
lines changed

1 file changed

+46
-20
lines changed

lib/dashboard/view/dashboard_page.dart

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,52 @@ class _DashboardPageState extends State<DashboardPage> {
5858
return ListView(
5959
padding: const EdgeInsets.all(AppSpacing.lg),
6060
children: [
61-
Wrap(
62-
spacing: AppSpacing.lg,
63-
runSpacing: AppSpacing.lg,
64-
children: [
65-
_SummaryCard(
66-
icon: Icons.article_outlined,
67-
title: l10n.totalHeadlines,
68-
value: summary.headlineCount.toString(),
69-
),
70-
_SummaryCard(
71-
icon: Icons.category_outlined,
72-
title: l10n.totalCategories,
73-
value: summary.categoryCount.toString(),
74-
),
75-
_SummaryCard(
76-
icon: Icons.source_outlined,
77-
title: l10n.totalSources,
78-
value: summary.sourceCount.toString(),
79-
),
80-
],
61+
LayoutBuilder(
62+
builder: (context, constraints) {
63+
const tabletBreakpoint = 800;
64+
final isNarrow = constraints.maxWidth < tabletBreakpoint;
65+
66+
final summaryCards = [
67+
_SummaryCard(
68+
icon: Icons.article_outlined,
69+
title: l10n.totalHeadlines,
70+
value: summary.headlineCount.toString(),
71+
),
72+
_SummaryCard(
73+
icon: Icons.category_outlined,
74+
title: l10n.totalCategories,
75+
value: summary.categoryCount.toString(),
76+
),
77+
_SummaryCard(
78+
icon: Icons.source_outlined,
79+
title: l10n.totalSources,
80+
value: summary.sourceCount.toString(),
81+
),
82+
];
83+
84+
if (isNarrow) {
85+
return Column(
86+
crossAxisAlignment: CrossAxisAlignment.stretch,
87+
children: [
88+
summaryCards[0],
89+
const SizedBox(height: AppSpacing.lg),
90+
summaryCards[1],
91+
const SizedBox(height: AppSpacing.lg),
92+
summaryCards[2],
93+
],
94+
);
95+
}
96+
return Row(
97+
crossAxisAlignment: CrossAxisAlignment.start,
98+
children: [
99+
Expanded(child: summaryCards[0]),
100+
const SizedBox(width: AppSpacing.lg),
101+
Expanded(child: summaryCards[1]),
102+
const SizedBox(width: AppSpacing.lg),
103+
Expanded(child: summaryCards[2]),
104+
],
105+
);
106+
},
81107
),
82108
const SizedBox(height: AppSpacing.lg),
83109
Row(

0 commit comments

Comments
 (0)