mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Can update a conversation from the list of conversations
This commit is contained in:
parent
db02a41b75
commit
8d1de2aac8
@ -5,6 +5,7 @@ import 'package:comunic/lists/conversations_list.dart';
|
||||
import 'package:comunic/models/conversation.dart';
|
||||
import 'package:comunic/ui/routes/conversation_route.dart';
|
||||
import 'package:comunic/ui/routes/create_conversation_route.dart';
|
||||
import 'package:comunic/ui/routes/update_conversation_route.dart';
|
||||
import 'package:comunic/ui/tiles/conversation_tile.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
@ -106,7 +107,18 @@ class _ConversationScreenState extends State<ConversationsListScreen> {
|
||||
.push(MaterialPageRoute(builder: (c) => CreateConversationRoute()));
|
||||
}
|
||||
|
||||
/// Handles conversation deletion request
|
||||
/// Handle conversations updated requests
|
||||
void _updateConversation(Conversation conversation) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (c) => UpdateConversationRoute(
|
||||
conversationID: conversation.id,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Handle conversation deletion request
|
||||
Future<void> _requestDeleteConversation(Conversation conversation) async {
|
||||
final result = await showDialog<bool>(
|
||||
context: context,
|
||||
@ -166,6 +178,7 @@ class _ConversationScreenState extends State<ConversationsListScreen> {
|
||||
onOpen: (c) {
|
||||
_openConversation(context, c.id);
|
||||
},
|
||||
onRequestUpdate: _updateConversation,
|
||||
onRequestDelete: _requestDeleteConversation,
|
||||
);
|
||||
},
|
||||
|
@ -11,24 +11,28 @@ import 'package:flutter/material.dart';
|
||||
|
||||
typedef OpenConversationCallback = void Function(Conversation);
|
||||
typedef RequestDeleteConversationCallback = void Function(Conversation);
|
||||
typedef RequestUpdateConversationCallback = void Function(Conversation);
|
||||
|
||||
enum _PopupMenuChoices { DELETE }
|
||||
enum _PopupMenuChoices { UPDATE, DELETE }
|
||||
|
||||
class ConversationTile extends StatelessWidget {
|
||||
final Conversation conversation;
|
||||
final UsersList usersList;
|
||||
final OpenConversationCallback onOpen;
|
||||
final RequestUpdateConversationCallback onRequestUpdate;
|
||||
final RequestDeleteConversationCallback onRequestDelete;
|
||||
|
||||
const ConversationTile(
|
||||
{Key key,
|
||||
const ConversationTile({
|
||||
Key key,
|
||||
@required this.conversation,
|
||||
@required this.usersList,
|
||||
@required this.onOpen,
|
||||
@required this.onRequestDelete})
|
||||
: assert(conversation != null),
|
||||
@required this.onRequestUpdate,
|
||||
@required this.onRequestDelete,
|
||||
}) : assert(conversation != null),
|
||||
assert(usersList != null),
|
||||
assert(onOpen != null),
|
||||
assert(onRequestUpdate != null),
|
||||
assert(onRequestDelete != null),
|
||||
super(key: key);
|
||||
|
||||
@ -90,6 +94,10 @@ class ConversationTile extends StatelessWidget {
|
||||
// Trailing information
|
||||
trailing: PopupMenuButton<_PopupMenuChoices>(
|
||||
itemBuilder: (b) => <PopupMenuEntry<_PopupMenuChoices>>[
|
||||
PopupMenuItem(
|
||||
child: Text(tr("Update")),
|
||||
value: _PopupMenuChoices.UPDATE,
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text(tr("Delete")),
|
||||
value: _PopupMenuChoices.DELETE,
|
||||
@ -103,6 +111,10 @@ class ConversationTile extends StatelessWidget {
|
||||
/// Method called each time an option of the menu is selected
|
||||
void _conversationMenuCallback(_PopupMenuChoices c) {
|
||||
switch (c) {
|
||||
case _PopupMenuChoices.UPDATE:
|
||||
onRequestUpdate(conversation);
|
||||
break;
|
||||
|
||||
case _PopupMenuChoices.DELETE:
|
||||
onRequestDelete(conversation);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user