@@ -11,7 +11,8 @@ class PeriodLogSettingsScreen extends StatefulWidget {
1111 const PeriodLogSettingsScreen ({super .key});
1212
1313 @override
14- State <PeriodLogSettingsScreen > createState () => _PeriodLogSettingsScreenState ();
14+ State <PeriodLogSettingsScreen > createState () =>
15+ _PeriodLogSettingsScreenState ();
1516}
1617
1718class _PeriodLogSettingsScreenState extends State <PeriodLogSettingsScreen > {
@@ -20,7 +21,7 @@ class _PeriodLogSettingsScreenState extends State<PeriodLogSettingsScreen> {
2021
2122 bool _isLoading = true ;
2223
23- Set <Symptom > _defaultSymptoms = {};
24+ final Set <Symptom > _defaultSymptoms = {};
2425
2526 @override
2627 void initState () {
@@ -29,50 +30,63 @@ class _PeriodLogSettingsScreenState extends State<PeriodLogSettingsScreen> {
2930 }
3031
3132 Future <void > _loadSettings () async {
33+ _isLoading = true ;
34+
3235 var defaultSymptoms = await _settingsService.getDefaultSymptoms ();
3336 defaultSymptoms.add (Symptom .addSymptom ());
37+ defaultSymptoms.add (Symptom .refreshSymptom ());
3438
3539 if (mounted) {
3640 setState (() {
41+ _defaultSymptoms.clear ();
3742 _defaultSymptoms.addAll (defaultSymptoms);
38- _isLoading = false ;
3943 });
4044 }
45+
46+ _isLoading = false ;
4147 }
4248
4349 Future <void > _showNewCustomSymptomDialog () async {
44- final (String name, bool isDefault)? result = await showDialog< (String , bool )> (
45- context: context,
46- builder: (BuildContext context) {
47- return const CustomSymptomDialog (showTemporarySymptomButton: true );
48- },
49- );
50+ final (String name, bool isDefault)? result =
51+ await showDialog< (String , bool )> (
52+ context: context,
53+ builder: (BuildContext context) {
54+ return const CustomSymptomDialog (showTemporarySymptomButton: true );
55+ },
56+ );
5057
51- if (mounted && result != null && _defaultSymptoms.any ((element) => element.customName == result.$1) == false ) {
58+ if (mounted &&
59+ result != null &&
60+ _defaultSymptoms.any ((element) => element.customName == result.$1) ==
61+ false ) {
5262 var symptom = Symptom .fromDbString (result.$1);
5363
5464 await _settingsService.addDefaultSymptom (symptom);
55-
56- setState (() {
57- _defaultSymptoms.remove (Symptom .addSymptom ());
58- _defaultSymptoms.add (symptom);
59- _defaultSymptoms.add (Symptom .addSymptom ());
60- });
65+ await _loadSettings ();
6166 }
6267 }
6368
6469 Future <void > _removeDefaultSymptom (Symptom symptom) async {
6570 final l10n = AppLocalizations .of (context)! ;
66- final symptomUsageCount = await periodsRepo.getSingleSymptomFrequency (symptom);
71+ final symptomUsageCount = await periodsRepo.getSingleSymptomFrequency (
72+ symptom,
73+ );
6774
6875 if (mounted) {
6976 return showDialog <void >(
7077 context: context,
7178 builder: (BuildContext context) {
7279 return ConfirmationDialog (
73- title: l10n.settingsScreen_deleteDefaultSymptomQuestion (symptom.getDisplayName (l10n)),
74- contentText: l10n.settingsScreen_deleteDefaultSymptomDescription (symptom.getDisplayName (l10n), symptomUsageCount),
75- confirmButtonText: symptomUsageCount > 0 ? l10n.deleteAnyways : l10n.delete,
80+ title: l10n.settingsScreen_deleteDefaultSymptomQuestion (
81+ symptom.getDisplayName (l10n),
82+ ),
83+ contentText: l10n.settingsScreen_deleteDefaultSymptomDescription (
84+ symptom.getDisplayName (l10n),
85+ symptomUsageCount,
86+ ),
87+ confirmButtonText: symptomUsageCount > 0
88+ ? l10n.deleteAnyways
89+ : l10n.delete,
7690 onConfirm: () async {
7791 setState (() {
7892 _defaultSymptoms.remove (symptom);
@@ -85,31 +99,75 @@ class _PeriodLogSettingsScreenState extends State<PeriodLogSettingsScreen> {
8599 }
86100 }
87101
102+ Future <void > _refreshSymptoms () async {
103+ final l10n = AppLocalizations .of (context)! ;
104+
105+ if (mounted) {
106+ return showDialog <void >(
107+ context: context,
108+ builder: (BuildContext context) {
109+ return ConfirmationDialog (
110+ title: l10n.settingsScreen_resetDefaultSymptoms,
111+ contentText: l10n.settingsScreen_resetDefaultSymptomsDescription,
112+ confirmButtonText: l10n.reset,
113+ onConfirm: () async {
114+ await _settingsService.resetDefaultSymptoms ();
115+ await _loadSettings ();
116+ },
117+ );
118+ },
119+ );
120+ }
121+ }
122+
88123 @override
89124 Widget build (BuildContext context) {
90125 final l10n = AppLocalizations .of (context)! ;
91126 final theme = Theme .of (context);
92127 final colorScheme = theme.colorScheme;
93128 return Scaffold (
94- appBar: AppBar (title: Text (l10n.settingsScreen_periodPredictionAndReminders)),
129+ appBar: AppBar (
130+ title: Text (l10n.settingsScreen_periodPredictionAndReminders),
131+ ),
95132 body: _isLoading
96133 ? const Center (child: CircularProgressIndicator ())
97134 : ListView (
98135 children: [
99136 ListTile (
100137 title: Text (l10n.settingsScreen_defaultSymptoms),
101- leading: Icon (Icons .bubble_chart_outlined, color: colorScheme.onSurfaceVariant, size: 20 ),
138+ leading: Icon (
139+ Icons .bubble_chart_outlined,
140+ color: colorScheme.onSurfaceVariant,
141+ size: 20 ,
142+ ),
143+ ),
144+ ListTile (
145+ subtitle: Text (l10n.settingsScreen_defaultSymptomsSubtitle),
102146 ),
103- ListTile (subtitle: Text (l10n.settingsScreen_defaultSymptomsSubtitle)),
104147 Padding (
105148 padding: EdgeInsets .symmetric (horizontal: 12 ),
106149 child: Wrap (
107150 alignment: WrapAlignment .start,
108151 spacing: 4.0 ,
109152 runSpacing: 4.0 ,
110153 children: _defaultSymptoms.map ((symptom) {
111- var isAdd = symptom.type == SymptomType .add;
112- return RawChip (label: Text (symptom.getDisplayName (l10n)), backgroundColor: isAdd ? colorScheme.onSecondary : null , tapEnabled: true , onPressed: () => {if (isAdd) _showNewCustomSymptomDialog () else _removeDefaultSymptom (symptom)});
154+ var isAdd = symptom == Symptom .addSymptom ();
155+ var isRefresh = symptom == Symptom .refreshSymptom ();
156+ return RawChip (
157+ label: Text (symptom.getDisplayName (l10n)),
158+ backgroundColor: isAdd || isRefresh
159+ ? colorScheme.onSecondary
160+ : null ,
161+ tapEnabled: true ,
162+ onPressed: () => {
163+ if (isRefresh)
164+ {_refreshSymptoms ()}
165+ else if (isAdd)
166+ {_showNewCustomSymptomDialog ()}
167+ else
168+ {_removeDefaultSymptom (symptom)},
169+ },
170+ );
113171 }).toList (),
114172 ),
115173 ),
0 commit comments