提交 047a73da authored 作者: maodou's avatar maodou

订单评价

上级 54488db0
......@@ -3,10 +3,11 @@ part of user_order_evaluate;
/// 订单评价
class UserOrderEvaluateController extends GetxController {
OrderInfoModel orderInfoModel;
late OrderInfoModel orderInfoModel = OrderInfoModel();
String orderNum;
UserOrderEvaluateController(this.orderNum,this.orderInfoModel); // 已完成订单
UserOrderEvaluateController(this.orderNum); // 已完成订单
final TextEditingController commentsInput = TextEditingController();
final FocusNode _focusNode = FocusNode();
// 按钮是否可用
bool _enable = false;
bool get enable => _enable;
......@@ -33,8 +34,8 @@ class UserOrderEvaluateController extends GetxController {
}
}
void setCanClick(num double){
if (double > 0){
void setCanClick({num double=0}){
if (double > 0 || commentsInput.text!=''){
_enable = true;
}
else{
......@@ -42,4 +43,11 @@ class UserOrderEvaluateController extends GetxController {
}
update();
}
@override
void onClose() {
commentsInput.dispose();
_focusNode.dispose();
super.onClose();
}
}
......@@ -16,37 +16,34 @@ class UserOrderEvaluatePage extends StatefulWidget {
}
class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with AutomaticKeepAliveClientMixin{
late UserOrderEvaluateController myController;
List<TextEditingController> controllers = [];
// late UserOrderEvaluateController myController;
List<OrderEvaluate> orderEvaluates = [];
List<double> ratings = [];
@override
void initState() {
myController = Get.put(UserOrderEvaluateController(widget.orderNum,widget.orderInfoModel));
// myController = Get.put(UserOrderEvaluateController(widget.orderNum));
super.initState();
}
@override
Widget build(BuildContext context) {
super.build(context);
return Scaffold(
// super.build(context);
return
GetBuilder<UserOrderEvaluateController>(
init: UserOrderEvaluateController(widget.orderNum),
builder: (controller) => Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text('订单评价'),
),
body: FutureBuilder(
future: myController.getOrderInfo(),
builder: (context, snapshot) {
if(snapshot.connectionState == ConnectionState.waiting){
return Container(
body:(controller.orderInfoModel==null ||controller.orderInfoModel.bookList==null)?
Container(
alignment: Alignment.center,
child: const CircularProgressIndicator(),
); // 加载中的指示
}else{
return Column(
child: const CircularProgressIndicator(),):
Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Container(child: SingleChildScrollView(
child: Column(
children: [
ListView.builder(
......@@ -54,15 +51,15 @@ class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with Auto
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return listItem(
myController.orderInfoModel.bookList![index],
orderEvaluates,controllers);
controller.orderInfoModel.bookList![index],index,controller
/*orderEvaluates,*//*controllers*/);
},
itemCount:
myController.orderInfoModel.bookList?.length,
controller.orderInfoModel.bookList?.length,
),
],
),
),
),),
),
SizedBox(
height: 26.w,
......@@ -71,13 +68,14 @@ class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with Auto
margin: EdgeInsets.symmetric(horizontal: 10.w),
child: CustomGradientButton(
text: '提交评价',
isEnabled: myController.enable,
isEnabled: controller.enable,
onPressed: () {
controller._focusNode.unfocus();
for(int i=0;i<orderEvaluates.length;i++){
orderEvaluates[i].comments=controllers[i].text.toString();
// orderEvaluates[i].comments=controllers[i].text.toString();
}
print(jsonEncode(orderEvaluates));
myController.UpOrderEvaluate(jsonEncode(orderEvaluates));
controller.UpOrderEvaluate(jsonEncode(orderEvaluates));
},
),
),
......@@ -85,27 +83,24 @@ class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with Auto
height: 41.w,
)
],
);
}
},
),
);
),);
}
Widget listItem(BookListModel bookListModel,
List<OrderEvaluate> orderEvaluates,
List<TextEditingController> controllers) {
Widget listItem(BookListModel bookListModel,int index,UserOrderEvaluateController myController) {
int indexToUpdate = orderEvaluates.indexWhere((obj) => obj.recordId == bookListModel.recordId);
// TextEditingController textFieldController= TextEditingController();
// if(indexToUpdate==-1){
// OrderEvaluate evaluate = OrderEvaluate(recordId: bookListModel.recordId);
// orderEvaluates.add(evaluate);
// controllers.add(textFieldController);
// }else{
// textFieldController = controllers[indexToUpdate];
// }
int index = orderEvaluates.length-1;
myController.commentsInput.text =bookListModel.comments.toString();
if(indexToUpdate==-1){
OrderEvaluate evaluate = OrderEvaluate(recordId: bookListModel.recordId,rating: bookListModel.rating,comments: bookListModel.comments);
orderEvaluates.add(evaluate);
}
return Container(
margin:
EdgeInsets.only(left: 10.w, top: 10.w, right: 10.w),
......@@ -196,39 +191,70 @@ class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with Auto
absorbing: false,
child: CustomRating(
max: 5,
score: 0,
score:bookListModel.rating !=null ?bookListModel.rating!.toDouble():0,
star: Star(
fat: 0.5,
progress: 7,
progress: 3,
fillColor: AppTheme.primary,
size: 16.w,
emptyColor: Colours.cE2,
),
onRating: (double) {
orderEvaluates[index].rating=double;
myController.setCanClick(double);
myController.setCanClick(double: double);
print(double);
},
),
),
],
),
Expanded(
// color: Colors.red,
child: CustomInput(
TextField(
controller: myController.commentsInput,
style:
TextStyle(fontSize: 14.w, color: Colours.c3),
decoration: InputDecoration(
focusedBorder: InputBorder.none,
border: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
fillColor: Colors.white,
hintText: '请简要描述',
hintStyle: TextStyle(
fontSize: 14.w, height: 1.5, color: Colours.c6)),
maxLines: 5,
// controller: textFieldController,
hintText: '请简要描述',
),
onChanged: (text){
myController.setCanClick();
orderEvaluates[index].comments=myController.commentsInput.text;
},
focusNode: myController._focusNode,
// onTap: () {
// // 在文本框获取焦点时,将光标移动到文本末尾
// myController.commentsInput.selection = TextSelection.fromPosition(
// TextPosition(offset: myController.commentsInput.text.length),
// );
// },
),
// CustomInputCommands(
// decoration: InputDecoration(
// focusedBorder: InputBorder.none,
// border: InputBorder.none,
// enabledBorder: InputBorder.none,
// errorBorder: InputBorder.none,
// fillColor: Colors.white,
// hintStyle: TextStyle(
// fontSize: 14.w, height: 1.5, color: Colours.c6)),
// maxLines: 5,
// controller: myController.commentsInput,
// hintText: '请简要描述',
// onChanged: (text){
// myController.setCanClick();
// print(myController.commentsInput.text);
// orderEvaluates[index].comments=myController.commentsInput.text;
// },
// focusNode: myController._focusNode,
// ),
],
),
),
......
......@@ -433,4 +433,159 @@ class CustomInputSearch extends StatelessWidget {
}
}
class CustomInputCommands extends StatelessWidget {
final TextEditingController? controller;
final String? label;
final String? helper;
final String? hintText;
final String? error;
final bool required;
final bool readOnly;
final bool obscureText;
final Widget? iconData;
final int? minLines;
final int? maxLines;
final void Function()? onTap;
final void Function()? onIcon;
final ValueChanged<String>? onChanged;
final InputDecoration decoration;
final TextInputType? keyboardType;
final bool autofocus;
final FocusNode focusNode;
final List<TextInputFormatter>? inputFormatters;
const CustomInputCommands({
Key? key,
this.controller,
this.label,
this.helper,
this.hintText,
this.error,
this.required = false,
this.readOnly = false,
this.obscureText = false,
this.onTap,
this.onIcon,
this.iconData,
this.onChanged,
this.decoration = const InputDecoration(),
this.minLines,
this.maxLines = 1,
this.keyboardType,
this.autofocus = false,
this.inputFormatters,
required this.focusNode,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final decorationTheme = theme.inputDecorationTheme;
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (label != null || required)
Padding(
padding: EdgeInsets.symmetric(
horizontal: (decorationTheme.contentPadding?.horizontal ?? 0) / 2,
vertical: 10.w,
).copyWith(top: 0),
child: RichText(
text: TextSpan(
text: label,
style: decorationTheme.labelStyle,
children: [
if (required)
TextSpan(
text: label != null ? ' *' : '*',
style: const TextStyle(color: AppTheme.error),
),
],
),
),
),
DecoratedBox(
decoration: const BoxDecoration(
boxShadow: [
// BoxShadow(
// color: theme.colorScheme.shadow,
// offset: Offset(0, 20.w),
// blurRadius: 10.w,
// spreadRadius: -10.w,
// ),
],
),
child: TextField(
focusNode: focusNode,
autofocus: autofocus,
controller: controller,
readOnly: readOnly,
onTap: onTap,
obscureText: obscureText,
onChanged: onChanged,
minLines: minLines,
maxLines: maxLines,
inputFormatters: inputFormatters,
keyboardType: keyboardType,
style: TextStyle(
// fontFamily: 'Sans',
fontSize: 15.w,
height: 1.2,
// fontWeight: FontWeight.w600,
),
decoration: decoration.copyWith(
hintText: hintText,
hintStyle: const TextStyle(fontWeight: FontWeight.normal,color: Colours.c9,fontSize: 13),
suffixIconConstraints: const BoxConstraints(),
suffixIcon: _suffixIcon(decorationTheme),
),
),
),
AnimatedSize(
duration: const Duration(milliseconds: 180),
alignment: Alignment.topCenter,
child: error != null
? Padding(
padding: EdgeInsets.only(top: 10.w),
// child: CustomAlert.error(
// size: CustomAlertSize.mini,
// text: Text(error!),
// ),
)
: const SizedBox.shrink(),
),
if (helper != null)
Padding(
padding: EdgeInsets.symmetric(
horizontal: (decorationTheme.contentPadding?.horizontal ?? 0) / 2,
vertical: 10.w,
).copyWith(bottom: 0),
child: Text(
helper!,
style: decorationTheme.helperStyle,
),
)
],
);
}
Widget? _suffixIcon(InputDecorationTheme decorationTheme) {
if (iconData == null) return null;
return Padding(
padding: EdgeInsetsDirectional.only(
end: (decorationTheme.contentPadding?.horizontal ?? 0) / 2,
),
child: GestureDetector(
onTap: onIcon,
child: SizedBox(
width: 24,
height: 24,
child: iconData,
)
),
);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论