import 'package:file_picker/file_picker.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:flutter_vr/tools/YSSqlite.dart'; import 'package:flutter_vr/tools/YSTools.dart'; import 'package:flutter_vr/video/YSVideoDetail.dart'; import 'package:flutter_vr/video/view/YSAlertView.dart'; import 'package:flutter_vr/video/view/YSVideoImage.dart'; import 'YSVideoVRDetail.dart'; class YSVideoList extends StatefulWidget { const YSVideoList({Key? key}) : super(key: key); @override YSVideoListState createState() => YSVideoListState(); } class YSVideoListState extends State { List _dataArray = []; final YSVideoTable _ysVideoTable = YSVideoTable().init(); bool _isVR = false; @override void initState() { Future.delayed(const Duration(seconds: 0)).then((value) { _getData(); }); super.initState(); } _getData() async{ _dataArray = await _ysVideoTable.rawQuery(); LogUtil.d(_dataArray); setState(() {}); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, appBar: CupertinoNavigationBar( backgroundColor: appColor, middle: const Text('添加文件',style: TextStyle(fontSize: 20,color: Colors.white),), trailing: GestureDetector( onTap: (){ _isVR = !_isVR; setState(() {}); }, child: Text(_isVR?'VR':'普通',style: const TextStyle(fontSize: 15,color: Colors.white),) ), ), body: ListView.separated( itemBuilder: (context,index){ Map item = _dataArray[index]; return Slidable( key: const ValueKey(0), endActionPane: ActionPane( extentRatio: 0.3, motion: GestureDetector( onTap: (){ ysShowCenterAlertView(context, YSTipsAlertView(valueSetter: (value) async{ if(value){ _ysVideoTable.rawDelete('${item['id']}'); _getData(); } },tipsStr: '是否移除次视频?',)); }, child: Container( color: Colors.red, alignment: Alignment.center, child: const Text('移除',style: TextStyle(fontSize: 15,color: Colors.white),), ), ), children: const [], ), child: GestureDetector( onTap: (){ Navigator.of(context).push( CupertinoPageRoute(builder: (context){ return _isVR?YSVideoVRDetail(video: item,):YSVideoDetail(video: item,); }) ); }, behavior: HitTestBehavior.opaque, child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ ClipRRect( borderRadius: const BorderRadius.all(Radius.circular(5)), child: Container( height: 80, width: 100, color: appColor, child: YSVideoImage(path: item['path'],), ), ), Expanded(child: Container( padding: const EdgeInsets.only(left: 10,top: 10,bottom: 5), height: 80, child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(item['name'],style: const TextStyle(fontSize: 15,color: Colors.black),maxLines: 3, overflow: TextOverflow.ellipsis,), // Text(item['time'],style: const TextStyle(fontSize: 12,color: Colors.grey),) ], ), )) ], ), ), ); }, separatorBuilder: (context,index){ return Container(height: 10,); }, itemCount: _dataArray.length, padding: const EdgeInsets.only(top: 10,bottom: 10,left: 15,right: 15), ), floatingActionButton: GestureDetector( onTap: () async{ FilePickerResult? result = await FilePicker.platform.pickFiles( type: FileType.custom, allowedExtensions: ['mp4', 'avi', 'wmv', 'mkv', 'mov'],//,'jpg','jpeg' ); if(result!=null){ List files = result.files; for (var file in files) { bool isHas = _dataArray.any((element) => element['path']==file.path); if(isHas==false){ _ysVideoTable.rawInsert(name: file.name, path: file.path!, time: '0'); }else{ LogUtil.d('已添加'); } } _getData(); } }, child: Icon(Icons.add_circle,size: 60,color: appColor,) ), ); } }