@@ -6,6 +6,7 @@ import 'package:menstrudel/models/flows/flow_enum.dart';
66import 'package:menstrudel/models/period_logs/pain_level_enum.dart' ;
77
88import '../../services/settings_service.dart' ;
9+ import '../dialogs/custom_symptom_dialog.dart' ;
910
1011class 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 });
0 commit comments