[baozhangchao] 3 vuotta sitten
vanhempi
commit
e1a6ebb466

+ 85
- 2
lib/pages/orderInfo/index.dart Näytä tiedosto

1
+import 'package:farmer_client/pages/orderInfo/widgets/star.dart';
1
 import 'package:farmer_client/widgets/DefaultButton.dart';
2
 import 'package:farmer_client/widgets/DefaultButton.dart';
3
+import 'package:ff_stars/ff_stars.dart';
2
 import 'package:flutter/material.dart';
4
 import 'package:flutter/material.dart';
3
 import 'package:flutter_screenutil/flutter_screenutil.dart';
5
 import 'package:flutter_screenutil/flutter_screenutil.dart';
4
 import 'package:fluttertoast/fluttertoast.dart';
6
 import 'package:fluttertoast/fluttertoast.dart';
21
   final orderStateText = Rx<String>('待支付');
23
   final orderStateText = Rx<String>('待支付');
22
   final orderStateColor = Rx<Color>(Colors.black);
24
   final orderStateColor = Rx<Color>(Colors.black);
23
   final orderInfoContent = Rx<OrderInfoModel>(OrderInfoModel());
25
   final orderInfoContent = Rx<OrderInfoModel>(OrderInfoModel());
26
+  final evalText=Rx<String>('');
27
+  final evalStars=Rx<num>(-1);
28
+
29
+
24
   // orderStates
30
   // orderStates
25
 
31
 
26
   @override
32
   @override
75
                     height: 49.h,
81
                     height: 49.h,
76
                     text: '评价',
82
                     text: '评价',
77
                     onPressed: () {
83
                     onPressed: () {
78
-                      Fluttertoast.showToast(msg: '评价成功!');
79
-                      Get.offNamed('/order');
84
+
85
+                      modal.showDialog(
86
+                          title: '评价此订单',
87
+                          content: Container(
88
+                            alignment: Alignment.center,
89
+                            child:Container(
90
+                              margin: const EdgeInsets.fromLTRB(15, 20, 15, 20),
91
+                              child: Column(
92
+                                children: [
93
+                                  Container(
94
+                                    padding: const EdgeInsets.fromLTRB(0, 0, 0, 10),
95
+                                    decoration: const BoxDecoration(
96
+                                        border: Border(
97
+                                            bottom: BorderSide(
98
+                                                width: 0.8, color: Color(0x20000000)
99
+                                              // 0x17000000
100
+                                            ))),
101
+                                    child: Row(
102
+                                      children: [
103
+                                        Text('满意度:',style: TextStyle(fontSize: 17.sp,fontWeight: FontWeight.bold),),
104
+                                        FFStars(
105
+                                          //https://pub.dev/packages/ff_stars
106
+                                          normalStar:Image.asset('images/icons/starOff.png'),
107
+                                          selectedStar:Image.asset('images/icons/starOn.png'),
108
+                                          starsChanged: (realStars, selectedStars) {
109
+                                            evalStars(realStars);
110
+                                            print("real: $selectedStars, final: $realStars");
111
+                                          },
112
+                                          step: 1,
113
+                                          defaultStars: 0,
114
+                                        ),
115
+                                      ],
116
+                                    ),
117
+                                  ),
118
+                                  Container(
119
+                                    margin: const EdgeInsets.fromLTRB(0, 20, 0, 0),
120
+                                    width: 300.w,
121
+                                    height: 100.w,
122
+                                    decoration: BoxDecoration(
123
+                                      border: Border.all(
124
+                                        color: Color(0x20000000),
125
+                                        width: 0.8,
126
+                                      ),
127
+                                    ),
128
+                                    child:  TextField(
129
+                                      minLines: 6,
130
+                                      maxLines: 6,
131
+                                      style: TextStyle(fontSize: 17.sp, height: 1.5),
132
+                                      decoration: const InputDecoration(
133
+                                        isCollapsed: true,
134
+                                        border: InputBorder.none,
135
+                                        counterText: '',
136
+                                        hintText: '请输入评价内容',
137
+                                        floatingLabelBehavior: FloatingLabelBehavior.never,
138
+                                      ),
139
+                                      onChanged: (e) {
140
+                                        evalText(e);
141
+                                      },
142
+                                    ),
143
+                                  )
144
+
145
+                                ],
146
+                              )
147
+                              ,
148
+                            )
149
+                          ),
150
+                          onCancel: () => true,
151
+                          onConfirm:() {
152
+                                if(evalStars.value!=-1&&evalText.value!=''){
153
+                                    orderEvaluation(id,evalStars.value,evalText.value).then((value) {
154
+                                      Fluttertoast.showToast(msg: '评价成功!');
155
+                                       Get.offNamed('/order');
156
+                                    });
157
+                                }else{
158
+                                  Fluttertoast.showToast(msg: '请完整选择评分或输入评价内容');
159
+                                  return false;
160
+                                }
161
+                          }
162
+                          );
80
                     },
163
                     },
