From 74803516a318c345746c7e5b04569e3474abf97e Mon Sep 17 00:00:00 2001 From: wanchao-xu Date: Fri, 17 Nov 2023 08:58:47 +0800 Subject: [PATCH] Remove the deprecated widget 'WillPopScope'. --- .../lib/src/call_sample/call_sample.dart | 163 +++++++++--------- 1 file changed, 78 insertions(+), 85 deletions(-) diff --git a/packages/flutter_webrtc/example/flutter_webrtc_demo/lib/src/call_sample/call_sample.dart b/packages/flutter_webrtc/example/flutter_webrtc_demo/lib/src/call_sample/call_sample.dart index b73bf2c97..e780bbb52 100644 --- a/packages/flutter_webrtc/example/flutter_webrtc_demo/lib/src/call_sample/call_sample.dart +++ b/packages/flutter_webrtc/example/flutter_webrtc_demo/lib/src/call_sample/call_sample.dart @@ -41,6 +41,9 @@ class _CallSampleState extends State { @override void deactivate() { super.deactivate(); + if (_inCalling) { + _hangUp(); + } _signaling?.close(); _localRenderer.dispose(); _remoteRenderer.dispose(); @@ -275,96 +278,86 @@ class _CallSampleState extends State { ]); } - Future _onWillPop(BuildContext context) async { - if (_inCalling) { - _hangUp(); - } - return true; - } - @override Widget build(BuildContext context) { - return WillPopScope( - onWillPop: () => _onWillPop(context), - child: Scaffold( - appBar: AppBar( - title: Text( - 'P2P Call Sample${_selfId != null ? ' [Your ID ($_selfId)] ' : ''}'), - actions: [ - IconButton( - icon: const Icon(Icons.settings), - onPressed: null, - tooltip: 'setup', - ), - ], - ), - floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, - floatingActionButton: _inCalling - ? SizedBox( - width: 240.0, + return Scaffold( + appBar: AppBar( + title: Text( + 'P2P Call Sample${_selfId != null ? ' [Your ID ($_selfId)] ' : ''}'), + actions: [ + IconButton( + icon: const Icon(Icons.settings), + onPressed: null, + tooltip: 'setup', + ), + ], + ), + floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, + floatingActionButton: _inCalling + ? SizedBox( + width: 240.0, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + FloatingActionButton( + tooltip: 'Camera', + onPressed: _switchCamera, + child: const Icon(Icons.switch_camera), + ), + FloatingActionButton( + tooltip: 'Screen Sharing', + onPressed: () => selectScreenSourceDialog(context), + child: const Icon(Icons.desktop_mac), + ), + FloatingActionButton( + onPressed: _hangUp, + tooltip: 'Hangup', + backgroundColor: Colors.pink, + child: Icon(Icons.call_end), + ), + FloatingActionButton( + tooltip: 'Mute Mic', + onPressed: _muteMic, + child: const Icon(Icons.mic_off), + ) + ])) + : null, + body: _inCalling + ? OrientationBuilder(builder: (context, orientation) { + return Container( + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.height, child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - FloatingActionButton( - tooltip: 'Camera', - onPressed: _switchCamera, - child: const Icon(Icons.switch_camera), - ), - FloatingActionButton( - tooltip: 'Screen Sharing', - onPressed: () => selectScreenSourceDialog(context), - child: const Icon(Icons.desktop_mac), + children: [ + Expanded( + flex: 1, + child: Container( + alignment: Alignment.center, + padding: const EdgeInsets.all(8.0), + decoration: BoxDecoration(color: Colors.black54), + child: RTCVideoView(_localRenderer), ), - FloatingActionButton( - onPressed: _hangUp, - tooltip: 'Hangup', - backgroundColor: Colors.pink, - child: Icon(Icons.call_end), + ), + Expanded( + flex: 1, + child: Container( + alignment: Alignment.center, + padding: const EdgeInsets.all(8.0), + decoration: BoxDecoration(color: Colors.black54), + child: RTCVideoView(_remoteRenderer), ), - FloatingActionButton( - tooltip: 'Mute Mic', - onPressed: _muteMic, - child: const Icon(Icons.mic_off), - ) - ])) - : null, - body: _inCalling - ? OrientationBuilder(builder: (context, orientation) { - return Container( - width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.height, - child: Row( - children: [ - Expanded( - flex: 1, - child: Container( - alignment: Alignment.center, - padding: const EdgeInsets.all(8.0), - decoration: BoxDecoration(color: Colors.black54), - child: RTCVideoView(_localRenderer), - ), - ), - Expanded( - flex: 1, - child: Container( - alignment: Alignment.center, - padding: const EdgeInsets.all(8.0), - decoration: BoxDecoration(color: Colors.black54), - child: RTCVideoView(_remoteRenderer), - ), - ), - ], - ), - ); - }) - : ListView.builder( - shrinkWrap: true, - padding: const EdgeInsets.all(0.0), - itemCount: _peers.length, - itemBuilder: (context, i) { - return _buildRow(context, _peers[i]); - }), - ), + ), + ], + ), + ); + }) + : ListView.builder( + shrinkWrap: true, + padding: const EdgeInsets.all(0.0), + itemCount: _peers.length, + itemBuilder: (context, i) { + return _buildRow(context, _peers[i]); + }), ); } }