123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- import 'package:flutter/material.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:ysairplane/base/YSBase.dart';
- import 'package:ysairplane/tools/YSNetWorking.dart';
- import 'package:ysairplane/tools/YSTools.dart';
- import 'package:image_picker/image_picker.dart';
- import 'package:smooth_star_rating/smooth_star_rating.dart';
- import 'package:sy_flutter_qiniu_storage/sy_flutter_qiniu_storage.dart';
- class YSCommentAdd extends StatefulWidget {
- final String orderStr;
- const YSCommentAdd({Key key, this.orderStr}) : super(key: key);
- @override
- _YSCommentAddState createState() => _YSCommentAddState();
- }
- class _YSCommentAddState extends State<YSCommentAdd> {
- ImagePicker _picker = ImagePicker();
- List _images = [];
- List _types = [];
- List _comments = [];
- String _tokenStr = '';
- String _urlStr = '';
- TextEditingController _content = TextEditingController();
- @override
- void initState() {
- Future.delayed(Duration(seconds: 0)).then((value){
- _getQiNiuTokenData();
- _getCommentType();
- });
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return YSBase(
- ystitle: '点评',
- yschild: Container(
- height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44,
- width: MediaQuery.of(context).size.width,
- color: Color(0xFFF4F5F6),
- child: Column(
- children: [
- Container(
- margin: EdgeInsets.only(top: hsp(20)),
- padding: EdgeInsets.all(hsp(30)),
- color: Colors.white,
- child: ListView.builder(
- itemBuilder: (context,index){
- return Container(
- height: hsp(80),
- child: Row(
- children: [
- Text('${_types[index]['name']}',style: TextStyle(fontSize: zsp(30),color: Color(0xFF535353)),),
- Container(
- margin: EdgeInsets.only(left: wsp(80),right: wsp(80)),
- child: SmoothStarRating(
- rating: double.parse('${_comments[index]['score']}'),
- isReadOnly: false,
- size: hsp(40),
- filledIconData: Icons.star,
- halfFilledIconData: Icons.star_half,
- defaultIconData: Icons.star_border,
- starCount: int.parse('${_types[index]['totalScore']}'),
- allowHalfRating: true,
- spacing: 1.0,
- onRated: (value) {
- _comments[index]['score'] = value;
- },
- color: Color(0xFFF97C00),
- borderColor: Color(0xFFF97C00),
- ),
- ),
- //Text('超棒',style: TextStyle(fontSize: zsp(30),color: Color(0xFFBFBFBF)),),
- ],
- ),
- );
- },
- itemCount: _types.length,
- padding: EdgeInsets.all(0),
- shrinkWrap: true,
- physics: NeverScrollableScrollPhysics(),
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: hsp(10)),
- padding: EdgeInsets.all(hsp(30)),
- width: MediaQuery.of(context).size.width,
- height: hsp(180),
- color: Colors.white,
- child: ListView.separated(
- scrollDirection: Axis.horizontal,
- itemBuilder: (context,index){
- return GestureDetector(
- onTap: (){
- showCupertinoModalPopup(
- context: context,
- builder: (context) {
- return CupertinoActionSheet(
- actions: <Widget>[
- CupertinoActionSheetAction(
- child: Text('拍摄照片'),
- onPressed: () {
- Navigator.pop(context);
- _picker.getImage(source: ImageSource.camera).then((value){
- _onUpload(value);
- });
- },
- ),
- CupertinoActionSheetAction(
- child: Text('选择图片'),
- onPressed: () {
- Navigator.pop(context);
- _picker.getImage(source: ImageSource.gallery).then((value){
- _onUpload(value);
- });
- },
- ),
- ],
- cancelButton: CupertinoActionSheetAction(
- child: Text('取消'),
- onPressed: () {
- Navigator.pop(context);
- },
- ),
- );
- }
- );
- },
- child: index==_images.length?Container(
- height: hsp(120),
- width: hsp(120),
- decoration: BoxDecoration(
- color: Color(0xFFF2F2F2),
- borderRadius: BorderRadius.all(Radius.circular(10))
- ),
- child: Icon(Icons.add,size: 25,color: Color(0xFF9A9A9A),),
- ):Container(
- height: hsp(120),
- width: hsp(120),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.all(Radius.circular(10)),
- image: DecorationImage(image: NetworkImage(_images[index]),fit: BoxFit.fill)
- ),
- )
- );
- },
- separatorBuilder: (context,index){
- return Container(width: 10,);
- },
- itemCount: _images.length+1,
- padding: EdgeInsets.all(0),
- shrinkWrap: true,
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: hsp(10)),
- padding: EdgeInsets.all(hsp(30)),
- width: MediaQuery.of(context).size.width,
- color: Colors.white,
- child: Column(
- children: [
- GestureDetector(
- onTap: (){
- Navigator.push(context, PopRoute(child: BottomInputDialog(
- height: 50,
- inputView: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Container(
- width: MediaQuery.of(context).size.width-100,
- child: CupertinoTextField(
- placeholder: '说点儿好听的~',
- style: TextStyle(fontSize: 15,color: Color(0xFF5A5A5A),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
- placeholderStyle: TextStyle(fontSize: 15,color: Color(0xFF5A5A5A),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
- autofocus: true,
- decoration: BoxDecoration(),
- controller: _content,
- ),
- ),
- Icon(Icons.alternate_email,size: 25,color: Color(0xFFA1A1A2),),
- Icon(Icons.tag_faces,size: 25,color: Color(0xFFA1A1A2),),
- ],
- ),
- )));
- },
- child: Container(
- height: hsp(200),
- decoration: BoxDecoration(
- color: Color(0xFFF4F5F6),
- borderRadius: BorderRadius.all(Radius.circular(5))
- ),
- width: MediaQuery.of(context).size.width-hsp(60),
- padding: EdgeInsets.all(hsp(20)),
- child: SingleChildScrollView(
- child: Text(_content.text.isEmpty?'添加正文':_content.text,style: TextStyle(fontSize: 15,color: Color(0xFF9A9A9A)),),
- ),
- ),
- ),
- Container(
- width: MediaQuery.of(context).size.width-hsp(60),
- child: RichText(
- text: TextSpan(
- text: '还差',
- style: TextStyle(fontSize: 14,color: Color(0xFF9A9A9A)),
- children: [
- TextSpan(
- text: '15',
- style: TextStyle(color: Color(0xFFEB8232))
- ),
- TextSpan(
- text: '字,即可发表点评'
- )
- ]
- ),
- ),
- height: hsp(60),
- alignment: Alignment.centerRight,
- ),
- ],
- ),
- ),
- GestureDetector(
- onTap: (){
- _postCommentData();
- },
- child: Container(
- margin: EdgeInsets.only(top: hsp(200)),
- width: MediaQuery.of(context).size.width-hsp(100),
- height: hsp(92),
- alignment: Alignment.center,
- decoration: BoxDecoration(
- color: Color(0xFF143C64),
- borderRadius: BorderRadius.all(Radius.circular(5))
- ),
- child: Text('发布',style: TextStyle(fontSize: 18,color: Colors.white,fontWeight: FontWeight.bold),),
- ),
- )
- ],
- ),
- ),
- );
- }
- _getQiNiuTokenData() async{
- Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/getToken',parameter: {},isLoading: false,isToken: false);
- if(dict!=null){
- _tokenStr = dict['token'];
- _urlStr = dict['prefix'];
- }
- }
- _onUpload(var value) async {
- if (value == null) {
- return;
- }
- print(value.path);
- print(_tokenStr);
- final syStorage = new SyFlutterQiniuStorage();
- //监听上传进度
- syStorage.onChanged().listen((dynamic percent) {
- print(percent);
- });
- //上传文件
- var result = await syStorage.upload(value.path, _tokenStr, DateTime.now().millisecondsSinceEpoch.toString() +'.' +value.path.split('.').last);
- if(result.success==true){
- setState(() {
- _images.add(_urlStr+'${result.result['key']}');
- });
- }
- print(result);
- }
- _getCommentType() async{
- Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/orderscoring/type/list',parameter: {},isLoading: false,isToken: false);
- if(dict!=null){
- _types = dict['data'];
- _types.forEach((element) {
- _comments.add({'orderscoringtypeid':element['id'],'score':5});
- });
- setState(() {});
- }
- }
- _postCommentData() async{
- if(_content.text.isEmpty){
- ysFlutterToast(context, '请输入评价内容');
- return;
- }
- Map request = {};
- request['content'] = _content.text;
- request['ordersn'] = widget.orderStr;
- request['picture'] = _images.join(',');
- request['dtOrderScoringList'] = _comments;
- Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/applets/orderscoring/add',parameter: request,
- isLoading: false,isToken: true);
- if(dict!=null){
- Navigator.of(context).pop('');
- }
- }
- }
|