1
- import 'package:flutter/material.dart' ;
2
- import 'package:flutter_webrtc/webrtc.dart' ;
3
1
import 'dart:core' ;
4
2
import 'dart:async' ;
3
+ import 'dart:io' ;
4
+ import 'package:flutter/material.dart' ;
5
+ import 'package:flutter_webrtc/webrtc.dart' ;
6
+
7
+
5
8
/*
6
9
* getDisplayMedia sample
7
10
*/
8
11
class GetDisplayMediaSample extends StatefulWidget {
9
12
static String tag = 'get_display_media_sample' ;
10
13
11
14
@override
12
- _GetDisplayMediaSampleState createState () => new _GetDisplayMediaSampleState ();
15
+ _GetDisplayMediaSampleState createState () =>
16
+ new _GetDisplayMediaSampleState ();
13
17
}
14
18
15
19
class _GetDisplayMediaSampleState extends State <GetDisplayMediaSample > {
@@ -54,8 +58,10 @@ class _GetDisplayMediaSampleState extends State<GetDisplayMediaSample> {
54
58
55
59
try {
56
60
var stream = await navigator.getDisplayMedia (mediaConstraints);
57
- _localStream = stream;
58
- _localRenderer.srcObject = _localStream;
61
+ setState (() {
62
+ _localStream = stream;
63
+ _localRenderer.srcObject = _localStream;
64
+ });
59
65
} catch (e) {
60
66
print (e.toString ());
61
67
}
@@ -72,6 +78,7 @@ class _GetDisplayMediaSampleState extends State<GetDisplayMediaSample> {
72
78
try {
73
79
await _localStream.dispose ();
74
80
_localRenderer.srcObject = null ;
81
+ _localStream = null ;
75
82
} catch (e) {
76
83
print (e.toString ());
77
84
}
@@ -90,19 +97,22 @@ class _GetDisplayMediaSampleState extends State<GetDisplayMediaSample> {
90
97
body: new OrientationBuilder (
91
98
builder: (context, orientation) {
92
99
return new Center (
93
- child: new Stack (
94
- children: < Widget > [
95
- new Center (
96
- child: new Text ('counter: ' + _counter.toString ()),
97
- ),
98
- new Container (
99
- margin: new EdgeInsets .fromLTRB (0.0 , 0.0 , 0.0 , 0.0 ),
100
- width: MediaQuery .of (context).size.width,
101
- height: MediaQuery .of (context).size.height,
102
- child: RTCVideoView (_localRenderer),
103
- decoration: new BoxDecoration (color: Colors .black54),
104
- )
105
- ]),
100
+ child: new Stack (children: < Widget > [
101
+ new Center (
102
+ child: new Text ('counter: ' + _counter.toString ()),
103
+ ),
104
+ new Container (
105
+ margin: new EdgeInsets .fromLTRB (0.0 , 0.0 , 0.0 , 0.0 ),
106
+ width: MediaQuery .of (context).size.width,
107
+ height: MediaQuery .of (context).size.height,
108
+ child: Platform .isIOS
109
+ ? (_localStream == null
110
+ ? Container ()
111
+ : RTCPlatformVideoView (_localStream))
112
+ : RTCVideoView (_localRenderer),
113
+ decoration: new BoxDecoration (color: Colors .black54),
114
+ )
115
+ ]),
106
116
);
107
117
},
108
118
),
0 commit comments