member_list.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import 'package:flutter/material.dart';
  2. import 'package:tencent_trtc_cloud/trtc_cloud.dart';
  3. import 'package:provider/provider.dart';
  4. import 'package:ustest/models/meeting.dart';
  5. import 'package:ustest/tool.dart';
  6. /// Member list page
  7. class MemberListPage extends StatefulWidget {
  8. @override
  9. State<StatefulWidget> createState() => MemberListPageState();
  10. }
  11. class MemberListPageState extends State<MemberListPage> {
  12. late TRTCCloud trtcCloud;
  13. var meetModel;
  14. var userInfo;
  15. List micList = [];
  16. var micMap = {};
  17. @override
  18. initState() {
  19. super.initState();
  20. initRoom();
  21. meetModel = context.read<MeetingModel>();
  22. userInfo = meetModel.getUserInfo();
  23. micList = meetModel.getList();
  24. }
  25. initRoom() async {
  26. trtcCloud = (await TRTCCloud.sharedInstance())!;
  27. }
  28. @override
  29. dispose() {
  30. super.dispose();
  31. micList = [];
  32. micMap = {};
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return Scaffold(
  37. appBar: AppBar(
  38. title: const Text('Member List'),
  39. centerTitle: true,
  40. elevation: 0,
  41. backgroundColor: Color.fromRGBO(14, 25, 44, 1),
  42. ),
  43. body: Container(
  44. color: Color.fromRGBO(14, 25, 44, 1),
  45. padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 10.0),
  46. child: Stack(
  47. children: <Widget>[
  48. Container(
  49. padding: const EdgeInsets.symmetric(horizontal: 10.0),
  50. child: Consumer<MeetingModel>(
  51. builder: (context, meet, child) {
  52. List newList = [];
  53. meet.userList.forEach((item) {
  54. if (item['type'] == 'video') {
  55. newList.add(item);
  56. }
  57. });
  58. micList = newList;
  59. return ListView(
  60. children: newList
  61. .map<Widget>((item) => Container(
  62. key: ValueKey(item['userId']),
  63. height: 50,
  64. child: Row(
  65. children: [
  66. Expanded(
  67. flex: 1,
  68. child: Text(item['userId'],
  69. style: TextStyle(
  70. color: Colors.white, fontSize: 16)),
  71. ),
  72. Expanded(
  73. flex: 1,
  74. child: Offstage(
  75. offstage:
  76. item['userId'] == userInfo['userId'],
  77. child: IconButton(
  78. icon: Icon(
  79. micMap[item['userId']] == null
  80. ? Icons.mic
  81. : Icons.mic_off,
  82. color: Colors.white,
  83. size: 36.0,
  84. ),
  85. onPressed: () {
  86. if (micMap[item['userId']] ==
  87. null) {
  88. micMap[item['userId']] = true;
  89. trtcCloud.muteRemoteAudio(
  90. item['userId'], true);
  91. } else {
  92. micMap.remove(item['userId']);
  93. trtcCloud.muteRemoteAudio(
  94. item['userId'], false);
  95. }
  96. this.setState(() {});
  97. }),
  98. ),
  99. ),
  100. ],
  101. ),
  102. ))
  103. .toList(),
  104. );
  105. },
  106. ),
  107. ),
  108. new Align(
  109. child: new Container(
  110. // grey box
  111. child: new Row(
  112. mainAxisAlignment: MainAxisAlignment.spaceAround,
  113. children: <Widget>[
  114. ElevatedButton(
  115. //color: Color.fromRGBO(245, 108, 108, 1),
  116. onPressed: () {
  117. trtcCloud.muteAllRemoteAudio(true);
  118. MeetingTool.toast('Total silence', context);
  119. for (var i = 0; i < micList.length; i++) {
  120. micMap[micList[i]['userId']] = true;
  121. }
  122. this.setState(() {});
  123. },
  124. child: Text('Total silence',
  125. style: TextStyle(color: Colors.white)),
  126. ),
  127. ElevatedButton(
  128. //color: Color.fromRGBO(64, 158, 255, 1),
  129. onPressed: () {
  130. trtcCloud.muteAllRemoteAudio(false);
  131. MeetingTool.toast('Lift all bans', context);
  132. this.setState(() {
  133. micMap = {};
  134. });
  135. },
  136. child: Text('Lift all bans',
  137. style: TextStyle(color: Colors.white)),
  138. ),
  139. ],
  140. ),
  141. height: 50.0,
  142. ),
  143. alignment: Alignment.bottomCenter),
  144. ],
  145. ),
  146. ),
  147. );
  148. }
  149. }