From 25222e91569364a6e5e298c0cee53de672444373 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 9 May 2020 20:11:54 +0200 Subject: [PATCH] Manage to add call button in a visible way --- lib/ui/widgets/custom_app_bar_size.dart | 22 ++++++++ .../conversations/conversation_window.dart | 54 +++++++++---------- .../conversation_window_container.dart | 22 ++++---- 3 files changed, 60 insertions(+), 38 deletions(-) create mode 100644 lib/ui/widgets/custom_app_bar_size.dart diff --git a/lib/ui/widgets/custom_app_bar_size.dart b/lib/ui/widgets/custom_app_bar_size.dart new file mode 100644 index 0000000..49b3105 --- /dev/null +++ b/lib/ui/widgets/custom_app_bar_size.dart @@ -0,0 +1,22 @@ +import 'package:flutter/material.dart'; + +/// Customize the size of the AppBar +/// +/// @author Pierre Hubert + +/// Reduce the size of the appbar +class AppBarWrapper extends StatelessWidget implements PreferredSizeWidget { + final Widget appBar; + final double height; + + const AppBarWrapper({@required this.height, @required this.appBar}) + : assert(height != null), + assert(appBar != null), + super(); + + @override + Widget build(BuildContext context) => appBar; + + @override + Size get preferredSize => Size.fromHeight(height); +} diff --git a/lib/ui/widgets/tablet_mode/conversations/conversation_window.dart b/lib/ui/widgets/tablet_mode/conversations/conversation_window.dart index d1efbf1..ce54191 100644 --- a/lib/ui/widgets/tablet_mode/conversations/conversation_window.dart +++ b/lib/ui/widgets/tablet_mode/conversations/conversation_window.dart @@ -17,7 +17,7 @@ import 'package:flutter/material.dart'; /// /// @author Pierre Hubert -enum _Actions { START_CALL, OPEN_MEMBERS, OPEN_SETTINGS } +enum _Actions { OPEN_MEMBERS, OPEN_SETTINGS } class ConversationWindow extends StatefulWidget { final int convID; @@ -119,37 +119,35 @@ class _ConversationWindowState extends SafeState { ); return ConversationWindowContainer( - icon: Icon(_hasNewMessages ? Icons.trip_origin : Icons.comment), + icon: _hasNewMessages ? Icon(Icons.trip_origin) : null, appBarBgColor: _hasNewMessages ? Colors.green : null, title: Text(_convTitle), onClose: widget.onClose, onToggleCollapse: _toggleVisibility, isCollapsed: _collapsed, - action: [ - PopupMenuButton<_Actions>( - itemBuilder: (c) => [ - // Start a new call - PopupMenuItem( - child: Text(tr("Start call")), - value: _Actions.START_CALL, - enabled: _conversation.callCapabilities != CallCapabilities.NONE, - ), + action: (_conversation.callCapabilities != CallCapabilities.NONE + ? [IconButton(icon: Icon(Icons.call), onPressed: _startCall)] + : []) + ..addAll([ + PopupMenuButton<_Actions>( + itemBuilder: (c) => [ + // Start a new call - // Show the list of members - PopupMenuItem( - child: Text(tr("Members")), - value: _Actions.OPEN_MEMBERS, - ), + // Show the list of members + PopupMenuItem( + child: Text(tr("Members")), + value: _Actions.OPEN_MEMBERS, + ), - // Show conversation settings - PopupMenuItem( - child: Text(tr("Settings")), - value: _Actions.OPEN_SETTINGS, - ) - ], - onSelected: _menuCallback, - ), - ], + // Show conversation settings + PopupMenuItem( + child: Text(tr("Settings")), + value: _Actions.OPEN_SETTINGS, + ) + ], + onSelected: _menuCallback, + ), + ]), body: ConversationScreen( key: _convKey, conversationID: _convID, @@ -159,10 +157,6 @@ class _ConversationWindowState extends SafeState { void _menuCallback(_Actions value) { switch (value) { - case _Actions.START_CALL: - MainController.of(context).startCall(_convID); - break; - case _Actions.OPEN_MEMBERS: _openMembersList(); break; @@ -182,4 +176,6 @@ class _ConversationWindowState extends SafeState { context, UpdateConversationRoute(conversationID: _convID)); _refresh(); } + + void _startCall() => MainController.of(context).startCall(_convID); } 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 246feff..6817cb0 100644 --- a/lib/ui/widgets/tablet_mode/conversations/conversation_window_container.dart +++ b/lib/ui/widgets/tablet_mode/conversations/conversation_window_container.dart @@ -1,3 +1,4 @@ +import 'package:comunic/ui/widgets/custom_app_bar_size.dart'; import 'package:flutter/material.dart'; /// Conversation window @@ -40,15 +41,18 @@ class ConversationWindowContainer extends StatelessWidget { width: 300, height: !isCollapsed ? 400 : 40, child: Scaffold( - appBar: AppBar( - backgroundColor: appBarBgColor, - leading: icon, - title: GestureDetector(child: title, onTap: onToggleCollapse), - actions: (action == null ? [] : action) - ..add( - IconButton(icon: Icon(Icons.close), onPressed: onClose), - ), - ), + appBar: AppBarWrapper( + height: 40, + appBar: AppBar( + textTheme: TextTheme(title: TextStyle(fontSize: 15)), + backgroundColor: appBarBgColor, + leading: icon, + title: GestureDetector(child: title, onTap: onToggleCollapse), + actions: (action == null ? [] : action) + ..add( + IconButton(icon: Icon(Icons.close), onPressed: onClose), + ), + )), body: Visibility( child: body, visible: !isCollapsed,