YSVideoList.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import 'package:file_picker/file_picker.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_slidable/flutter_slidable.dart';
  5. import 'package:flutter_vr/tools/YSSqlite.dart';
  6. import 'package:flutter_vr/tools/YSTools.dart';
  7. import 'package:flutter_vr/video/YSVideoDetail.dart';
  8. import 'package:flutter_vr/video/view/YSAlertView.dart';
  9. import 'package:flutter_vr/video/view/YSVideoImage.dart';
  10. import 'YSVideoVRDetail.dart';
  11. class YSVideoList extends StatefulWidget {
  12. const YSVideoList({Key? key}) : super(key: key);
  13. @override
  14. YSVideoListState createState() => YSVideoListState();
  15. }
  16. class YSVideoListState extends State<YSVideoList> {
  17. List _dataArray = [];
  18. final YSVideoTable _ysVideoTable = YSVideoTable().init();
  19. bool _isVR = false;
  20. @override
  21. void initState() {
  22. Future.delayed(const Duration(seconds: 0)).then((value) {
  23. _getData();
  24. });
  25. super.initState();
  26. }
  27. _getData() async{
  28. _dataArray = await _ysVideoTable.rawQuery();
  29. LogUtil.d(_dataArray);
  30. setState(() {});
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. return Scaffold(
  35. backgroundColor: Colors.white,
  36. appBar: CupertinoNavigationBar(
  37. backgroundColor: appColor,
  38. middle: const Text('添加文件',style: TextStyle(fontSize: 20,color: Colors.white),),
  39. trailing: GestureDetector(
  40. onTap: (){
  41. _isVR = !_isVR;
  42. setState(() {});
  43. },
  44. child: Text(_isVR?'VR':'普通',style: const TextStyle(fontSize: 15,color: Colors.white),)
  45. ),
  46. ),
  47. body: ListView.separated(
  48. itemBuilder: (context,index){
  49. Map item = _dataArray[index];
  50. return Slidable(
  51. key: const ValueKey(0),
  52. endActionPane: ActionPane(
  53. extentRatio: 0.3,
  54. motion: GestureDetector(
  55. onTap: (){
  56. ysShowCenterAlertView(context, YSTipsAlertView(valueSetter: (value) async{
  57. if(value){
  58. _ysVideoTable.rawDelete('${item['id']}');
  59. _getData();
  60. }
  61. },tipsStr: '是否移除次视频?',));
  62. },
  63. child: Container(
  64. color: Colors.red,
  65. alignment: Alignment.center,
  66. child: const Text('移除',style: TextStyle(fontSize: 15,color: Colors.white),),
  67. ),
  68. ),
  69. children: const [],
  70. ),
  71. child: GestureDetector(
  72. onTap: (){
  73. Navigator.of(context).push(
  74. CupertinoPageRoute(builder: (context){
  75. return _isVR?YSVideoVRDetail(video: item,):YSVideoDetail(video: item,);
  76. })
  77. );
  78. },
  79. behavior: HitTestBehavior.opaque,
  80. child: Row(
  81. crossAxisAlignment: CrossAxisAlignment.start,
  82. children: [
  83. ClipRRect(
  84. borderRadius: const BorderRadius.all(Radius.circular(5)),
  85. child: Container(
  86. height: 80,
  87. width: 100,
  88. color: appColor,
  89. child: YSVideoImage(path: item['path'],),
  90. ),
  91. ),
  92. Expanded(child: Container(
  93. padding: const EdgeInsets.only(left: 10,top: 10,bottom: 5),
  94. height: 80,
  95. child: Column(
  96. crossAxisAlignment: CrossAxisAlignment.start,
  97. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  98. children: [
  99. Text(item['name'],style: const TextStyle(fontSize: 15,color: Colors.black),maxLines: 3,
  100. overflow: TextOverflow.ellipsis,),
  101. // Text(item['time'],style: const TextStyle(fontSize: 12,color: Colors.grey),)
  102. ],
  103. ),
  104. ))
  105. ],
  106. ),
  107. ),
  108. );
  109. },
  110. separatorBuilder: (context,index){
  111. return Container(height: 10,);
  112. },
  113. itemCount: _dataArray.length,
  114. padding: const EdgeInsets.only(top: 10,bottom: 10,left: 15,right: 15),
  115. ),
  116. floatingActionButton: GestureDetector(
  117. onTap: () async{
  118. FilePickerResult? result = await FilePicker.platform.pickFiles(
  119. type: FileType.custom,
  120. allowedExtensions: ['mp4', 'avi', 'wmv', 'mkv', 'mov'],//,'jpg','jpeg'
  121. );
  122. if(result!=null){
  123. List<PlatformFile> files = result.files;
  124. for (var file in files) {
  125. bool isHas = _dataArray.any((element) => element['path']==file.path);
  126. if(isHas==false){
  127. _ysVideoTable.rawInsert(name: file.name, path: file.path!, time: '0');
  128. }else{
  129. LogUtil.d('已添加');
  130. }
  131. }
  132. _getData();
  133. }
  134. },
  135. child: Icon(Icons.add_circle,size: 60,color: appColor,)
  136. ),
  137. );
  138. }
  139. }