You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/pages/feedback/send_feedback_page.dart

763 lines
32 KiB
Dart

import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/viewModels/feedback/feedback_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
4 years ago
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
4 years ago
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
4 years ago
import 'package:diplomaticquarterapp/widgets/avatar/large_avatar.dart';
import 'package:diplomaticquarterapp/widgets/bottom_options/BottomSheet.dart';
import 'package:diplomaticquarterapp/widgets/buttons/button.dart';
4 years ago
import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/input/text_field.dart';
4 years ago
import 'package:diplomaticquarterapp/widgets/others/StarRating.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
4 years ago
import 'dart:convert';
import 'dart:io';
4 years ago
import 'appointment_history.dart';
class SendFeedbackPage extends StatefulWidget {
@override
_SendFeedbackPageState createState() => _SendFeedbackPageState();
}
class _SendFeedbackPageState extends State<SendFeedbackPage> {
TextEditingController titleController = TextEditingController();
TextEditingController messageController = TextEditingController();
List<String> images = [];
String title;
4 years ago
AppointmentHistory appointHistory;
bool isShowListAppointHistory = true;
String message;
final formKey = GlobalKey<FormState>();
4 years ago
MessageType messageType = MessageType.NON;
String getSelected(BuildContext context) {
switch (messageType) {
case MessageType.ComplaintOnAnAppointment:
return TranslationBase.of(context).complainAppo;
break;
case MessageType.ComplaintWithoutAppointment:
return TranslationBase.of(context).complainWithoutAppo;
break;
case MessageType.Question:
return TranslationBase.of(context).question;
break;
case MessageType.Compliment:
return TranslationBase.of(context).compliment;
break;
case MessageType.Suggestion:
return TranslationBase.of(context).suggestion;
break;
case MessageType.NON:
return TranslationBase.of(context).notClassified;
break;
}
return TranslationBase.of(context).notClassified;
}
setMessageType(MessageType messageType) {
setState(() {
this.messageType = messageType;
});
}
@override
Widget build(BuildContext context) {
return BaseView<FeedbackViewModel>(
4 years ago
allowAny: true,
builder: (_, model, widget) => AppScaffold(
baseViewModel: model,
4 years ago
isShowDecPage: false,
body: Container(
height: MediaQuery.of(context).size.height * 0.8,
child: SingleChildScrollView(
child: Form(
key: formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 65,
),
Container(
margin: EdgeInsets.only(left: 20, right: 20, top: 8),
child: Texts(
TranslationBase.of(context).likeToHear,
textAlign: TextAlign.center,
),
),
InkWell(
onTap: () {
4 years ago
confirmBox(model);
},
child: Container(
margin: EdgeInsets.only(left: 10, right: 10, top: 15),
height: 50,
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(7),
color: Colors.white,
shape: BoxShape.rectangle,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
child: Texts(
4 years ago
getSelected(context),
variant: 'bodyText',
),
margin: EdgeInsets.only(left: 10,right: 10),
),
Icon(
Icons.arrow_drop_down,
size: 22,
color: Colors.grey,
)
],
),
),
),
4 years ago
if (appointHistory != null && messageType ==
MessageType.ComplaintOnAnAppointment)
4 years ago
InkWell(
onTap: () {
setState(() {
isShowListAppointHistory = true;
});
},
child: Container(
margin: EdgeInsets.all(8.0),
color: Colors.white,
child: Row(
children: <Widget>[
Expanded(
flex: 4,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(10.0),
child: Row(
children: <Widget>[
Expanded(
flex: 1,
child: LargeAvatar(
name: appointHistory.doctorNameObj,
url: appointHistory.doctorImageURL,
),
),
Expanded(
flex: 4,
child: Container(
margin: EdgeInsets.all(10),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Texts(
appointHistory.doctorNameObj,
bold: true,
),
Texts(
DateUtil
.getMonthDayYearDateFormatted(
appointHistory
.appointmentDate),
variant: 'caption3',
),
StarRating(
totalAverage: appointHistory
.doctorRate
.toDouble(),
forceStars: true),
],
),
),
),
],
),
),
],
),
),
Expanded(
flex: 1,
child: Center(
child: Icon(
Icons.arrow_forward_ios,
size: 15,
),
),
)
],
),
),
),
4 years ago
if (messageType == MessageType.ComplaintOnAnAppointment && model.appointHistoryList.length != 0 &&
4 years ago
isShowListAppointHistory)
Container(
4 years ago
height: model.appointHistoryList.length>2?MediaQuery.of(context).size.height * 0.25:MediaQuery.of(context).size.height * 0.15,
4 years ago
child: ListView.builder(
itemCount: model.appointHistoryList.length,
itemBuilder: (context, index) => InkWell(
onTap: () {
setState(() {
appointHistory = model.appointHistoryList[index];
isShowListAppointHistory = false;
});
},
child: Container(
margin: EdgeInsets.only(left: 8, right: 8),
color: Colors.white,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
flex: 4,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(10.0),
child: Row(
children: <Widget>[
Expanded(
flex: 1,
child: LargeAvatar(
name: model
.appointHistoryList[
index]
.doctorNameObj,
url: model
.appointHistoryList[
index]
.doctorImageURL,
),
),
Expanded(
flex: 4,
child: Container(
margin: EdgeInsets.all(10),
child: Column(
crossAxisAlignment:
CrossAxisAlignment
.start,
children: <Widget>[
Texts(
model
.appointHistoryList[
index]
.doctorNameObj,
bold: true,
),
Texts(
DateUtil.getMonthDayYearDateFormatted(model
.appointHistoryList[
index]
.appointmentDate),
variant: 'caption3',
),
StarRating(
totalAverage: model
.appointHistoryList[
index]
.doctorRate
.toDouble(),
forceStars: true),
],
),
),
),
],
),
),
],
),
),
Expanded(
flex: 1,
child: Center(
child: Icon(
Icons.arrow_forward_ios,
size: 15,
),
),
)
],
),
SizedBox(
height: 5,
),
Divider(
height: 0.5,
color: Colors.grey[400],
)
],
),
),
),
),
),
Container(
margin: EdgeInsets.only(left: 10, right: 10, top: 15),
child: TextFields(
hintText: TranslationBase.of(context).subject,
controller: titleController,
fontSize: 13.5,
hintColor: Colors.black,
fontWeight: FontWeight.w600,
validator: (value) {
4 years ago
if (value.isEmpty)
return TranslationBase.of(context).emptySubject;
else
return null;
},
),
),
Container(
margin: EdgeInsets.only(left: 10, right: 10, top: 15),
child: TextFields(
hintText: TranslationBase.of(context).message,
fontSize: 13.5,
hintColor: Colors.black,
fontWeight: FontWeight.w600,
maxLines: 25,
minLines: 13,
controller: messageController,
validator: (value) {
4 years ago
if (value.isEmpty)
return TranslationBase.of(context).emptyMessage;
else
return null;
}),
),
InkWell(
onTap: () {
4 years ago
ImageOptions.showImageOptions(context, (String image,File file) {
setState(() {
images.add(image);
});
4 years ago
} );
},
child: Container(
margin: EdgeInsets.only(left: 10, right: 10, top: 15),
height: 50,
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(7),
color: Colors.white,
shape: BoxShape.rectangle,
),
child: Center(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.attach_file),
Texts(
TranslationBase.of(context).selectAttachment,
variant: 'bodyText',
textAlign: TextAlign.center,
),
],
),
),
),
),
...List.generate(
images.length,
(index) => Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Icon(FontAwesomeIcons.paperclip),
SizedBox(
width: 8,
),
Texts(
'image ${index + 1}.png',
),
],
),
InkWell(
onTap: () {
setState(() {
images.remove(images[index]);
});
},
child: Icon(
FontAwesomeIcons.trashAlt,
color: Colors.red[300],
))
],
),
)),
SizedBox(
height: 100,
),
],
),
),
),
),
bottomSheet: Container(
height: MediaQuery.of(context).size.height * 0.12,
width: double.infinity,
4 years ago
padding: EdgeInsets.all(15.0),
child: Center(
child: Container(
height: MediaQuery.of(context).size.height * 0.1,
4 years ago
child: SecondaryButton(
label: TranslationBase.of(context).send,
textColor: Colors.white,
4 years ago
disabled: (titleController.text.toString().isEmpty || messageController.text.toString().isEmpty|| messageType == MessageType.NON),
onTap: () {
final form = formKey.currentState;
4 years ago
if (form.validate())
if (messageType != MessageType.NON){
GifLoaderDialogUtils.showMyDialog(context);
model.sendCOCItem(
title: titleController.text,
attachment: images.length > 0 ? images[0] : "",
details: messageController.text,
4 years ago
cOCTypeName: getCOCName(),
4 years ago
appointHistory:messageType == MessageType.ComplaintOnAnAppointment
4 years ago
? appointHistory
: null)
.then((value) {
if (value) {
setState(() {
titleController.text = "";
messageController.text = "";
4 years ago
images = [];
});
4 years ago
setMessageType(MessageType.NON);
4 years ago
GifLoaderDialogUtils.hideDialog(context);
4 years ago
AppToast.showSuccessToast(
message: TranslationBase.of(context).yourFeedback);
} else {
AppToast.showErrorToast(message: model.error);
4 years ago
GifLoaderDialogUtils.hideDialog(context);
}
4 years ago
});}
else {
AppToast.showErrorToast(message: TranslationBase.of(context).selectPart);
}
},
),
),
),
),
),
);
}
4 years ago
String getCOCName() {
switch (messageType) {
case MessageType.ComplaintOnAnAppointment:
return "1";
break;
case MessageType.ComplaintWithoutAppointment:
return "2";
break;
case MessageType.Question:
return "3";
break;
case MessageType.Compliment:
return "4";
break;
case MessageType.Suggestion:
return "5";
break;
case MessageType.NON:
return "";
break;
}
return "";
}
// Show Dialog function
4 years ago
void confirmBox(FeedbackViewModel model) {
showDialog(
context: context,
child: FeedbackTypeDialog(
4 years ago
messageTypeDialog: messageType,
onValueSelected: (MessageType value) {
4 years ago
if (value == MessageType.ComplaintOnAnAppointment) {
4 years ago
GifLoaderDialogUtils.showMyDialog(context);
model.getPatentAppointmentHistory().then((value) {
4 years ago
GifLoaderDialogUtils.hideDialog(context);
setState(() {
appointHistory = null;
});
4 years ago
});
}
4 years ago
setMessageType(value);
},
));
}
}
class FeedbackTypeDialog extends StatefulWidget {
final Function(MessageType) onValueSelected;
4 years ago
final MessageType messageTypeDialog;
4 years ago
const FeedbackTypeDialog({Key key, this.onValueSelected, this.messageTypeDialog=MessageType.NON}) : super(key: key);
@override
State createState() => new FeedbackTypeDialogState();
}
class FeedbackTypeDialogState extends State<FeedbackTypeDialog> {
4 years ago
MessageType messageTypeDialog = MessageType.NON;
setMessageDialogType(MessageType messageType) {
setState(() {
messageTypeDialog = messageType;
});
}
@override
void initState() {
messageTypeDialog = widget.messageTypeDialog;
super.initState();
}
Widget build(BuildContext context) {
return BaseView<FeedbackViewModel>(
builder: (_, model, widge) => SimpleDialog(
title: Text(
TranslationBase.of(context).messageType,
textAlign: TextAlign.center,
),
children: <Widget>[
Container(
// padding: const EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
Divider(
height: 2.5,
color: Colors.grey[500],
),
Row(
children: <Widget>[
Expanded(
flex: 1,
child: InkWell(
onTap: () => setMessageDialogType(
MessageType.NON),
child: ListTile(
title: Texts(TranslationBase.of(context).notClassified),
leading: Radio(
value: MessageType.NON,
groupValue: messageTypeDialog,
activeColor: Theme.of(context).primaryColor,
onChanged: (MessageType value) =>
setMessageDialogType(value),
),
),
),
)
],
),
SizedBox(
height: 5.0,
),
Row(
children: <Widget>[
Expanded(
flex: 1,
child: InkWell(
4 years ago
onTap: () => setMessageDialogType(
MessageType.ComplaintOnAnAppointment),
child: ListTile(
title: Texts(TranslationBase.of(context).complainAppo),
leading: Radio(
value: MessageType.ComplaintOnAnAppointment,
4 years ago
groupValue: messageTypeDialog,
activeColor: Theme.of(context).primaryColor,
onChanged: (MessageType value) =>
4 years ago
setMessageDialogType(value),
),
),
),
)
],
),
SizedBox(
height: 5.0,
),
Row(
children: <Widget>[
Expanded(
flex: 1,
child: InkWell(
4 years ago
onTap: () => setMessageDialogType(
MessageType.ComplaintWithoutAppointment),
child: ListTile(
title: Texts(TranslationBase.of(context).complainWithoutAppo),
leading: Radio(
value: MessageType.ComplaintWithoutAppointment,
4 years ago
groupValue: messageTypeDialog,
activeColor: Theme.of(context).primaryColor,
onChanged: (MessageType value) =>
4 years ago
setMessageDialogType(value),
),
),
),
)
],
),
SizedBox(
height: 5.0,
),
Row(
children: <Widget>[
Expanded(
flex: 1,
child: InkWell(
onTap: () =>
4 years ago
setMessageDialogType(MessageType.Question),
child: ListTile(
title: Texts(TranslationBase.of(context).question),
leading: Radio(
value: MessageType.Question,
4 years ago
groupValue: messageTypeDialog,
activeColor: Theme.of(context).primaryColor,
onChanged: (MessageType value) =>
4 years ago
setMessageDialogType(value),
),
),
),
)
],
),
SizedBox(
height: 5.0,
),
Row(
children: <Widget>[
Expanded(
flex: 1,
child: InkWell(
onTap: () =>
4 years ago
setMessageDialogType(MessageType.Compliment),
child: ListTile(
title: Texts(TranslationBase.of(context).compliment),
leading: Radio(
value: MessageType.Compliment,
4 years ago
groupValue: messageTypeDialog,
activeColor: Theme.of(context).primaryColor,
onChanged: (MessageType value) =>
4 years ago
setMessageDialogType(value),
),
),
),
)
],
),
SizedBox(
height: 5.0,
),
Row(
children: <Widget>[
Expanded(
flex: 1,
child: InkWell(
onTap: () =>
4 years ago
setMessageDialogType(MessageType.Suggestion),
child: ListTile(
title: Texts(TranslationBase.of(context).suggestion),
leading: Radio(
value: MessageType.Suggestion,
4 years ago
groupValue: messageTypeDialog,
activeColor: Theme.of(context).primaryColor,
4 years ago
onChanged: (MessageType value) => setMessageDialogType(value),
),
),
),
)
],
),
SizedBox(
height: 5.0,
),
Divider(
height: 2.5,
color: Colors.grey[500],
),
SizedBox(
height: 5,
),
Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
flex: 1,
child: InkWell(
onTap: () {
Navigator.pop(context);
},
child: Padding(
padding: EdgeInsets.all(8.0),
child: Container(
child: Center(
child: Texts(
TranslationBase.of(context).cancel,
color: Theme.of(context).primaryColor,
),
),
),
),
),
),
Container(
width: 1,
height: 30,
color: Colors.grey[500],
),
Expanded(
flex: 1,
child: InkWell(
onTap: () {
4 years ago
widget.onValueSelected(messageTypeDialog);
Navigator.pop(context);
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: Texts(
TranslationBase.of(context).ok,
fontWeight: FontWeight.w400,
)),
),
)),
],
)
],
),
),
],
),
);
}
}