81
                     margin: const EdgeInsets.all(0),
164
                     margin: const EdgeInsets.all(0),
82
                     fontSize: 20.sp,
165
                     fontSize: 20.sp,

+ 114
- 0
lib/pages/orderInfo/widgets/star.dart Näytä tiedosto

1
+
2
+import 'package:flutter/material.dart';
3
+
4
+
5
+
6
+
7
+class HTStarRating extends StatefulWidget {
8
+  final double rating;       // 当前分数
9
+  final double maxRating;    // 满分
10
+  final int count;           // 总共几颗心
11
+  final double size;          // 星星大小
12
+  final Color defaultColor;
13
+  final Color selectedColor;
14
+  final Widget unselectedImage;
15
+  final Widget selectedImage;
16
+
17
+  HTStarRating({
18
+    required this.rating,   // 必填
19
+    //选填, 初始默认值
20
+    this.maxRating = 10,
21
+    this.count = 5,
22
+    this.size = 30,
23
+    this.defaultColor = Colors.grey,
24
+    this.selectedColor = Colors.red,
25
+     Widget? unselectedImage,
26
+     Widget? selectedImage,
27
+
28
+
29
+  }):unselectedImage = unselectedImage?? Icon(
30
+      Icons.star_border, color: defaultColor, size: size),
31
+        selectedImage = selectedImage?? Icon(Icons.star, color: selectedColor,size: size);
32
+
33
+  @override
34
+  _HTStarRatingState createState() => _HTStarRatingState();
35
+}
36
+
37
+class _HTStarRatingState extends State<HTStarRating> {
38
+  @override
39
+  Widget build(BuildContext context) {
40
+    return Stack(
41
+      children: <Widget>[
42
+        Row(
43
+            mainAxisSize: MainAxisSize.min,
44
+            children: buildDefaultStar()
45
+        ),
46
+        Row(
47
+            mainAxisSize: MainAxisSize.min,
48
+            children: buildSelectedStar()
49
+        )
50
+      ],
51
+    );
52
+  }
53
+
54
+
55
+  /*
56
+  *  创建默认的星星
57
+  * */
58
+  List<Widget> buildDefaultStar(){
59
+    return List.generate(widget.count, (index) {
60
+      return widget.unselectedImage;
61
+    });
62
+  }
63
+
64
+  /*
65
+  *  创建选中的星星
66
+  * */
67
+  List<Widget> buildSelectedStar() {
68
+    // 创建stats
69
+    List<Widget> starts = [];
70
+    final star = widget.selectedImage;
71
+    //构建满的start
72
+    double oneValue = widget.maxRating / widget.count;
73
+    int entireCount = (widget.rating / oneValue).floor(); //.floor() 向下取整
74
+
75
+    for (var i = 0; i< entireCount ; i++){
76
+      starts.add(star);
77
+    }
78
+    //构建部分start
79
+    double leftWidth = ((widget.rating /oneValue)-entireCount)* widget.size;
80
+    final halfStar = ClipRect(
81
+        clipper: HTStartClipper(leftWidth),
82
+        child: star
83
+    );
84
+    starts.add(halfStar);
85
+
86
+    // 防止传入参数大于总分
87
+    if (starts.length > widget.count){
88
+      return starts.sublist(0,widget.count);
89
+    }
90
+
91
+    return starts;
92
+  }
93
+}
94
+
95
+/*
96
+* 切割
97
+* */
98
+class HTStartClipper extends CustomClipper<Rect> {
99
+
100
+  double width;
101
+
102
+  HTStartClipper(this.width);
103
+
104
+  @override
105
+  Rect getClip(Size size) {
106
+    return Rect.fromLTRB(0, 0, width, size.height);
107
+  }
108
+
109
+  @override
110
+  bool shouldReclip(HTStartClipper oldClipper) {
111
+    return oldClipper.width != this.width;
112
+  }
113
+
114
+}

