diff --git a/lib/ui/dialogs/screen_dialog.dart b/lib/ui/dialogs/screen_dialog.dart new file mode 100644 index 0000000..c44f13a --- /dev/null +++ b/lib/ui/dialogs/screen_dialog.dart @@ -0,0 +1,43 @@ +import 'dart:math'; + +import 'package:comunic/utils/ui_utils.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +/// Screen dialog +/// +/// @author Pierre Hubert + +/// Show a screen dialog +/// +/// This widget automatically adapt himself if we are in tablet +/// or in mobile mode +Future showScreenDialog(BuildContext context, Widget screen) async { + // TODO : add mobile support + if (!isTablet(context)) throw Exception("Unsupported mode!"); + + return await showDialog( + context: context, builder: (c) => _ScreenDialog(body: screen)); +} + +class _ScreenDialog extends StatelessWidget { + final Widget body; + + const _ScreenDialog({Key key, this.body}) : super(key: key); + + @override + Widget build(BuildContext context) { + final size = MediaQuery.of(context).size; + final width = min(500.0, size.width - 50); + final height = min(800.0, size.height - 50); + + return AlertDialog( + contentPadding: EdgeInsets.all(0.0), + content: Container( + width: width, + height: height, + child: body, + ), + ); + } +} diff --git a/lib/ui/widgets/tablet_mode/conversations/conversation_window.dart b/lib/ui/widgets/tablet_mode/conversations/conversation_window.dart index a289bf8..7269b22 100644 --- a/lib/ui/widgets/tablet_mode/conversations/conversation_window.dart +++ b/lib/ui/widgets/tablet_mode/conversations/conversation_window.dart @@ -1,7 +1,9 @@ import 'package:comunic/helpers/conversations_helper.dart'; import 'package:comunic/helpers/events_helper.dart'; import 'package:comunic/models/conversation.dart'; +import 'package:comunic/ui/dialogs/screen_dialog.dart'; import 'package:comunic/ui/screens/conversation_screen.dart'; +import 'package:comunic/ui/screens/user_page_screen.dart'; import 'package:comunic/ui/widgets/safe_state.dart'; import 'package:comunic/ui/widgets/tablet_mode/conversations/conversation_window_container.dart'; import 'package:comunic/utils/account_utils.dart'; @@ -13,6 +15,8 @@ import 'package:flutter/material.dart'; /// /// @author Pierre Hubert +enum _Actions { OPEN_MEMBERS } + class ConversationWindow extends StatefulWidget { final int convID; final Function() onClose; @@ -119,10 +123,35 @@ class _ConversationWindowState extends SafeState { onClose: widget.onClose, onToggleCollapse: _toggleVisibility, isCollapsed: _collapsed, + action: [ + PopupMenuButton<_Actions>( + itemBuilder: (c) => [ + // Show the list of members + PopupMenuItem( + child: Text(tr("Members")), + value: _Actions.OPEN_MEMBERS, + ) + ], + onSelected: _menuCallback, + ), + ], body: ConversationScreen( key: _convKey, conversationID: _convID, ), ); } + + void _menuCallback(_Actions value) { + switch (value) { + case _Actions.OPEN_MEMBERS: + _openMembersList(); + break; + } + } + + void _openMembersList() { + // dummy test + showScreenDialog(context, UserPageScreen(userID: 1)); + } } diff --git a/lib/ui/widgets/tablet_mode/conversations/conversation_window_container.dart b/lib/ui/widgets/tablet_mode/conversations/conversation_window_container.dart index 3dcf755..246feff 100644 --- a/lib/ui/widgets/tablet_mode/conversations/conversation_window_container.dart +++ b/lib/ui/widgets/tablet_mode/conversations/conversation_window_container.dart @@ -14,6 +14,7 @@ class ConversationWindowContainer extends StatelessWidget { final void Function() onToggleCollapse; final bool isCollapsed; final Widget body; + final List action; const ConversationWindowContainer({ Key key, @@ -24,6 +25,7 @@ class ConversationWindowContainer extends StatelessWidget { @required this.body, @required this.onToggleCollapse, @required this.isCollapsed, + this.action, }) : assert(title != null), assert(onClose != null), assert(body != null), @@ -42,9 +44,10 @@ class ConversationWindowContainer extends StatelessWidget { backgroundColor: appBarBgColor, leading: icon, title: GestureDetector(child: title, onTap: onToggleCollapse), - actions: [ - IconButton(icon: Icon(Icons.close), onPressed: onClose), - ], + actions: (action == null ? [] : action) + ..add( + IconButton(icon: Icon(Icons.close), onPressed: onClose), + ), ), body: Visibility( child: body,