Skip to content

Commit 6a87d71

Browse files
Example app cleanup (#394)
* Example app cleanup - mirror local video when front facing camera - run dart format - update dependencies * try a newer version of stable flutter --------- Co-authored-by: CloudWebRTC <duanweiwei1982@gmail.com>
1 parent f1f8bb8 commit 6a87d71

File tree

7 files changed

+350
-380
lines changed

7 files changed

+350
-380
lines changed

example/lib/main.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
44
import 'package:flutter_webrtc/flutter_webrtc.dart';
55
import 'package:sip_ua/sip_ua.dart';
66

7-
87
import 'src/about.dart';
98
import 'src/callscreen.dart';
109
import 'src/dialpad.dart';
@@ -57,6 +56,18 @@ class MyApp extends StatelessWidget {
5756
theme: ThemeData(
5857
primarySwatch: Colors.blue,
5958
fontFamily: 'Roboto',
59+
inputDecorationTheme: InputDecorationTheme(
60+
hintStyle: TextStyle(color: Colors.grey),
61+
contentPadding: EdgeInsets.all(10.0),
62+
border: UnderlineInputBorder(
63+
borderSide: BorderSide(color: Colors.black12)),
64+
),
65+
elevatedButtonTheme: ElevatedButtonThemeData(
66+
style: ElevatedButton.styleFrom(
67+
padding: const EdgeInsets.all(16),
68+
textStyle: TextStyle(fontSize: 18),
69+
),
70+
),
6071
),
6172
initialRoute: '/',
6273
onGenerateRoute: _onGenerateRoute,

example/lib/src/about.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ class AboutWidget extends StatelessWidget {
44
@override
55
Widget build(BuildContext context) {
66
return Scaffold(
7-
appBar: AppBar(
8-
title: Text("About"),
9-
),
10-
body: SingleChildScrollView(
11-
child: Padding(
12-
padding: const EdgeInsets.all(18.0),
13-
child: Center(
14-
child: Column(
15-
children: <Widget>[
16-
Text(
17-
'GitHub:\nhttps://github.com/cloudwebrtc/dart-sip-ua.git')
18-
],
19-
),
7+
appBar: AppBar(
8+
title: Text("About"),
9+
),
10+
body: SingleChildScrollView(
11+
child: Padding(
12+
padding: const EdgeInsets.all(18.0),
13+
child: Center(
14+
child: Column(
15+
children: <Widget>[
16+
Text('GitHub:\nhttps://github.com/cloudwebrtc/dart-sip-ua.git'),
17+
],
2018
),
2119
),
22-
));
20+
),
21+
),
22+
);
2323
}
2424
}

example/lib/src/callscreen.dart

Lines changed: 94 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import 'widgets/action_button.dart';
1010
class CallScreenWidget extends StatefulWidget {
1111
final SIPUAHelper? _helper;
1212
final Call? _call;
13+
1314
CallScreenWidget(this._helper, this._call, {Key? key}) : super(key: key);
15+
1416
@override
15-
_MyCallScreenWidget createState() => _MyCallScreenWidget();
17+
State<CallScreenWidget> createState() => _MyCallScreenWidget();
1618
}
1719

1820
class _MyCallScreenWidget extends State<CallScreenWidget>
@@ -27,13 +29,17 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
2729

2830
bool _showNumPad = false;
2931
String _timeLabel = '00:00';
30-
late Timer _timer;
3132
bool _audioMuted = false;
3233
bool _videoMuted = false;
3334
bool _speakerOn = false;
3435
bool _hold = false;
36+
bool _mirror = true;
3537
String? _holdOriginator;
3638
CallStateEnum _state = CallStateEnum.NONE;
39+
40+
late String _transferTarget;
41+
late Timer _timer;
42+
3743
SIPUAHelper? get helper => widget._helper;
3844

3945
bool get voiceOnly =>
@@ -237,6 +243,9 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
237243
void _switchCamera() {
238244
if (_localStream != null) {
239245
Helper.switchCamera(_localStream!.getVideoTracks()[0]);
246+
setState(() {
247+
_mirror = !_mirror;
248+
});
240249
}
241250
}
242251

@@ -264,7 +273,6 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
264273
}
265274
}
266275

267-
late String _transferTarget;
268276
void _handleTransfer() {
269277
showDialog<void>(
270278
context: context,
@@ -324,7 +332,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
324332
}
325333

326334
List<Widget> _buildNumPad() {
327-
var labels = [
335+
final labels = [
328336
[
329337
{'1': ''},
330338
{'2': 'abc'},
@@ -364,22 +372,22 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
364372
}
365373

366374
Widget _buildActionButtons() {
367-
var hangupBtn = ActionButton(
375+
final hangupBtn = ActionButton(
368376
title: "hangup",
369377
onPressed: () => _handleHangup(),
370378
icon: Icons.call_end,
371379
fillColor: Colors.red,
372380
);
373381

374-
var hangupBtnInactive = ActionButton(
382+
final hangupBtnInactive = ActionButton(
375383
title: "hangup",
376384
onPressed: () {},
377385
icon: Icons.call_end,
378386
fillColor: Colors.grey,
379387
);
380388

381-
var basicActions = <Widget>[];
382-
var advanceActions = <Widget>[];
389+
final basicActions = <Widget>[];
390+
final advanceActions = <Widget>[];
383391

384392
switch (_state) {
385393
case CallStateEnum.NONE:
@@ -472,91 +480,117 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
472480
break;
473481
}
474482

475-
var actionWidgets = <Widget>[];
483+
final actionWidgets = <Widget>[];
476484

477485
if (_showNumPad) {
478486
actionWidgets.addAll(_buildNumPad());
479487
} else {
480488
if (advanceActions.isNotEmpty) {
481-
actionWidgets.add(Padding(
489+
actionWidgets.add(
490+
Padding(
482491
padding: const EdgeInsets.all(3),
483492
child: Row(
484493
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
485-
children: advanceActions)));
494+
children: advanceActions),
495+
),
496+
);
486497
}
487498
}
488499

489-
actionWidgets.add(Padding(
500+
actionWidgets.add(
501+
Padding(
490502
padding: const EdgeInsets.all(3),
491503
child: Row(
492504
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
493-
children: basicActions)));
505+
children: basicActions),
506+
),
507+
);
494508

495509
return Column(
496-
crossAxisAlignment: CrossAxisAlignment.end,
497-
mainAxisAlignment: MainAxisAlignment.end,
498-
children: actionWidgets);
510+
crossAxisAlignment: CrossAxisAlignment.end,
511+
mainAxisAlignment: MainAxisAlignment.end,
512+
children: actionWidgets,
513+
);
499514
}
500515

501516
Widget _buildContent() {
502-
var stackWidgets = <Widget>[];
517+
final stackWidgets = <Widget>[];
503518

504519
if (!voiceOnly && _remoteStream != null) {
505-
stackWidgets.add(Center(
506-
child: RTCVideoView(_remoteRenderer!),
507-
));
520+
stackWidgets.add(
521+
Center(
522+
child: RTCVideoView(
523+
_remoteRenderer!,
524+
objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover,
525+
),
526+
),
527+
);
508528
}
509529

510530
if (!voiceOnly && _localStream != null) {
511-
stackWidgets.add(Container(
512-
child: AnimatedContainer(
513-
child: RTCVideoView(_localRenderer!),
531+
stackWidgets.add(
532+
AnimatedContainer(
533+
child: RTCVideoView(
534+
_localRenderer!,
535+
mirror: _mirror,
536+
objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover,
537+
),
514538
height: _localVideoHeight,
515539
width: _localVideoWidth,
516540
alignment: Alignment.topRight,
517541
duration: Duration(milliseconds: 300),
518542
margin: _localVideoMargin,
519543
),
520-
alignment: Alignment.topRight,
521-
));
544+
);
522545
}
523546

524-
stackWidgets.addAll([
525-
Positioned(
526-
top: voiceOnly ? 48 : 6,
527-
left: 0,
528-
right: 0,
529-
child: Center(
547+
stackWidgets.addAll(
548+
[
549+
Positioned(
550+
top: voiceOnly ? 48 : 6,
551+
left: 0,
552+
right: 0,
553+
child: Center(
530554
child: Column(
531-
crossAxisAlignment: CrossAxisAlignment.center,
532-
mainAxisAlignment: MainAxisAlignment.center,
533-
children: <Widget>[
534-
Center(
535-
child: Padding(
555+
crossAxisAlignment: CrossAxisAlignment.center,
556+
mainAxisAlignment: MainAxisAlignment.center,
557+
children: <Widget>[
558+
Center(
559+
child: Padding(
536560
padding: const EdgeInsets.all(6),
537561
child: Text(
538562
(voiceOnly ? 'VOICE CALL' : 'VIDEO CALL') +
539563
(_hold
540564
? ' PAUSED BY ${_holdOriginator!.toUpperCase()}'
541565
: ''),
542566
style: TextStyle(fontSize: 24, color: Colors.black54),
543-
))),
544-
Center(
545-
child: Padding(
567+
),
568+
),
569+
),
570+
Center(
571+
child: Padding(
546572
padding: const EdgeInsets.all(6),
547573
child: Text(
548574
'$remoteIdentity',
549575
style: TextStyle(fontSize: 18, color: Colors.black54),
550-
))),
551-
Center(
552-
child: Padding(
576+
),
577+
),
578+
),
579+
Center(
580+
child: Padding(
553581
padding: const EdgeInsets.all(6),
554-
child: Text(_timeLabel,
555-
style: TextStyle(fontSize: 14, color: Colors.black54))))
556-
],
557-
)),
558-
),
559-
]);
582+
child: Text(
583+
_timeLabel,
584+
style: TextStyle(fontSize: 14, color: Colors.black54),
585+
),
586+
),
587+
)
588+
],
589+
),
590+
),
591+
),
592+
],
593+
);
560594

561595
return Stack(
562596
children: stackWidgets,
@@ -566,16 +600,18 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
566600
@override
567601
Widget build(BuildContext context) {
568602
return Scaffold(
569-
appBar: AppBar(
570-
automaticallyImplyLeading: false,
571-
title: Text('[$direction] ${EnumHelper.getName(_state)}')),
572-
body: Container(
573-
child: _buildContent(),
574-
),
575-
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
576-
floatingActionButton: Padding(
577-
padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 24.0),
578-
child: Container(width: 320, child: _buildActionButtons())));
603+
appBar: AppBar(
604+
automaticallyImplyLeading: false,
605+
title: Text('[$direction] ${EnumHelper.getName(_state)}'),
606+
),
607+
body: _buildContent(),
608+
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
609+
floatingActionButton: Container(
610+
width: 320,
611+
padding: EdgeInsets.only(bottom: 24.0),
612+
child: _buildActionButtons(),
613+
),
614+
);
579615
}
580616

581617
@override

0 commit comments

Comments
 (0)