diff --git a/lib/pages/new_group/new_group_chat_info.dart b/lib/pages/new_group/new_group_chat_info.dart index 375ef50ed..50b6779ff 100644 --- a/lib/pages/new_group/new_group_chat_info.dart +++ b/lib/pages/new_group/new_group_chat_info.dart @@ -5,6 +5,9 @@ import 'package:fluffychat/app_state/failure.dart'; import 'package:fluffychat/app_state/success.dart'; import 'package:fluffychat/domain/app_state/room/create_new_group_chat_state.dart'; import 'package:fluffychat/domain/app_state/room/upload_content_state.dart'; +import 'package:fluffychat/domain/app_state/validator/verify_name_view_state.dart'; +import 'package:fluffychat/domain/model/verification/name_with_space_only_validator.dart'; +import 'package:fluffychat/domain/usecase/verify_name_interactor.dart'; import 'package:fluffychat/pages/new_group/new_group_chat_info_view.dart'; import 'package:fluffychat/pages/new_group/new_group_info_controller.dart'; import 'package:fluffychat/presentation/mixins/common_media_picker_mixin.dart'; @@ -55,6 +58,7 @@ class NewGroupChatInfoController extends State final groupNameTextEditingController = TextEditingController(); final avatarAssetEntityNotifier = ValueNotifier(null); final avatarFilePickerNotifier = ValueNotifier(null); + VerifyNameInteractor verifyNameInteractor = VerifyNameInteractor(); final groupNameFocusNode = FocusNode(); StreamSubscription? createNewGroupChatInteractorStreamSubscription; @@ -309,6 +313,20 @@ class NewGroupChatInfoController extends State ); } + String? getErrorMessage(String content) { + verifyNameInteractor.execute(content, [NameWithSpaceOnlyValidator()]).fold( + (failure) { + if (failure is VerifyNameFailure) { + return failure.exception.getMessage(context); + } else { + return null; + } + }, + (success) => null, + ); + return null; + } + @override void initState() { listenGroupNameChanged(); diff --git a/lib/pages/new_group/new_group_chat_info_view.dart b/lib/pages/new_group/new_group_chat_info_view.dart index 0965f6243..1994761dd 100644 --- a/lib/pages/new_group/new_group_chat_info_view.dart +++ b/lib/pages/new_group/new_group_chat_info_view.dart @@ -210,6 +210,9 @@ class NewGroupChatInfoView extends StatelessWidget { borderSide: BorderSide(color: Theme.of(context).colorScheme.shadow), ), + errorText: newGroupInfoController.getErrorMessage( + newGroupInfoController.groupNameTextEditingController.text, + ), labelText: L10n.of(context)!.widgetName, labelStyle: Theme.of(context).textTheme.bodySmall?.copyWith( color: Theme.of(context).colorScheme.onSurface,