From 65e7fd9b3d7e2037c9cc8676b0646b13c4a44e83 Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Wed, 10 Jan 2024 12:04:00 +0700 Subject: [PATCH] TW-1299: Support create chat when click on pencil in chat blank --- lib/pages/chat_blank/chat_blank.dart | 63 ++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/lib/pages/chat_blank/chat_blank.dart b/lib/pages/chat_blank/chat_blank.dart index d7538e6e0..3620c84da 100644 --- a/lib/pages/chat_blank/chat_blank.dart +++ b/lib/pages/chat_blank/chat_blank.dart @@ -1,5 +1,8 @@ +import 'package:fluffychat/config/first_column_inner_routes.dart'; import 'package:fluffychat/pages/chat_blank/chat_blank_style.dart'; +import 'package:fluffychat/presentation/mixins/go_to_group_chat_mixin.dart'; import 'package:fluffychat/resource/image_paths.dart'; +import 'package:fluffychat/utils/extension/build_context_extension.dart'; import 'package:fluffychat/utils/string_extension.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; @@ -9,7 +12,9 @@ import 'package:linagora_design_flutter/linagora_design_flutter.dart'; class ChatBlank extends StatelessWidget { final bool loading; + const ChatBlank({this.loading = false, Key? key}) : super(key: key); + @override Widget build(BuildContext context) { return Scaffold( @@ -63,7 +68,7 @@ class _ChatBlankNotChat extends StatelessWidget { } } -class _ChatBlankRichText extends StatelessWidget { +class _ChatBlankRichText extends StatelessWidget with GoToGroupChatMixin { const _ChatBlankRichText({ required this.context, }); @@ -95,18 +100,58 @@ class _ChatBlankRichText extends StatelessWidget { WidgetSpan _buildIconTitle(BuildContext context) { return WidgetSpan( alignment: PlaceholderAlignment.middle, - child: IconButton( - onPressed: () { - context.go('/rooms/newprivatechat'); - }, - icon: Icon( - Icons.mode_edit_outline_outlined, - size: ChatBlankStyle.iconSize, - color: Theme.of(context).primaryColor, + child: MenuAnchor( + menuChildren: [ + MenuItemButton( + leadingIcon: const Icon(Icons.chat), + onPressed: goToNewPrivateChat, + child: Text(L10n.of(context)!.newDirectMessage), + ), + MenuItemButton( + leadingIcon: const Icon(Icons.group), + onPressed: () => goToNewGroupChat( + innerNavigatorContext(), + ), + child: Text(L10n.of(context)!.newChat), + ), + ], + style: const MenuStyle( + alignment: Alignment.topLeft, ), + builder: (context, menuController, _) { + return InkWell( + onTap: () => menuController.open(), + child: Icon( + Icons.mode_edit_outline_outlined, + size: ChatBlankStyle.iconSize, + color: Theme.of(context).primaryColor, + ), + ); + }, ), ); } + + bool get goRouteAvailableInFirstColumn => + FirstColumnInnerRoutes.instance.goRouteAvailableInFirstColumn(); + + BuildContext innerNavigatorContext() { + if (!goRouteAvailableInFirstColumn) { + return FirstColumnInnerRoutes + .innerNavigatorNotOneColumnKey.currentState!.context; + } else { + return FirstColumnInnerRoutes + .innerNavigatorOneColumnKey.currentState!.context; + } + } + + void goToNewPrivateChat() { + if (!goRouteAvailableInFirstColumn) { + innerNavigatorContext().pushInner('innernavigator/newprivatechat'); + } else { + innerNavigatorContext().push('/rooms/newprivatechat'); + } + } } class _ChatBlankLoading extends StatelessWidget {