123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680 |
- import 'package:flutter/material.dart';
- import 'package:liftmanager/res/gaps.dart';
- import 'package:liftmanager/net/api_service.dart';
- import 'package:liftmanager/utils/toast.dart';
- import 'package:liftmanager/widgets/app_bar.dart';
- import 'package:liftmanager/internal/search/search_router.dart';
- import 'package:liftmanager/widgets/app_search_bar.dart';
- import 'package:liftmanager/res/resources.dart';
- import 'package:liftmanager/routers/fluro_navigator.dart';
- import 'package:liftmanager/widgets/load_image.dart';
- import 'package:liftmanager/widgets/selected_image_change.dart';
- import 'package:image_picker/image_picker.dart';
- import 'dart:io';
- import 'package:liftmanager/widgets/bbs_content.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:flutter_spinkit/flutter_spinkit.dart';
- import 'package:video_player/video_player.dart';
- import 'package:liftmanager/utils/image_utils.dart';
- import 'package:liftmanager/internal/bbs/bbs_router.dart';
- import 'package:liftmanager/internal/wode/wode_router.dart';
- import 'package:liftmanager/internal/bbs/model/video_detail.dart';
- import 'package:liftmanager/utils/log_util.dart';
- import 'dart:convert';
- import 'package:flustars/flustars.dart' as FlutterStars;
- import 'package:liftmanager/common/common.dart';
- import 'dart:math';
- import 'package:liftmanager/utils/fast_notification.dart';
- import 'package:liftmanager/utils/theme_utils.dart';
- class VideoUpload extends StatefulWidget {
- VideoUpload(this.id);
- final String id;
-
- @override
- State<StatefulWidget> createState() {
- return VideoUploadState();
- }
- }
- class VideoUploadState extends State<VideoUpload> {
- // NewsDetailItem item = NewsDetailItem();
-
- ScrollController _scrollController = new ScrollController();
- String brandChiose='请选择';
- String brandName = "品牌";
- int brandIdss;
- bool sortBool = true;
- List<String> imagesUrl = [];
- List<String> videoUrl = [];
- VideoDetailModel detailObj;
- // 焦点控制
- FocusNode _focusNode1 = new FocusNode();
- GlobalKey _formKey= new GlobalKey<FormState>();
- TextEditingController _titleController = new TextEditingController();
- TextEditingController _descController = new TextEditingController();
- @override
- void initState() {
- super.initState();
- print(widget.id);
-
- if(widget.id!=null&&widget.id!=""){
- NewApiService().getVideoDetail(int.parse(widget.id), 1,
- onSuccess: (res) {
- if (res != null) {
- detailObj = res;
-
- LogUtil.d(jsonEncode(res));
- print(88885);
-
- setState(() {
- videoUrl = [];
- imagesUrl = [];
- videoUrl.add(res.url);
- imagesUrl.add(res.cover);
- _titleController.text = res.title;
- _descController.text = res.descr;
- brandIdss = res.brandId;
- brandChiose = res.brandName;
- });
-
- }
- }, onError: (code, msg) {
- toasts(msg);
- });
- }
- }
- upLoadFileOnce(path) {
- showLoading(context, "正在上传...");
- NewApiService().upload(path, onSuccess: (res) {
- // imagesUrl.add(res.path);
- dismissLoading(context);
- setState(() {
- videoUrl = [];
- imagesUrl = [];
- videoUrl.add(res.pathUrl);
- imagesUrl.add(res.coverUrl);
-
- });
- }, onError: (code, msg) {
- dismissLoading(context);
- toasts(msg);
- });
- }
- randomInt(int min, int max) {
- return new Random().nextInt(max) % (max - min + 1) + min;
- }
- List<dynamic> brandList;
- Future getBrandList() async {
- await NewApiService().getBrandListNoPage(
- onSuccess: (res) {
- if (res != null) {
- brandList = res;
- setState(() {});
- }
- }, onError: (code, msg) {
- toasts(msg);
- });
- }
- ///选择视频
- void selectPicker() {
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return SimpleDialog(
- title: Text("选择方式"),
- children: ["拍照", '从手机相册选择'].map((String value) {
- print("$value");
- return SimpleDialogOption(
- child: Text(
- "${value}",
- style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
- ),
- onPressed: () {
- _getImage(value == '拍照' ? 1 : 0);
- Navigator.of(context).pop();
- },
- );
- }).toList());
- });
- }
- void _getImage(int key) async {
- print(key);
- print(333);
- try {
- var _imageFile = await ImagePicker.pickVideo(
- source: key == 1 ? ImageSource.camera : ImageSource.gallery,
- );
- if (_imageFile != null) {
- // print(123);
- // print(_imageFile);
- // print(jsonEncode(_imageFile));
- LogUtil.d(_imageFile);
- LogUtil.d(_imageFile.hashCode);
- LogUtil.d(_imageFile.path);
- print(123);
- upLoadFileOnce(_imageFile.path);
- setState(() {});
- }
- } catch (e) {
- toasts("没有权限,无法打开相册!");
- }
- }
- FocusNode focusNode1 = new FocusNode();
- @override
- Widget build(BuildContext context) {
- double width = MediaQuery.of(context).size.width;
- double height = MediaQuery.of(context).size.height;
-
- // 监听FocusNode
- _focusNode1.addListener((){
- // _focusNode1.hasFocus 是否聚焦
- print(_focusNode1.hasFocus);
- });
- return Scaffold(
- resizeToAvoidBottomPadding: false,//不让键盘弹上去
- appBar: MyAppBar(
- centerTitle: "上传视频",
- ),
- body:GestureDetector(
- onTap: () {
- // 点击空白页面关闭键盘
- FocusScope.of(context).requestFocus(focusNode1);
- },
- child: Stack(
- children: <Widget>[
- Container(
- child: ListView(
- children: <Widget>[
- Form(
- key: _formKey, //设置globalKey,用于后面获取FormState
- // autovalidate: true, //开启自动校验
- child: Column(
- children: <Widget>[
- ChioseThisRight(label: "电梯品牌",value:brandChiose,fun:(){
- setState(() {
- // brandChiose = brandListChiose[index];
- sortBool = false;
- print(5656333);
- });
- getBrandList();
- // Navigator.maybePop(context);
- }),
-
- Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- Container(
- padding:EdgeInsets.only(left:ScreenUtil().setWidth(15),top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(5)),
- child: Text(
- "视频标题",
- style: TextStyle(
- color:Color(0xff222222),
- // fontSize:ScreenUtil().setSp(14),
-
- ),
- textAlign:TextAlign.left,
- ),
- ),
- ],
- ),
- Container(
- height:80,
- padding: EdgeInsets.only(left:ScreenUtil().setWidth(15),right:ScreenUtil().setWidth(15),bottom:ScreenUtil().setWidth(20)),
- child: TextFormField(
- // autofocus: true,
- maxLength: 50,
- cursorColor: Color(0xffcccccc),
- controller: _titleController,
- maxLines:5,
- decoration: InputDecoration(
- contentPadding: EdgeInsets.all(0),
-
- hintText: '请输入你上传视频的标题',
- hintStyle:TextStyle(
- color: Color(0xffcccccc)
- ),
- focusedBorder: InputBorder.none,
- border: InputBorder.none,
- // filled: true, // 背景色
- // fillColor: Colors.cyan.withAlpha(35),
- // icon: Icon(Icons.person)
- ),
-
- // 校验
- validator: (val) {
- return val.trim().length > 0 ? null : "不能为空";
- }
- ),
- ),
- SizedBox(
- height:6,
- child: Container(
- color:ThemeUtils.getDialogTextFieldColor(context)
- ),
- ),
- Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- Container(
- padding:EdgeInsets.only(left:ScreenUtil().setWidth(15),top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(5)),
- child: Text(
- "视频简介",
- style: TextStyle(
- color:Color(0xff222222),
- // fontSize:ScreenUtil().setSp(14),
-
- ),
- textAlign:TextAlign.left,
- ),
- ),
- ],
- ),
- Container(
- height:120,
- padding: EdgeInsets.only(left:ScreenUtil().setWidth(15),right:ScreenUtil().setWidth(15),bottom:ScreenUtil().setWidth(20)),
- child: TextFormField(
- // autofocus: true,
- maxLength: 500,
- cursorColor: Color(0xffcccccc),
- controller: _descController,
- maxLines:5,
- decoration: InputDecoration(
- contentPadding: EdgeInsets.all(0),
-
- hintText: '请输入您上传视频的简介',
- hintStyle:TextStyle(
- color: Color(0xffcccccc)
- ),
- focusedBorder: InputBorder.none,
- border: InputBorder.none,
- // filled: true, // 背景色
- // fillColor: Colors.cyan.withAlpha(35),
- // icon: Icon(Icons.person)
- ),
-
- // 校验
- validator: (val) {
- return val.trim().length > 0 ? null : "不能为空";
- }
- ),
- ),
- SizedBox(
- height:6,
- child: Container(
- color:ThemeUtils.getDialogTextFieldColor(context)
- ),
- ),
- Container(
- width: width,
- padding: EdgeInsets.only(left:15,top:15),
- child: Text(
- "(建议时长3分钟,建议大小50M)",
- style: TextStyle(
- color: Colors.red,
- fontSize:
- ScreenUtil()
- .setSp(14),
- ),
- textAlign: TextAlign.left,
- ),
- ),
- Container(
- color: ThemeUtils.getTabsBg(context),
- child: GridView.builder(
- shrinkWrap: true,
- padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
- physics: NeverScrollableScrollPhysics(),
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: 3, childAspectRatio: 1.18),
- itemCount: videoUrl.length >= 1 ? 1 : videoUrl.length + 1,
- itemBuilder: (_, index) {
- return Stack(
- children: <Widget>[
- Center(
- child: SelectedImage(
- image: index < videoUrl.length ? imagesUrl[index] : null,
- // image: index < videoUrl.length ? videoUrl[index] : null,
- index:index,
- onTap: () {
- if(index >= videoUrl.length){
- selectPicker();
- }
- FocusScope.of(context).requestFocus(FocusNode());
- print(index);
- print(videoUrl);
- }),
- ),
- index < videoUrl.length?Positioned(
- top:0,
- right:0,
- child:GestureDetector(
- onTap: (){
- print(index);
- videoUrl.remove(videoUrl[index]);
- imagesUrl.remove(imagesUrl[index]);
- setState(() {
-
- });
- },
- child:Icon(
- IconData(
- 0xe62a,
- fontFamily:"myfont"
- ),
- size: 24.0,
- color:Color(0xff999999),
- ),
- )
- ):Container(child: null,)
- ],
- );
- },
- )
- ),
- SizedBox(
- height:ScreenUtil().setWidth(80),
- ),
- ],
- ),
- )
- ]
- )
-
- ),
- Positioned(
- bottom:0,
- left:0,
- child:Container(
- width: width,
- padding: EdgeInsets.only(top:ScreenUtil().setWidth(15),bottom:ScreenUtil().setWidth(15),left:ScreenUtil().setWidth(25),right:ScreenUtil().setWidth(25)),
- color:ThemeUtils.getDialogTextFieldColor(context),
- child: Container(
- height:ScreenUtil().setWidth(44),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(ScreenUtil().setWidth(22)),
- gradient: const LinearGradient(
- colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
- ),
- child: FlatButton(
- // padding: EdgeInsets.all(15.0),
- child: Text("提交"),
- textColor: Colors.white,
- onPressed: () {
- if(brandIdss==null){
- toasts("请选择品牌");
- return;
- }
- if(videoUrl.length<1){
- toasts("请上传视频");
- return;
- }
- String videos = videoUrl.join(",");
- String images = imagesUrl.join(",");
- if((_formKey.currentState as FormState).validate()){
-
-
- showLoading(context, "正在提交...");
- if(widget.id!=null&&widget.id!=""){
- dynamic objEdit = {
- "brandId":brandIdss,
- "title":_titleController.text,
- "descr":_descController.text,
- "url":videos,
- "cover": images,
- "checkFlag":2,
- "statuz":1,
- "platformFlag":1,
- "userId":FlutterStars.SpUtil.getString(Constant.userId),
- "id":detailObj.id
- };
- NewApiService().editVideo(objEdit, onSuccess: (res) {
- dismissLoading(context);
- toasts("修改成功");
- String initThisMyVideo = randomInt(1111,9999).toString() + DateTime.now().millisecondsSinceEpoch.toString();
- FastNotification.push("initMyVideo",initThisMyVideo);
- Navigator.pop(context);
- }, onError: (code, msg) {
- dismissLoading(context);
- toasts(msg);
- });
- }else {
- dynamic obj = {
- "brandId":brandIdss,
- "title":_titleController.text,
- "descr":_descController.text,
- "url":videos,
- "cover": images,
- "checkFlag":2,
- "statuz":1,
- "platformFlag":1,
- "userId":FlutterStars.SpUtil.getString(Constant.userId)
- };
- NewApiService().addVideo(obj, onSuccess: (res) {
- dismissLoading(context);
- toasts("提交成功");
- String initThisMyVideo = randomInt(1111,9999).toString() + DateTime.now().millisecondsSinceEpoch.toString();
- FastNotification.push("initMyVideo",initThisMyVideo);
- Navigator.pop(context);
- }, onError: (code, msg) {
- dismissLoading(context);
- toasts(msg);
- });
- }
-
-
-
-
- }
-
- },
- ),
- ),
- )
- ),
- !sortBool?
- Positioned(
- top:0,
- left:0,
- child: Container(
- width:width,
- height:height,
- color: Color.fromRGBO(0, 0, 0, 0.5)
- )
- )
- :Container(
- child:null
- ),
- !sortBool?
- Positioned(
- top:0,
- right:0,
- child:Container(
- width: width/4*3,
- height:height,
- color: ThemeUtils.getTabsBg(context),
- padding: EdgeInsets.all(10),
- child:ListView(
- children:<Widget>[
- Container(
- padding: EdgeInsets.only(left:5,top:5,bottom:10),
- child:Text(
- "品牌",
- style: TextStyle(
- color:Color(0xff666666),
- fontSize:ScreenUtil().setSp(16)
- ),
- textAlign:TextAlign.start,
- ),
- ),
- brandList!=null&&brandList!=[]?Container(
- child: Wrap(
- alignment: WrapAlignment.start,
- crossAxisAlignment: WrapCrossAlignment.center,
- children: brandList.asMap().keys.map((index){
- return InkWell(
- onTap: (){
- print("666");
-
- setState(() {
- sortBool = true;
- brandChiose = brandList[index].name??"";
- brandIdss = brandList[index].id;
- });
-
- },
- child: Container(
- width: width/4-17,
- padding: EdgeInsets.only(bottom:ScreenUtil().setWidth(10),top:ScreenUtil().setWidth(10)),
- margin: EdgeInsets.only(left:5,right:5,bottom:5,top:5),
- decoration: BoxDecoration(
- // border: Border(
- // bottom: BorderSide(width: 0.5, color: Colours.line),
- // ),
- color: Color(0xfff5f5f5)
- ),
- child:Text(
- brandList[index].name??"",
- style: TextStyle(
- color:Color(0xff666666),
- fontSize:ScreenUtil().setSp(15)
- ),
- textAlign:TextAlign.center,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- );
-
- }).toList(),
- )
- ):loadCircle()
- ],
-
- )
- )
- ):
- Container(
- child:null
- ),
- ],
- ),
- ),
- );
- }
- Widget loadCircle() {
- return Container(
- padding: EdgeInsets.only(top: 10, bottom: 10),
- color: ThemeUtils.getTabsBg(context),
- child: Center(
- child: SpinKitFadingCircle(
- color: Colors.blueAccent,
- size: 30.0,
- ),
- ),
- );
- }
- }
- class ChioseThisRight extends StatelessWidget {
- ChioseThisRight({Key key,this.value,this.label,this.fun,this.labelText='请选择'}) : super(key: key);
- String value;
- String label;
- Function fun;
- String labelText;
- @override
- Widget build(BuildContext context) {
- double width = MediaQuery.of(context).size.width;
- return InkWell(
- onTap: (){
- fun();
- },
- child: Container(
- padding: EdgeInsets.only(top:ScreenUtil().setWidth(15),bottom:ScreenUtil().setWidth(15)),
- margin: EdgeInsets.only(left:ScreenUtil().setWidth(15)),
- decoration: BoxDecoration(
- border: Border(
- bottom: BorderSide(width: 0.5, color: Colours.line),
- ),
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children:<Widget>[
- Text(
- label,
- style: TextStyle(
- color:Color(0xff222222),
- // fontSize: ScreenUtil().setSp(14)
- ),
- textAlign:TextAlign.start,
- ),
- value.isEmpty? Container(
- child: Row(
- children:<Widget>[
- Text(
- labelText,
- style: TextStyle(
- color:Color(0xffcccccc),
- // fontSize: ScreenUtil().setSp(14)
- ),
- textAlign:TextAlign.start,
- ),
- Container(
- padding: EdgeInsets.only(top:3),
- child: Icon(
- Icons.keyboard_arrow_right,
- size: 20.0,
- color:Color(0xffcccccc),
- ),
- ),
- SizedBox(
- width:10
- )
- ]
- ),
- ):
- Container(
- padding: EdgeInsets.only(right:ScreenUtil().setWidth(15)),
- child: Row(
- children:<Widget>[
- Text(
- value,
- style: TextStyle(
- color:Color(0xff222222),
- fontSize: ScreenUtil().setSp(14)
- ),
- textAlign:TextAlign.start,
- ),
- ]
- ),
- ),
- ]
- ),
- ),
- );
- }
- }
|