From 6a9e0e36c1a7ca44608bba701b04dfcd30570f8e Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 21 Apr 2020 18:08:01 +0200 Subject: [PATCH] Create Footer button widget --- lib/ui/screens/call_screen.dart | 54 +++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/lib/ui/screens/call_screen.dart b/lib/ui/screens/call_screen.dart index f285d8f..90fbd6d 100644 --- a/lib/ui/screens/call_screen.dart +++ b/lib/ui/screens/call_screen.dart @@ -436,34 +436,50 @@ class _CallScreenState extends SafeState { mainAxisAlignment: MainAxisAlignment.center, children: [ // Toggle audio button - Expanded( - child: IconButton( - icon: Icon(isStreamingAudio && !isAudioMuted - ? Icons.mic - : Icons.mic_off), - onPressed: () => _toggleStreaming(false), - ), + _FooterButton( + onPressed: () => _toggleStreaming(false), + icon: Icon( + isStreamingAudio && !isAudioMuted ? Icons.mic : Icons.mic_off), ), // Hang up call - Expanded( - child: IconButton( - icon: Icon(Icons.phone, color: Colors.red), - onPressed: () => _leaveCall(), - ), + _FooterButton( + icon: Icon(Icons.phone, color: Colors.red), + onPressed: () => _leaveCall(), ), // Toggle video button - Expanded( - child: IconButton( - icon: Icon(isStreamingVideo && !isVideoMuted - ? Icons.videocam - : Icons.videocam_off), - onPressed: () => _toggleStreaming(true), - ), + _FooterButton( + icon: Icon(isStreamingVideo && !isVideoMuted + ? Icons.videocam + : Icons.videocam_off), + onPressed: () => _toggleStreaming(true), ), ], ), ); } } + +class _FooterButton extends StatelessWidget { + final Function() onPressed; + final Widget icon; + + const _FooterButton({ + Key key, + @required this.onPressed, + @required this.icon, + }) : assert(onPressed != null), + assert(icon != null), + super(key: key); + + @override + Widget build(BuildContext context) { + return Expanded( + child: IconButton( + icon: icon, + onPressed: () => onPressed(), + ), + ); + } +}