1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-23 05:19:22 +00:00
comunicmobile/lib/ui/widgets/tablet_mode/conversations/conversations_area_widget.dart

49 lines
1.5 KiB
Dart

import 'package:comunic/ui/widgets/tablet_mode/conversations/conversation_window.dart';
import 'package:comunic/ui/widgets/tablet_mode/conversations/open_conversation_button_widget.dart';
import 'package:flutter/material.dart';
/// Conversations area widget
///
/// This widget allow floating conversations in tablet mode
///
/// @author Pierre
class ConversationsAreaWidget extends StatefulWidget {
const ConversationsAreaWidget({Key? key}) : super(key: key);
@override
ConversationsAreaWidgetState createState() => ConversationsAreaWidgetState();
}
class ConversationsAreaWidgetState extends State<ConversationsAreaWidget> {
final _openConversations = Map<int?, UniqueKey>();
@override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: _openConversations.map(_conversationWindow).values.toList()
..add(_buildOpenButton()),
);
}
/// Add a button to open new conversations
Widget _buildOpenButton() => OpenConversationButton();
/// Open a new conversation
void openConversations(int? convID) {
if (!_openConversations.containsKey(convID))
setState(() => _openConversations[convID] = UniqueKey());
}
MapEntry<int?, Widget> _conversationWindow(int? convID, UniqueKey key) =>
MapEntry(
convID,
ConversationWindow(
key: key,
convID: convID!,
onClose: () => setState(() => _openConversations.remove(convID)),
),
);
}