Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/core/presentation/widgets/copy_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ import 'package:opennutritracker/features/add_meal/presentation/add_meal_type.da
import 'package:opennutritracker/generated/l10n.dart';

class CopyDialog extends StatefulWidget {
const CopyDialog({super.key});
final AddMealType initialValue;

const CopyDialog({super.key, required this.initialValue});
@override
State<StatefulWidget> createState() {
return CopyDialogState();
}
}

class CopyDialogState extends State<CopyDialog> {
AddMealType _selectedValue = AddMealType.breakfastType;
late AddMealType _selectedValue;

AddMealType get selectedMealType => _selectedValue;

@override
void initState() {
super.initState();
_selectedValue = widget.initialValue;
}

@override
Expand Down
12 changes: 11 additions & 1 deletion lib/features/diary/presentation/widgets/day_info_widget.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:opennutritracker/core/domain/entity/intake_entity.dart';
import 'package:opennutritracker/core/domain/entity/intake_type_entity.dart';
import 'package:opennutritracker/core/domain/entity/tracked_day_entity.dart';
import 'package:opennutritracker/core/domain/entity/user_activity_entity.dart';
import 'package:opennutritracker/core/presentation/widgets/activity_vertial_list.dart';
Expand Down Expand Up @@ -246,7 +247,16 @@ class DayInfoWidget extends StatelessWidget {
}

void showCopyDialog(BuildContext context, IntakeEntity intakeEntity) async {
const copyDialog = CopyDialog();
final defaultMealType = switch (intakeEntity.type) {
IntakeTypeEntity.breakfast => AddMealType.breakfastType,
IntakeTypeEntity.lunch => AddMealType.lunchType,
IntakeTypeEntity.dinner => AddMealType.dinnerType,
IntakeTypeEntity.snack => AddMealType.snackType,
};

final copyDialog = CopyDialog(
initialValue: defaultMealType,
);
final selectedMealType = await showDialog<AddMealType>(
context: context,
builder: (context) => copyDialog,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class _IntakeVerticalListState extends State<IntakeVerticalList> {
) async {
switch (selection) {
case VerticalListPopupMenuSelections.onCopy:
const copyDialog = CopyDialog();
final copyDialog =
CopyDialog(initialValue: widget.addMealType);
final selectedMealType = await showDialog<AddMealType>(
context: context,
builder: (context) => copyDialog,
Expand Down