Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent the user to create a folder with null or an empty string #1095

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/sharezone_widgets/lib/src/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,21 @@ class OneTextFieldDialog extends StatefulWidget {
required this.title,
required this.hint,
required this.actionName,
this.isNullOrEmptyTextAllowed = false,
this.notAllowedChars,
this.text,
}) : super(key: key);

final ValueChanged<String?> 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 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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final bool isNullOrEmptyTextAllowed;
final bool isEmptyAllowed;

I think that this should be still clear but a bit more readable. WDYT?


/// The text, which will be set at the beginning
final String? text;

Expand Down Expand Up @@ -160,6 +168,14 @@ class _OneTextFieldDialogState extends State<OneTextFieldDialog> {
),
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 {
Expand Down