From f7b7c97faa8162730887b27c8080a06a7c8528da Mon Sep 17 00:00:00 2001 From: nilsreichardt Date: Mon, 25 Sep 2023 07:52:23 +0200 Subject: [PATCH 1/3] Prevent the user to create a folder with `null` or an empty string --- lib/sharezone_widgets/lib/src/form.dart | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/sharezone_widgets/lib/src/form.dart b/lib/sharezone_widgets/lib/src/form.dart index 389b6f484..2e9a6526a 100644 --- a/lib/sharezone_widgets/lib/src/form.dart +++ b/lib/sharezone_widgets/lib/src/form.dart @@ -88,6 +88,7 @@ class OneTextFieldDialog extends StatefulWidget { required this.title, required this.hint, required this.actionName, + this.isNullOrEmptyTextAllowed = false, this.notAllowedChars, this.text, }) : super(key: key); @@ -95,6 +96,13 @@ class OneTextFieldDialog extends StatefulWidget { final ValueChanged onTap; final String? title, hint, actionName, notAllowedChars; + /// Defines if the user is allowed to submit `null` or empty text. + /// + /// If [isNullOrEmptyTextAllowed] is `false` and the user submits `null` or + /// empty text, then the dialog will not be closed and the `onTap` callback + /// will not be called. Instead the user will be shown an error message. + final bool isNullOrEmptyTextAllowed; + /// The text, which will be set at the beginning final String? text; @@ -160,6 +168,14 @@ class _OneTextFieldDialogState extends State { ), child: Text(widget.actionName!), onPressed: () { + final isNullOrEmpty = name == null || name!.isEmpty; + if (!widget.isNullOrEmptyTextAllowed && isNullOrEmpty) { + setState(() { + errorText = 'Das Textfeld darf nicht leer sein!'; + }); + return; + } + if (widget.notAllowedChars == null) { widget.onTap(name); } else { From baf082a55fb6f232da7f7d069ed277c2f7e54517 Mon Sep 17 00:00:00 2001 From: nilsreichardt Date: Mon, 25 Sep 2023 10:28:35 +0200 Subject: [PATCH 2/3] Improve comment --- lib/sharezone_widgets/lib/src/form.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/sharezone_widgets/lib/src/form.dart b/lib/sharezone_widgets/lib/src/form.dart index 2e9a6526a..0541dfeb8 100644 --- a/lib/sharezone_widgets/lib/src/form.dart +++ b/lib/sharezone_widgets/lib/src/form.dart @@ -98,9 +98,9 @@ class OneTextFieldDialog extends StatefulWidget { /// Defines if the user is allowed to submit `null` or empty text. /// - /// If [isNullOrEmptyTextAllowed] is `false` and the user submits `null` or - /// empty text, then the dialog will not be closed and the `onTap` callback - /// will not be called. Instead the user will be shown an error message. + /// If [isNullOrEmptyTextAllowed] is `false` and the user submits `null` or an + /// empty text, then the dialog will not be closed and the [onTap] callback + /// will not be called. Instead an error message will be shown. final bool isNullOrEmptyTextAllowed; /// The text, which will be set at the beginning From 34b959828660c55509f1ce169f4487e95de3ab2a Mon Sep 17 00:00:00 2001 From: nilsreichardt Date: Wed, 11 Oct 2023 14:49:42 +0200 Subject: [PATCH 3/3] Change to `isEmptyAllowed` --- lib/sharezone_widgets/lib/src/form.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/sharezone_widgets/lib/src/form.dart b/lib/sharezone_widgets/lib/src/form.dart index 0541dfeb8..adb0b0ada 100644 --- a/lib/sharezone_widgets/lib/src/form.dart +++ b/lib/sharezone_widgets/lib/src/form.dart @@ -88,7 +88,7 @@ class OneTextFieldDialog extends StatefulWidget { required this.title, required this.hint, required this.actionName, - this.isNullOrEmptyTextAllowed = false, + this.isEmptyAllowed = false, this.notAllowedChars, this.text, }) : super(key: key); @@ -98,10 +98,10 @@ class OneTextFieldDialog extends StatefulWidget { /// Defines if the user is allowed to submit `null` or empty text. /// - /// If [isNullOrEmptyTextAllowed] is `false` and the user submits `null` or an + /// If [isEmptyAllowed] is `false` and the user submits `null` or an /// empty text, then the dialog will not be closed and the [onTap] callback /// will not be called. Instead an error message will be shown. - final bool isNullOrEmptyTextAllowed; + final bool isEmptyAllowed; /// The text, which will be set at the beginning final String? text; @@ -169,7 +169,7 @@ class _OneTextFieldDialogState extends State { child: Text(widget.actionName!), onPressed: () { final isNullOrEmpty = name == null || name!.isEmpty; - if (!widget.isNullOrEmptyTextAllowed && isNullOrEmpty) { + if (!widget.isEmptyAllowed && isNullOrEmpty) { setState(() { errorText = 'Das Textfeld darf nicht leer sein!'; });