Skip to content

Commit f349e61

Browse files
committed
fix: show error when description is empty
1 parent eedbe5c commit f349e61

File tree

1 file changed

+111
-56
lines changed

1 file changed

+111
-56
lines changed

lib/app/modules/detailRoute/views/description_widget.dart

Lines changed: 111 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -86,64 +86,12 @@ class DescriptionWidget extends StatelessWidget {
8686
),
8787
),
8888
onTap: () {
89-
var controller = TextEditingController(
90-
text: value,
91-
);
9289
showDialog(
9390
context: context,
94-
builder: (context) => Utils.showAlertDialog(
95-
scrollable: true,
96-
title: Text(
97-
SentenceManager(currentLanguage: AppSettings.selectedLanguage)
98-
.sentences
99-
.editDescription,
100-
style: TextStyle(
101-
color: tColors.primaryTextColor,
102-
),
103-
),
104-
content: TextField(
105-
style: TextStyle(
106-
color: tColors.primaryTextColor,
107-
),
108-
autofocus: true,
109-
maxLines: null,
110-
controller: controller,
111-
),
112-
actions: [
113-
TextButton(
114-
onPressed: () {
115-
Get.back();
116-
},
117-
child: Text(
118-
SentenceManager(
119-
currentLanguage: AppSettings.selectedLanguage)
120-
.sentences
121-
.cancel,
122-
style: TextStyle(
123-
color: tColors.primaryTextColor,
124-
),
125-
),
126-
),
127-
TextButton(
128-
onPressed: () {
129-
try {
130-
callback(controller.text);
131-
Get.back();
132-
} on FormatException catch (e, trace) {
133-
logError(e, trace);
134-
}
135-
},
136-
child: Text(
137-
SentenceManager(
138-
currentLanguage: AppSettings.selectedLanguage)
139-
.sentences
140-
.submit,
141-
style: TextStyle(
142-
color: tColors.primaryTextColor,
143-
),
144-
),
145-
),
146-
],
91+
builder: (context) => _DescriptionEditDialog(
92+
value: value,
93+
callback: callback,
94+
tColors: tColors,
14795
),
14896
);
14997
},
@@ -295,3 +243,110 @@ class ProjectWidget extends StatelessWidget {
295243
);
296244
}
297245
}
246+
247+
class _DescriptionEditDialog extends StatefulWidget {
248+
const _DescriptionEditDialog({
249+
required this.value,
250+
required this.callback,
251+
required this.tColors,
252+
});
253+
254+
final dynamic value;
255+
final void Function(dynamic) callback;
256+
final TaskwarriorColorTheme tColors;
257+
258+
@override
259+
State<_DescriptionEditDialog> createState() => _DescriptionEditDialogState();
260+
}
261+
262+
class _DescriptionEditDialogState extends State<_DescriptionEditDialog> {
263+
late TextEditingController controller;
264+
final _formKey = GlobalKey<FormState>();
265+
String? errorText;
266+
267+
@override
268+
void initState() {
269+
super.initState();
270+
controller = TextEditingController(text: widget.value);
271+
}
272+
273+
@override
274+
void dispose() {
275+
controller.dispose();
276+
super.dispose();
277+
}
278+
279+
@override
280+
Widget build(BuildContext context) {
281+
return Utils.showAlertDialog(
282+
scrollable: true,
283+
title: Text(
284+
SentenceManager(currentLanguage: AppSettings.selectedLanguage)
285+
.sentences
286+
.editDescription,
287+
style: TextStyle(
288+
color: widget.tColors.primaryTextColor,
289+
),
290+
),
291+
content: Form(
292+
key: _formKey,
293+
child: TextFormField(
294+
style: TextStyle(
295+
color: widget.tColors.primaryTextColor,
296+
),
297+
decoration: InputDecoration(
298+
errorText: errorText,
299+
errorStyle: TextStyle(
300+
color: Colors.red,
301+
),
302+
),
303+
autofocus: true,
304+
maxLines: null,
305+
controller: controller,
306+
),
307+
),
308+
actions: [
309+
TextButton(
310+
onPressed: () {
311+
Get.back();
312+
},
313+
child: Text(
314+
SentenceManager(currentLanguage: AppSettings.selectedLanguage)
315+
.sentences
316+
.cancel,
317+
style: TextStyle(
318+
color: widget.tColors.primaryTextColor,
319+
),
320+
),
321+
),
322+
TextButton(
323+
onPressed: () {
324+
try {
325+
if (controller.text.trim().isEmpty) {
326+
setState(() {
327+
errorText = SentenceManager(
328+
currentLanguage: AppSettings.selectedLanguage)
329+
.sentences
330+
.descriprtionCannotBeEmpty;
331+
});
332+
return;
333+
}
334+
widget.callback(controller.text);
335+
Get.back();
336+
} on FormatException catch (e, trace) {
337+
logError(e, trace);
338+
}
339+
},
340+
child: Text(
341+
SentenceManager(currentLanguage: AppSettings.selectedLanguage)
342+
.sentences
343+
.submit,
344+
style: TextStyle(
345+
color: widget.tColors.primaryTextColor,
346+
),
347+
),
348+
),
349+
],
350+
);
351+
}
352+
}

0 commit comments

Comments
 (0)