YSMineLiveAdd.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  4. import 'package:flutterappfuyou/code/base/YSTools.dart';
  5. import '../live/YSLiveAnchor.dart';
  6. class YSMineLiveAdd extends StatefulWidget {
  7. const YSMineLiveAdd({Key key}) : super(key: key);
  8. @override
  9. _YSMineLiveAddState createState() => _YSMineLiveAddState();
  10. }
  11. class _YSMineLiveAddState extends State<YSMineLiveAdd> {
  12. List _titleArray = [
  13. {'title':'主题','type':1,'key':'title'},
  14. {'title':'密码','type':1,'key':'password'},
  15. {'title':'封面','type':3,'key':'cover'},
  16. {'title':'预告','type':2,'key':'expect_start','isClose':false},
  17. ];
  18. @override
  19. Widget build(BuildContext context) {
  20. return Scaffold(
  21. body: SingleChildScrollView(
  22. child: Container(
  23. width: ysWidth(context),
  24. height: ysHeight(context),
  25. decoration: BoxDecoration(
  26. image: DecorationImage(image: AssetImage('lib/images/图.png'),fit: BoxFit.fill)
  27. ),
  28. padding: EdgeInsets.only(top: ysTOP(context),left: 10,right: 10,bottom: 10),
  29. child: Column(
  30. crossAxisAlignment: CrossAxisAlignment.start,
  31. children: [
  32. Container(
  33. padding: EdgeInsets.only(top: 10,left: 10,bottom: 30),
  34. child: GestureDetector(
  35. onTap: (){
  36. Navigator.pop(context);
  37. },
  38. child: Icon(Icons.close,size: 30,color: Colors.white,),
  39. )
  40. ),
  41. ListView.separated(
  42. itemBuilder: (context,index){
  43. Map item = _titleArray[index];
  44. bool isColumn = item['title']=='预告';
  45. bool isMust = item['title']=='主题'||item['title']=='封面';
  46. bool isClose = item['isClose']??false;
  47. return Container(
  48. padding: isColumn?EdgeInsets.all(0):EdgeInsets.only(top: 15,bottom: 15),
  49. child: LayoutBuilder(
  50. builder: (context,conSize){
  51. return isColumn?Column(
  52. children: [
  53. Container(
  54. alignment: Alignment.centerLeft,
  55. decoration: BoxDecoration(
  56. border: Border(bottom: BorderSide(color: Colors.white,width: 0.1))
  57. ),
  58. child: Row(
  59. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  60. children: [
  61. Text(item['title'],style: TextStyle(fontSize: 15,color: Colors.white),),
  62. Switch(value: isClose, onChanged: (value){
  63. item['isClose'] = !item['isClose'];
  64. setState(() {});
  65. },activeColor: Colors.pinkAccent,)
  66. ],
  67. ),
  68. padding: EdgeInsets.only(left: 10,right: 10),
  69. ),
  70. if(isClose)Container(
  71. padding: EdgeInsets.only(left: 10,right: 10),
  72. alignment: Alignment.center,
  73. decoration: BoxDecoration(
  74. border: Border(bottom: BorderSide(color: Colors.white,width: 0.1))
  75. ),
  76. child: GestureDetector(
  77. onTap: (){
  78. FocusScope.of(context).unfocus();
  79. ysShowBottomAlertView(context, YSDatePicker(
  80. choose: (value){
  81. item['value'] = value;
  82. setState(() {});
  83. },
  84. withTime: true,
  85. ),isBarr: true);
  86. },
  87. behavior: HitTestBehavior.opaque,
  88. child: Container(
  89. width: conSize.maxWidth-40,
  90. child: RichText(
  91. text: TextSpan(
  92. text: '${item['value']??'请选择预约时间'} ',
  93. style: TextStyle(fontSize: 14,color: Colors.white),
  94. children: [
  95. WidgetSpan(child: Icon(Icons.calendar_today,size: 20,color: Colors.white,))
  96. ]
  97. ),
  98. ),
  99. alignment: Alignment.center,
  100. height: 50,
  101. ),
  102. ),
  103. )
  104. ],
  105. ):Row(
  106. children: [
  107. Container(
  108. width: 80,
  109. child: RichText(
  110. text: TextSpan(
  111. style: TextStyle(fontSize: 15,color: Colors.white),
  112. children: [
  113. TextSpan(
  114. text: '*',style: TextStyle(color: isMust?Color(0xFFE26085):Colors.transparent),
  115. ),
  116. TextSpan(
  117. text: item['title'],
  118. )
  119. ]
  120. ),
  121. ),
  122. ),
  123. Container(
  124. width: conSize.maxWidth-80,
  125. child: item['title']=='封面'?GestureDetector(
  126. child: Container(
  127. height: 80,
  128. width: 80,
  129. child: item['url']==null?Icon(
  130. Icons.add,size: 40,color: Colors.white,
  131. ):Image.network(
  132. item['url'],
  133. fit: BoxFit.cover,
  134. ),
  135. decoration: BoxDecoration(
  136. border: Border.all(color: Colors.white,width: 0.2)
  137. ),
  138. ),
  139. onTap: (){
  140. ysShowBottomAlertView(context, YSChooseFileView(valueSetter: (value){
  141. ysUploadFile(context,path: value.path,type: 'diary',setter: (result){
  142. item['value'] = result['path'];
  143. item['url'] = result['url'];
  144. setState(() {});
  145. });
  146. },),isBarr: true);
  147. },
  148. ):CupertinoTextField(
  149. placeholder: '请输入${item['title']}',
  150. decoration: BoxDecoration(
  151. color: Colors.transparent,
  152. ),
  153. style: TextStyle(fontSize: 15,color: Colors.white),
  154. placeholderStyle: TextStyle(fontSize: 15,color: Colors.white),
  155. onChanged: (value){
  156. if(value.isNotEmpty){
  157. item['value'] = value;
  158. }else{
  159. item.remove('value');
  160. }
  161. },
  162. ),
  163. alignment: Alignment.centerLeft,
  164. )
  165. ],
  166. );
  167. },
  168. ),
  169. );
  170. },
  171. separatorBuilder: (context,index){
  172. return Divider(height: 0.1,thickness: 0.1,color: Colors.white,);
  173. },
  174. itemCount: _titleArray.length,
  175. shrinkWrap: true,
  176. physics: NeverScrollableScrollPhysics(),
  177. padding: EdgeInsets.all(0),
  178. ),
  179. GestureDetector(
  180. onTap: () async{
  181. Map request = {};
  182. bool isSubmit = true;
  183. bool isSelect = true;
  184. _titleArray.forEach((element) {
  185. if(isSubmit==false)return;
  186. if(element['title']=='预告'){
  187. if(element['isClose']==true){
  188. isSelect = false;
  189. if(element['value']!=null){
  190. request['expect_start'] = '${element['value']}:${'${DateTime.now().second}'.padLeft(2,'0')}';
  191. DateTime time = DateTime.parse('${request['expect_start']}');
  192. if(time.isBefore(DateTime.now())){
  193. isSubmit = false;
  194. ysFlutterToast(context, '开始时间不能早于当前时间');
  195. return;
  196. }
  197. DateTime end = time.add(Duration(hours: 3));
  198. String endStr = end.year.toString()+'-'+end.month.toString().padLeft(2,'0')+'-'+end.day.toString().padLeft(2,'0')+' '+
  199. '${end.hour}'.padLeft(2,'0')+':'+'${end.minute}'.padLeft(2,'0')+':'+'${end.second}'.padLeft(2,'0');
  200. request['expect_end'] = endStr;
  201. }else{
  202. isSubmit = false;
  203. ysFlutterToast(context, '请选择预告时间');
  204. return;
  205. }
  206. }else{
  207. isSelect = true;
  208. DateTime start = DateTime.now().add(Duration(seconds: 10));
  209. String startStr = start.year.toString()+'-'+start.month.toString().padLeft(2,'0')+'-'+start.day.toString().padLeft(2,'0')+' '+
  210. '${start.hour}'.padLeft(2,'0')+':'+'${start.minute}'.padLeft(2,'0')+':'+'${start.second}'.padLeft(2,'0');
  211. request['expect_start'] = startStr;
  212. DateTime time = DateTime.parse('${request['expect_start']}');
  213. DateTime end = time.add(Duration(hours: 3));
  214. String endStr = end.year.toString()+'-'+end.month.toString().padLeft(2,'0')+'-'+end.day.toString().padLeft(2,'0')+' '+
  215. '${end.hour}'.padLeft(2,'0')+':'+'${end.minute}'.padLeft(2,'0')+':'+'${end.second}'.padLeft(2,'0');
  216. request['expect_end'] = endStr;
  217. }
  218. }else if(element['title']=='主题'){
  219. if(element['value']!=null){
  220. request[element['key']] = element['value'];
  221. }else{
  222. isSubmit = false;
  223. ysFlutterToast(context, '请输入主题');
  224. return;
  225. }
  226. }else{
  227. if(element['value']!=null)request[element['key']] = element['value'];
  228. }
  229. });
  230. if(isSubmit==false)return;
  231. Map dict = await ysRequestHttp(context, requestType.post, 'train/live2/create', request);
  232. if(dict!=null){
  233. Map data = dict['data'];
  234. Navigator.of(context).push(
  235. CupertinoPageRoute(builder: (context){
  236. return YSMineLiveAddDone(liveId: data['live_id'],title: request['title'],isSelect: isSelect,);
  237. })
  238. );
  239. }
  240. },
  241. behavior: HitTestBehavior.opaque,
  242. child: Container(
  243. margin: EdgeInsets.only(top: 100),
  244. height: 44,
  245. decoration: BoxDecoration(
  246. borderRadius: BorderRadius.all(Radius.circular(5)),
  247. color: Color(0xFFE36085)
  248. ),
  249. alignment: Alignment.center,
  250. child: Text('创建直播',style: TextStyle(color: Colors.white,fontSize: 18),),
  251. ),
  252. )
  253. ],
  254. ),
  255. ),
  256. ),
  257. );
  258. }
  259. }
  260. class YSMineLiveAddDone extends StatefulWidget {
  261. final liveId;
  262. final String title;
  263. final bool isSelect;
  264. const YSMineLiveAddDone({Key key, this.liveId, this.title = '', this.isSelect = false}) : super(key: key);
  265. @override
  266. _YSMineLiveAddDoneState createState() => _YSMineLiveAddDoneState();
  267. }
  268. class _YSMineLiveAddDoneState extends State<YSMineLiveAddDone> {
  269. bool _isSelect = false;
  270. @override
  271. void initState() {
  272. _isSelect = widget.isSelect;
  273. super.initState();
  274. }
  275. @override
  276. Widget build(BuildContext context) {
  277. return Scaffold(
  278. body: SingleChildScrollView(
  279. child: Container(
  280. width: ysWidth(context),
  281. height: ysHeight(context),
  282. decoration: BoxDecoration(
  283. image: DecorationImage(image: AssetImage('lib/images/图.png'),fit: BoxFit.fill)
  284. ),
  285. padding: EdgeInsets.only(top: ysTOP(context),left: 10,right: 10,bottom: 10),
  286. child: Column(
  287. mainAxisSize: MainAxisSize.min,
  288. crossAxisAlignment: CrossAxisAlignment.start,
  289. children: [
  290. Container(
  291. padding: EdgeInsets.only(top: 10,left: 10,bottom: 30),
  292. child: Row(
  293. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  294. children: [
  295. GestureDetector(
  296. onTap: (){
  297. Navigator.pop(context);
  298. },
  299. child: Icon(Icons.close,size: 30,color: Colors.white,),
  300. ),
  301. Text('创建完成',style: TextStyle(fontSize: 16,color: Colors.white),),
  302. Icon(Icons.close,size: 30,color: Colors.transparent,),
  303. ],
  304. )
  305. ),
  306. Container(
  307. padding: EdgeInsets.only(left: 40,right: 20,top: 300),
  308. child: Column(
  309. crossAxisAlignment: CrossAxisAlignment.start,
  310. children: [
  311. Text('${widget.title}直播间已创建成功, \n是否进入直播间?',style: TextStyle(fontSize: 18,color: Colors.white,fontWeight: FontWeight.bold),),
  312. Container(
  313. padding: EdgeInsets.only(top: 20,bottom: 20),
  314. child: Row(
  315. children: [
  316. GestureDetector(
  317. child: Icon(_isSelect?Icons.check_box:Icons.check_box_outline_blank,size: 20,color: Colors.white,),
  318. onTap: (){
  319. _isSelect = !_isSelect;
  320. setState(() {});
  321. },
  322. ),
  323. Text(' 立即推流',style: TextStyle(fontSize: 18,color: Colors.white,fontWeight: FontWeight.bold),),
  324. ],
  325. ),
  326. ),
  327. Text('注意:选择开启推流,则会立即进入直播模式',style: TextStyle(fontSize: 12,color: Colors.white),),
  328. ],
  329. )
  330. ),
  331. GestureDetector(
  332. onTap: (){
  333. Navigator.of(context).push(
  334. CupertinoPageRoute(builder: (context){
  335. return YSLiveAnchor(liveId: widget.liveId,isSelect: _isSelect,);
  336. })
  337. );
  338. },
  339. child: Container(
  340. margin: EdgeInsets.only(top: 60),
  341. height: 44,
  342. decoration: BoxDecoration(
  343. borderRadius: BorderRadius.all(Radius.circular(5)),
  344. color: Color(0xFFE36085)
  345. ),
  346. alignment: Alignment.center,
  347. child: Text('进入直播间',style: TextStyle(color: Colors.white,fontSize: 18),),
  348. ),
  349. )
  350. ],
  351. ),
  352. ),
  353. ),
  354. );
  355. }
  356. }