basic_video_configuration_widget.dart 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import 'package:agora_rtc_engine/agora_rtc_engine.dart';
  2. import 'package:flutter/material.dart';
  3. class BasicVideoConfigurationWidget extends StatefulWidget {
  4. const BasicVideoConfigurationWidget({
  5. Key? key,
  6. required this.rtcEngine,
  7. required this.setConfigButtonText,
  8. required this.title,
  9. this.width = 960,
  10. this.height = 540,
  11. this.frameRate = 15,
  12. this.bitrate = 0,
  13. this.onConfigChanged,
  14. }) : super(key: key);
  15. final RtcEngine rtcEngine;
  16. final String title;
  17. final int width;
  18. final int height;
  19. final int frameRate;
  20. final int bitrate;
  21. final Widget setConfigButtonText;
  22. final Function(int width, int height, int frameRate, int bitrate)?
  23. onConfigChanged;
  24. @override
  25. State<BasicVideoConfigurationWidget> createState() =>
  26. _BasicVideoConfigurationWidgetState();
  27. }
  28. class _BasicVideoConfigurationWidgetState
  29. extends State<BasicVideoConfigurationWidget> {
  30. late TextEditingController _heightController;
  31. late TextEditingController _widthController;
  32. late TextEditingController _frameRateController;
  33. late TextEditingController _bitrateController;
  34. @override
  35. void initState() {
  36. super.initState();
  37. _widthController = TextEditingController(text: widget.width.toString());
  38. _heightController = TextEditingController(text: widget.height.toString());
  39. _frameRateController =
  40. TextEditingController(text: widget.frameRate.toString());
  41. _bitrateController = TextEditingController(text: widget.bitrate.toString());
  42. }
  43. @override
  44. void dispose() {
  45. super.dispose();
  46. _dispose();
  47. }
  48. Future<void> _dispose() async {
  49. _widthController.dispose();
  50. _heightController.dispose();
  51. _frameRateController.dispose();
  52. _bitrateController.dispose();
  53. }
  54. @override
  55. Widget build(BuildContext context) {
  56. return Container(
  57. padding: const EdgeInsets.all(8),
  58. decoration: BoxDecoration(
  59. color: Colors.blueGrey[50],
  60. borderRadius: const BorderRadius.all(Radius.circular(4.0)),
  61. ),
  62. child: Column(
  63. mainAxisSize: MainAxisSize.min,
  64. mainAxisAlignment: MainAxisAlignment.start,
  65. crossAxisAlignment: CrossAxisAlignment.start,
  66. children: [
  67. Text(
  68. widget.title,
  69. style: const TextStyle(fontSize: 10),
  70. ),
  71. const SizedBox(
  72. height: 10,
  73. ),
  74. Row(
  75. mainAxisAlignment: MainAxisAlignment.start,
  76. mainAxisSize: MainAxisSize.max,
  77. children: [
  78. Expanded(
  79. child: Column(
  80. mainAxisAlignment: MainAxisAlignment.start,
  81. mainAxisSize: MainAxisSize.min,
  82. crossAxisAlignment: CrossAxisAlignment.start,
  83. children: [
  84. const Text('width: '),
  85. TextField(
  86. controller: _widthController,
  87. decoration: const InputDecoration(
  88. hintText: 'width',
  89. border: OutlineInputBorder(gapPadding: 0.0),
  90. isDense: true,
  91. ),
  92. ),
  93. ],
  94. ),
  95. ),
  96. const SizedBox(
  97. width: 10,
  98. ),
  99. Expanded(
  100. child: Column(
  101. mainAxisAlignment: MainAxisAlignment.start,
  102. mainAxisSize: MainAxisSize.min,
  103. crossAxisAlignment: CrossAxisAlignment.start,
  104. children: [
  105. const Text('heigth: '),
  106. TextField(
  107. controller: _heightController,
  108. decoration: const InputDecoration(
  109. hintText: 'height',
  110. border: OutlineInputBorder(),
  111. isDense: true,
  112. ),
  113. ),
  114. ],
  115. ),
  116. ),
  117. ],
  118. ),
  119. const SizedBox(
  120. height: 10,
  121. ),
  122. Row(
  123. mainAxisAlignment: MainAxisAlignment.start,
  124. mainAxisSize: MainAxisSize.max,
  125. children: [
  126. Expanded(
  127. child: Column(
  128. mainAxisAlignment: MainAxisAlignment.start,
  129. mainAxisSize: MainAxisSize.min,
  130. crossAxisAlignment: CrossAxisAlignment.start,
  131. children: [
  132. const Text('frame rate: '),
  133. TextField(
  134. controller: _frameRateController,
  135. decoration: const InputDecoration(
  136. hintText: 'frame rate',
  137. border: OutlineInputBorder(),
  138. isDense: true,
  139. ),
  140. ),
  141. ],
  142. ),
  143. ),
  144. const SizedBox(
  145. width: 10,
  146. ),
  147. Expanded(
  148. child: Column(
  149. mainAxisAlignment: MainAxisAlignment.start,
  150. mainAxisSize: MainAxisSize.min,
  151. crossAxisAlignment: CrossAxisAlignment.start,
  152. children: [
  153. const Text('bitrate: '),
  154. TextField(
  155. controller: _bitrateController,
  156. decoration: const InputDecoration(
  157. hintText: 'bitrate',
  158. border: OutlineInputBorder(),
  159. isDense: true,
  160. ),
  161. ),
  162. ],
  163. ),
  164. ),
  165. ],
  166. ),
  167. const SizedBox(
  168. width: 10,
  169. ),
  170. ElevatedButton(
  171. child: widget.setConfigButtonText,
  172. onPressed: () {
  173. widget.onConfigChanged?.call(
  174. int.parse(_widthController.text),
  175. int.parse(_heightController.text),
  176. int.parse(_frameRateController.text),
  177. int.parse(_bitrateController.text));
  178. },
  179. ),
  180. ],
  181. ),
  182. );
  183. }
  184. }