Skip to content

Commit

Permalink
fix: update chat menu options on every room change; remove button if …
Browse files Browse the repository at this point in the history
…no options are available
  • Loading branch information
brenodt authored and MathJud committed Mar 28, 2023
1 parent 9e74540 commit 899edac
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions qaul_ui/lib/screens/home/tabs/chat/widgets/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,14 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
@override
void didChangeDependencies() {
super.didChangeDependencies();

var l10n = AppLocalizations.of(context)!;
if (room.isGroupChatRoom) {
_overflowMenuOptions.addAll({'groupSettings': l10n.groupSettings});
}
_updateMenuOptionsBasedOnRoomType();
}

@override
void didUpdateWidget(covariant ChatScreen oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.room == room) return;
_updateMenuOptionsBasedOnRoomType();
_scheduleUpdateCurrentOpenChat();
}

Expand Down Expand Up @@ -198,20 +195,21 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
),
titleSpacing: 0,
actions: [
PopupMenuButton<String>(
onSelected: _handleClick,
iconSize: 36,
splashRadius: 20,
icon: const Icon(Icons.more_vert),
itemBuilder: (BuildContext context) {
return _overflowMenuOptions.keys.map((String key) {
return PopupMenuItem<String>(
value: key,
child: Text(_overflowMenuOptions[key]!),
);
}).toList();
},
),
if (_overflowMenuOptions.isNotEmpty)
PopupMenuButton<String>(
onSelected: _handleClick,
iconSize: 36,
splashRadius: 20,
icon: const Icon(Icons.more_vert),
itemBuilder: (BuildContext context) {
return _overflowMenuOptions.keys.map((String key) {
return PopupMenuItem<String>(
value: key,
child: Text(_overflowMenuOptions[key]!),
);
}).toList();
},
),
],
),
body: CronTaskDecorator(
Expand Down Expand Up @@ -469,6 +467,16 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
}
return isReceiving;
}

void _updateMenuOptionsBasedOnRoomType() {
var l10n = AppLocalizations.of(context)!;
if (room.isGroupChatRoom && _overflowMenuOptions.isEmpty) {
_overflowMenuOptions.addAll({'groupSettings': l10n.groupSettings});
}
if (room.isDirectChat && _overflowMenuOptions.isNotEmpty) {
_overflowMenuOptions.clear();
}
}
}

extension _MessageExtension on Message {
Expand Down

0 comments on commit 899edac

Please sign in to comment.