+ 15
- 0
lib/services/orderAPI.dart Näytä tiedosto

75
 }
75
 }
76
 
76
 
77
 
77
 
78
+
79
+
80
+/**
81
+ * 评价订单
82
+ * @param {*} data
83
+ * @returns
84
+ */
85
+
86
+Future orderEvaluation (String orderId,num score,String content)async{
87
+  return request('/evaluation',options: Options(method: 'POST'),data: {'orderId':orderId,'score':score,'content':content}).catchError((error) =>
88
+  { Fluttertoast.showToast(
89
+      msg: error.error['message']
90
+  ),});
91
+}
92
+

+ 2
- 2
lib/widgets/OrderInfoCard.dart Näytä tiedosto

133
                       padding: EdgeInsets.fromLTRB(0, 0, 0, 20),
133
                       padding: EdgeInsets.fromLTRB(0, 0, 0, 20),
134
                       child: RichText(
134
                       child: RichText(
135
                         text:  TextSpan(children: <InlineSpan>[
135
                         text:  TextSpan(children: <InlineSpan>[
136
-                          TextSpan(
136
+                          const TextSpan(
137
                               text: '下单时间:',
137
                               text: '下单时间:',
138
                               style: TextStyle(
138
                               style: TextStyle(
139
                                   color: Color(0xff666666),
139
                                   color: Color(0xff666666),
143
                               // text: DateFormat("yyyy-MM-dd").format(DateTime.parse(item.createDate!.toString())),
143
                               // text: DateFormat("yyyy-MM-dd").format(DateTime.parse(item.createDate!.toString())),
144
                               text:item.createDate!=null? DateFormat("yyyy-MM-dd").format(DateTime.parse(item.createDate.toString())):item.createDate.toString(),
144
                               text:item.createDate!=null? DateFormat("yyyy-MM-dd").format(DateTime.parse(item.createDate.toString())):item.createDate.toString(),
145
 
145
 
146
-                              style: TextStyle(
146
+                              style: const TextStyle(
147
                                   color: Color(0xff222222),
147
                                   color: Color(0xff222222),
148
                                   fontSize: 16,
148
                                   fontSize: 16,
149
                                   fontWeight: FontWeight.bold)),
149
                                   fontWeight: FontWeight.bold)),

+ 7
- 0
pubspec.lock Näytä tiedosto

155
       url: "https://pub.dartlang.org"
155
       url: "https://pub.dartlang.org"
156
     source: hosted
156
     source: hosted
157
     version: "1.2.0"
157
     version: "1.2.0"
158
+  ff_stars:
159
+    dependency: "direct main"
160
+    description:
161
+      name: ff_stars
162
+      url: "https://pub.dartlang.org"
163
+    source: hosted
164
+    version: "1.0.0"
158
   ffi:
165
   ffi:
159
     dependency: transitive
166
     dependency: transitive
160
     description:
167
     description:

+ 2
- 0
pubspec.yaml Näytä tiedosto

49
   amap_flutter_location: ^3.0.0
49
   amap_flutter_location: ^3.0.0
50
   carousel_slider: ^4.0.0
50
   carousel_slider: ^4.0.0
51
   permission_handler: ^9.2.0
51
   permission_handler: ^9.2.0
52
+  ff_stars: ^1.0.0
53
+
52
 #  flutter_bmflocation: ^3.1.0+1
54
 #  flutter_bmflocation: ^3.1.0+1
53
 
55
 
54
 
56