@@ -57,9 +57,6 @@ class _DashboardPageState extends State<DashboardPage> {
57
57
children: [
58
58
LayoutBuilder (
59
59
builder: (context, constraints) {
60
- const tabletBreakpoint = 800 ;
61
- final isNarrow = constraints.maxWidth < tabletBreakpoint;
62
-
63
60
final summaryCards = [
64
61
_SummaryCard (
65
62
icon: Icons .newspaper_outlined,
@@ -78,27 +75,39 @@ class _DashboardPageState extends State<DashboardPage> {
78
75
),
79
76
];
80
77
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
92
93
}
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 (),
102
111
);
103
112
},
104
113
),
0 commit comments