Skip to content

Commit 4a85632

Browse files
committed
reformat: create list of children
1 parent 4b2a25d commit 4a85632

1 file changed

Lines changed: 89 additions & 80 deletions

File tree

kitchenowl/lib/pages/household_page/planner.dart

Lines changed: 89 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,47 @@ class _PlannerPageState extends State<PlannerPage> {
176176
SliverPadding(
177177
padding: const EdgeInsets.symmetric(horizontal: 16),
178178
sliver: SliverLayoutBuilder(
179-
builder: (context, constraints) => SliverToBoxAdapter(
180-
child: Wrap(
181-
crossAxisAlignment: WrapCrossAlignment.end,
182-
alignment: WrapAlignment.start,
183-
children: [
184-
for (final plan in state.getPlannedWithoutDay())
179+
builder: (context, constraints) {
180+
final children = <Widget>[];
181+
182+
for (final plan in state.getPlannedWithoutDay()) {
183+
children.add(
184+
KitchenOwlFractionallySizedBox(
185+
widthFactor: (1 /
186+
DynamicStyling.itemCrossAxisCount(
187+
constraints.crossAxisExtent,
188+
context
189+
.read<SettingsCubit>()
190+
.state
191+
.gridSize,
192+
)),
193+
child: AspectRatio(
194+
aspectRatio: 1,
195+
child: SelectableButtonCard(
196+
key: ValueKey(plan.recipe.id),
197+
title: plan.recipe.name,
198+
selected: true,
199+
description: plan.yields?.toString(),
200+
onPressed: () {
201+
cubit.remove(plan.recipe);
202+
},
203+
onLongPressed: () => _openRecipePage(
204+
context,
205+
cubit,
206+
plan.recipe,
207+
plan.yields,
208+
),
209+
),
210+
),
211+
),
212+
);
213+
}
214+
215+
for (final cookingDate
216+
in state.getUniqueCookingDays()) {
217+
for (final plan
218+
in state.getPlannedOfDate(cookingDate)) {
219+
children.add(
185220
KitchenOwlFractionallySizedBox(
186221
widthFactor: (1 /
187222
DynamicStyling.itemCrossAxisCount(
@@ -191,85 +226,59 @@ class _PlannerPageState extends State<PlannerPage> {
191226
.state
192227
.gridSize,
193228
)),
194-
child: AspectRatio(
195-
aspectRatio: 1,
196-
child: SelectableButtonCard(
197-
key: ValueKey(plan.recipe.id),
198-
title: plan.recipe.name,
199-
selected: true,
200-
description: plan.yields?.toString(),
201-
onPressed: () {
202-
cubit.remove(plan.recipe);
203-
},
204-
onLongPressed: () => _openRecipePage(
205-
context,
206-
cubit,
207-
plan.recipe,
208-
plan.yields,
209-
),
210-
),
211-
),
212-
),
213-
for (final cookingDate
214-
in state.getUniqueCookingDays())
215-
for (final plan
216-
in state.getPlannedOfDate(cookingDate))
217-
KitchenOwlFractionallySizedBox(
218-
widthFactor: (1 /
219-
DynamicStyling.itemCrossAxisCount(
220-
constraints.crossAxisExtent,
221-
context
222-
.read<SettingsCubit>()
223-
.state
224-
.gridSize,
225-
)),
226-
child: Column(
227-
mainAxisSize: MainAxisSize.min,
228-
crossAxisAlignment:
229-
CrossAxisAlignment.stretch,
230-
children: [
231-
if (plan ==
232-
state
233-
.getPlannedOfDate(cookingDate)[0])
234-
Padding(
235-
padding:
236-
const EdgeInsets.only(top: 5),
237-
child: Text(
238-
'${_formatDate(context, daysBetween(DateTime.now(), cookingDate))}',
239-
style: Theme.of(context)
240-
.textTheme
241-
.bodyLarge,
242-
),
229+
child: Column(
230+
mainAxisSize: MainAxisSize.min,
231+
crossAxisAlignment:
232+
CrossAxisAlignment.stretch,
233+
children: [
234+
if (plan ==
235+
state.getPlannedOfDate(cookingDate)[0])
236+
Padding(
237+
padding: const EdgeInsets.only(top: 5),
238+
child: Text(
239+
'${_formatDate(context, daysBetween(DateTime.now(), cookingDate))}',
240+
style: Theme.of(context)
241+
.textTheme
242+
.bodyLarge,
243243
),
244-
AspectRatio(
245-
aspectRatio: 1,
246-
child: SelectableButtonCard(
247-
key: ValueKey(
248-
plan.recipe.id,
249-
),
250-
title: plan.recipe.name,
251-
description: plan.yields?.toString(),
252-
selected: true,
253-
onPressed: () {
254-
cubit.remove(
255-
plan.recipe,
256-
plan.cookingDate,
257-
);
258-
},
259-
onLongPressed: () => _openRecipePage(
260-
context,
261-
cubit,
244+
),
245+
AspectRatio(
246+
aspectRatio: 1,
247+
child: SelectableButtonCard(
248+
key: ValueKey(
249+
plan.recipe.id,
250+
),
251+
title: plan.recipe.name,
252+
description: plan.yields?.toString(),
253+
selected: true,
254+
onPressed: () {
255+
cubit.remove(
262256
plan.recipe,
263-
plan.yields,
264-
),
257+
plan.cookingDate,
258+
);
259+
},
260+
onLongPressed: () => _openRecipePage(
261+
context,
262+
cubit,
263+
plan.recipe,
264+
plan.yields,
265265
),
266266
),
267-
],
268-
),
267+
),
268+
],
269269
),
270-
],
271-
),
272-
),
270+
),
271+
);
272+
}
273+
}
274+
return SliverToBoxAdapter(
275+
child: Wrap(
276+
crossAxisAlignment: WrapCrossAlignment.end,
277+
alignment: WrapAlignment.start,
278+
children: children,
279+
),
280+
);
281+
},
273282
),
274283
),
275284
if (state.recentRecipes.isNotEmpty)

0 commit comments

Comments
 (0)