YSLiveAdd.dart 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutterappfuyou/code/base/YSBase.dart';
  4. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  5. import 'package:flutterappfuyou/code/base/YSTools.dart';
  6. import 'package:flutterappfuyou/code/live/YSLiveAnchor.dart';
  7. import 'package:image_picker/image_picker.dart';
  8. class YSLiveAdd extends StatefulWidget {
  9. const YSLiveAdd({Key key}) : super(key: key);
  10. @override
  11. _YSLiveAddState createState() => _YSLiveAddState();
  12. }
  13. class _YSLiveAddState extends State<YSLiveAdd> {
  14. List _titleArray = [
  15. {'title':'主题','type':1,'key':'title'},
  16. {'title':'会议密码','type':1,'isClose':true,'key':'password'},
  17. {'title':'预计培训时间','type':2,'isClose':true,'key1':'expect_start','key2':'expect_end'},
  18. {'title':'上传封面','type':3,'key':'cover'},
  19. ];
  20. final ImagePicker _picker = ImagePicker();
  21. bool _isEnable = false;
  22. _checkEnable() {
  23. bool isEnable = true;
  24. outLoop:
  25. for(int i=0;i<_titleArray.length;i++){
  26. Map item = _titleArray[i];
  27. if(item['value']==null&&item['isClose']==null){
  28. isEnable = false;
  29. continue outLoop;
  30. }
  31. }
  32. _isEnable = isEnable;
  33. setState(() {});
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. return YSBase2(
  38. title: '创建视频直播',
  39. color: Color(0xFFF5F3F0),
  40. child: Column(
  41. children: [
  42. ListView.builder(
  43. itemBuilder: (context,index){
  44. Map item = _titleArray[index];
  45. String title = item['title'];
  46. int type = item['type'];
  47. bool isClose = item['isClose'];
  48. return Column(
  49. children: [
  50. Container(
  51. height: 40,
  52. alignment: Alignment.centerLeft,
  53. child: isClose!=null?Row(
  54. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  55. children: [
  56. Text(title,style: TextStyle(fontSize: 15,color: Color(0xFF606266)),),
  57. Switch(value: isClose, onChanged: (value){
  58. item['isClose'] = !item['isClose'];
  59. setState(() {});
  60. },activeColor: Colors.pinkAccent,)
  61. ],
  62. ):Text(title,style: TextStyle(fontSize: 15,color: Color(0xFF606266)),),
  63. padding: EdgeInsets.only(left: 10,right: 10),
  64. ),
  65. if(item['isClose']!=false)Container(
  66. color: Colors.white,
  67. padding: EdgeInsets.only(left: 10,right: 10),
  68. child: type==1?Container(
  69. height: 50,
  70. child: CupertinoTextField(
  71. placeholder: '请输入$title',
  72. style: TextStyle(fontSize: 14,color: Color(0xFF606266)),
  73. decoration: BoxDecoration(),
  74. onChanged: (value){
  75. if(value.isNotEmpty){
  76. item['value'] = value;
  77. }else{
  78. item.remove('value');
  79. }
  80. _checkEnable();
  81. },
  82. ),
  83. ):type==2?ListView.builder(
  84. itemBuilder: (context,indexSub){
  85. return GestureDetector(
  86. onTap: (){
  87. FocusScope.of(context).unfocus();
  88. ysShowBottomAlertView(context, YSDatePicker(
  89. choose: (value){
  90. if(indexSub==0){
  91. item['value1'] = value;
  92. }else{
  93. item['value2'] = value;
  94. }
  95. setState(() {});
  96. _checkEnable();
  97. },
  98. withTime: true,
  99. ),isBarr: true);
  100. },
  101. behavior: HitTestBehavior.opaque,
  102. child: Row(
  103. children: [
  104. Container(
  105. width: MediaQuery.of(context).size.width-40,
  106. child: Text(item[indexSub==0?'value1':'value2']??'请选择${indexSub==0?'开始':'结束'}时间',style: TextStyle(fontSize: 14,color: Color(0xFF606266)),),
  107. alignment: Alignment.centerLeft,
  108. height: 50,
  109. ),
  110. Icon(Icons.keyboard_arrow_down,size: 20,color: Color(0xFF606266),)
  111. ],
  112. ),
  113. );
  114. },
  115. itemCount: 2,
  116. physics: NeverScrollableScrollPhysics(),
  117. shrinkWrap: true,
  118. padding: EdgeInsets.all(0),
  119. ):type==3?Container(
  120. child: GestureDetector(
  121. child: Container(
  122. height: 80,
  123. width: 80,
  124. child: item['url']==null?Icon(
  125. Icons.add,size: 40,color: Color(0xFFD3D3D3),
  126. ):Image.network(
  127. item['url'],
  128. fit: BoxFit.cover,
  129. ),
  130. decoration: BoxDecoration(
  131. border: Border.all(color: Color(0xFFD3D3D3),width: 0.2)
  132. ),
  133. ),
  134. onTap: (){
  135. ysShowBottomAlertView(context, YSChooseFileView(valueSetter: (value){
  136. ysUploadFile(context,path: value.path,type: 'diary',setter: (result){
  137. item['value'] = result['path'];
  138. item['url'] = result['url'];
  139. setState(() {});
  140. _checkEnable();
  141. });
  142. },),isBarr: true);
  143. },
  144. ),
  145. padding: EdgeInsets.only(top: 20,bottom: 20),
  146. alignment: Alignment.centerLeft,
  147. ):Container(),
  148. )
  149. ],
  150. );
  151. },
  152. itemCount: _titleArray.length,
  153. shrinkWrap: true,
  154. physics: NeverScrollableScrollPhysics(),
  155. padding: EdgeInsets.all(0),
  156. ),
  157. GestureDetector(
  158. onTap: (){
  159. // Navigator.of(context).push(
  160. // CupertinoPageRoute(builder: (context){
  161. // return YSLiveAnchor();
  162. // })
  163. // );
  164. // return;
  165. if(_isEnable==false)return;
  166. _postLiveAddData();
  167. },
  168. child: Container(
  169. width: MediaQuery.of(context).size.width-100,
  170. margin: EdgeInsets.only(top: 15),
  171. height: 50,
  172. decoration: BoxDecoration(
  173. color: _isEnable==true?Colors.pinkAccent:Colors.grey,
  174. borderRadius: BorderRadius.all(Radius.circular(5))
  175. ),
  176. alignment: Alignment.center,
  177. child: Text('创建直播',style: TextStyle(fontSize: 15,color: Colors.white,fontWeight: FontWeight.bold),),
  178. ),
  179. )
  180. ],
  181. ),
  182. );
  183. }
  184. _postLiveAddData() async{
  185. Map request = {};
  186. _titleArray.forEach((element) {
  187. if(element['title']=='预计培训时间'){
  188. if(element['value1']!=null)request[element['key1']] = '${element['value1']}:00';
  189. if(element['value2']!=null)request[element['key2']] = '${element['value2']}:00';
  190. }else{
  191. if(element['value']!=null)request[element['key']] = element['value'];
  192. }
  193. });
  194. Map dict = await ysRequestHttp(context, requestType.post, 'train/live2/create', request);
  195. if(dict!=null){
  196. Map data = dict['data'];
  197. Navigator.pop(context);
  198. Navigator.of(context).push(
  199. CupertinoPageRoute(builder: (context){
  200. return YSLiveAnchor(liveId: data['live_id'],);
  201. })
  202. );
  203. }
  204. }
  205. }