Skip to content

Commit 00b029f

Browse files
Allow adding new custom symptoms when editing existing log
1 parent 57f29d4 commit 00b029f

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

app/lib/widgets/sheets/period_details_bottom_sheet.dart

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:menstrudel/models/flows/flow_enum.dart';
66
import 'package:menstrudel/models/period_logs/pain_level_enum.dart';
77

88
import '../../services/settings_service.dart';
9+
import '../dialogs/custom_symptom_dialog.dart';
910

1011
class PeriodDetailsBottomSheet extends StatefulWidget {
1112
final PeriodDay log;
@@ -50,6 +51,7 @@ class _PeriodDetailsBottomSheetState extends State<PeriodDetailsBottomSheet> {
5051
_defaultSymptoms.addAll(defaultSymptoms);
5152
_symptoms.addAll(_defaultSymptoms);
5253
_symptoms.addAll(widget.log.symptoms ?? []);
54+
_symptoms.add("+");
5355
});
5456
}
5557

@@ -63,6 +65,32 @@ class _PeriodDetailsBottomSheetState extends State<PeriodDetailsBottomSheet> {
6365
});
6466
}
6567

68+
Future<void> _showNewCustomSymptomDialog() async {
69+
final (String name, bool isDefault)? result = await showDialog<(String, bool)>(
70+
context: context,
71+
builder: (BuildContext context) {
72+
return const CustomSymptomDialog();
73+
},
74+
);
75+
76+
if (result != null && mounted && _symptoms.contains(result.$1) == false) {
77+
var customSymptomName = result.$1;
78+
79+
if (result.$2) {
80+
_defaultSymptoms.add(customSymptomName);
81+
await _settingsService.addDefaultSymptom(customSymptomName);
82+
}
83+
84+
setState(() {
85+
_symptoms.remove("+");
86+
_symptoms.add(customSymptomName);
87+
_symptoms.add("+");
88+
89+
_selectedSymptoms.add(customSymptomName);
90+
});
91+
}
92+
}
93+
6694
@override
6795
Widget build(BuildContext context) {
6896
return Container(
@@ -276,17 +304,23 @@ class _PeriodDetailsBottomSheetState extends State<PeriodDetailsBottomSheet> {
276304
spacing: 8.0,
277305
runSpacing: 4.0,
278306
children: _symptoms.map((symptom) {
307+
var isAdd = symptom == "+";
279308
return FilterChip(
280309
label: Text(symptom),
310+
backgroundColor: isAdd ? colorScheme.onSecondary : null,
281311
selected: _selectedSymptoms.contains(symptom),
282312
onSelected: (isSelected) {
283313
setState(() {
284-
if (isSelected) {
285-
_selectedSymptoms.add(symptom);
314+
if (isAdd) {
315+
_showNewCustomSymptomDialog();
286316
} else {
287-
_selectedSymptoms.remove(symptom);
288-
if (_defaultSymptoms.contains(symptom) == false) {
289-
_symptoms.remove(symptom);
317+
if (isSelected) {
318+
_selectedSymptoms.add(symptom);
319+
} else {
320+
_selectedSymptoms.remove(symptom);
321+
if (_defaultSymptoms.contains(symptom) == false) {
322+
_symptoms.remove(symptom);
323+
}
290324
}
291325
}
292326
});

app/lib/widgets/sheets/symptom_entry_sheet.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class _SymptomEntrySheetState extends State<SymptomEntrySheet> {
8787
@override
8888
Widget build(BuildContext context) {
8989
final l10n = AppLocalizations.of(context)!;
90+
final colorScheme = Theme.of(context).colorScheme;
9091

9192
return Padding(
9293
padding: EdgeInsets.only(top: 20, left: 16, right: 16, bottom: MediaQuery.of(context).viewInsets.bottom + 32),
@@ -177,6 +178,7 @@ class _SymptomEntrySheetState extends State<SymptomEntrySheet> {
177178
var isAdd = symptom == "+";
178179
return FilterChip(
179180
label: Text(symptom),
181+
backgroundColor: isAdd ? colorScheme.onSecondary : null,
180182
selected: _selectedSymptoms.contains(symptom),
181183
onSelected: (bool selected) {
182184
setState(() {

0 commit comments

Comments
 (0)