2024-09-22 16:49:59 +06:30
|
|
|
import 'package:fcs/constants.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/domain/entities/package.dart';
|
|
|
|
|
import 'package:fcs/domain/entities/user.dart';
|
|
|
|
|
import 'package:fcs/domain/vo/message.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/pages/chat/model/message_model.dart';
|
|
|
|
|
import 'package:fcs/pages/customer/customer_editor.dart';
|
|
|
|
|
import 'package:fcs/pages/customer/model/customer_model.dart';
|
|
|
|
|
import 'package:fcs/pages/main/model/main_model.dart';
|
2020-10-19 14:02:34 +06:30
|
|
|
import 'package:fcs/pages/main/util.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/pages/package/model/package_model.dart';
|
|
|
|
|
import 'package:fcs/pages/package/package_info.dart';
|
|
|
|
|
import 'package:fcs/pages/profile/profile_page.dart';
|
2024-01-25 17:40:35 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
2020-10-12 03:34:05 +06:30
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-09-20 05:34:49 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
import 'bubble.dart';
|
|
|
|
|
|
|
|
|
|
class MessageDetail extends StatelessWidget {
|
2021-09-10 16:33:52 +06:30
|
|
|
final String? receiverName;
|
|
|
|
|
final String? receiverID;
|
2020-09-20 05:34:49 +06:30
|
|
|
final MessageModel messageModel;
|
|
|
|
|
final TextEditingController textEditingController = TextEditingController();
|
|
|
|
|
final ScrollController listScrollController = ScrollController();
|
|
|
|
|
|
|
|
|
|
MessageDetail(
|
2021-09-10 16:33:52 +06:30
|
|
|
{Key? key,
|
|
|
|
|
required this.messageModel,
|
|
|
|
|
this.receiverName,
|
|
|
|
|
this.receiverID})
|
2020-09-20 05:34:49 +06:30
|
|
|
: super(key: key) {
|
|
|
|
|
listScrollController.addListener(() {
|
|
|
|
|
if (listScrollController.offset >=
|
|
|
|
|
listScrollController.position.maxScrollExtent &&
|
|
|
|
|
!listScrollController.position.outOfRange) {
|
|
|
|
|
if (!messageModel.isEnded) messageModel.load();
|
|
|
|
|
}
|
|
|
|
|
if (listScrollController.offset <=
|
|
|
|
|
listScrollController.position.minScrollExtent &&
|
|
|
|
|
!listScrollController.position.outOfRange) {}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2021-09-10 16:33:52 +06:30
|
|
|
String userID = Provider.of<MessageModel>(context).user?.id ?? "";
|
2020-09-20 05:34:49 +06:30
|
|
|
|
|
|
|
|
return Scaffold(
|
2024-01-25 17:40:35 +06:30
|
|
|
appBar: LocalAppBar(
|
|
|
|
|
titleWidget: Text(receiverName ?? "FCS Team",
|
|
|
|
|
style: TextStyle(color: Colors.white, fontSize: 20))),
|
2020-09-20 05:34:49 +06:30
|
|
|
body: Padding(
|
|
|
|
|
padding: EdgeInsets.all(16.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ListView.builder(
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
var msg = messageModel.messages[index];
|
|
|
|
|
Message next;
|
|
|
|
|
bool showDate = false;
|
|
|
|
|
if (messageModel.messages.length > index + 1) {
|
|
|
|
|
next = messageModel.messages[index + 1];
|
|
|
|
|
if (!msg.sameDay(next)) {
|
|
|
|
|
showDate = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (messageModel.messages.length - 1 == index &&
|
|
|
|
|
messageModel.isEnded) {
|
|
|
|
|
showDate = true;
|
|
|
|
|
}
|
|
|
|
|
return buildBubble(
|
|
|
|
|
msg, userID, showDate, () => _viewDetail(context, msg));
|
|
|
|
|
},
|
|
|
|
|
itemCount: messageModel.messages.length,
|
|
|
|
|
reverse: true,
|
|
|
|
|
controller: listScrollController,
|
|
|
|
|
)),
|
|
|
|
|
buildInput(context),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget buildBubble(Message msg, String userID, bool showDate,
|
|
|
|
|
CallbackOnViewDetail callback) {
|
|
|
|
|
return Bubble(
|
2021-09-10 16:33:52 +06:30
|
|
|
message: msg.message ?? "",
|
|
|
|
|
date: msg.date!,
|
2020-09-20 05:34:49 +06:30
|
|
|
delivered: true,
|
|
|
|
|
sender: msg.senderName,
|
|
|
|
|
isMine: msg.senderID == userID || msg.receiverID == receiverID,
|
|
|
|
|
isCustomer: receiverID == null,
|
|
|
|
|
showDate: showDate,
|
|
|
|
|
isSystem: msg.messageType != null && msg.messageType != "",
|
|
|
|
|
callbackOnViewDetail: callback,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget buildInput(BuildContext context) {
|
|
|
|
|
return Container(
|
|
|
|
|
padding: EdgeInsets.only(top: 3),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Flexible(
|
|
|
|
|
child: Container(
|
|
|
|
|
child: TextField(
|
|
|
|
|
onSubmitted: (value) {
|
2021-09-10 16:33:52 +06:30
|
|
|
Provider.of<MessageModel>(context, listen: false).sendMessage(
|
|
|
|
|
textEditingController.text, receiverID ?? "");
|
2020-09-20 05:34:49 +06:30
|
|
|
textEditingController.text = "";
|
|
|
|
|
},
|
|
|
|
|
style: TextStyle(color: primaryColor, fontSize: 15.0),
|
|
|
|
|
maxLines: 10,
|
|
|
|
|
minLines: 1,
|
|
|
|
|
keyboardType: TextInputType.multiline,
|
|
|
|
|
controller: textEditingController,
|
2024-01-25 17:40:35 +06:30
|
|
|
cursorColor: primaryColor,
|
2020-09-20 05:34:49 +06:30
|
|
|
decoration: InputDecoration(
|
|
|
|
|
focusedBorder: const OutlineInputBorder(
|
|
|
|
|
borderSide:
|
|
|
|
|
const BorderSide(color: primaryColor, width: 1.0),
|
|
|
|
|
),
|
|
|
|
|
border: new OutlineInputBorder(
|
2024-01-25 17:40:35 +06:30
|
|
|
borderRadius:
|
|
|
|
|
const BorderRadius.all(const Radius.circular(5.0)),
|
2020-09-20 05:34:49 +06:30
|
|
|
),
|
|
|
|
|
hintText: getLocalString(context, "message.hint.input"),
|
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// Button send message
|
|
|
|
|
Material(
|
|
|
|
|
child: Container(
|
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 8.0),
|
|
|
|
|
child: IconButton(
|
|
|
|
|
icon: Icon(Icons.send),
|
|
|
|
|
onPressed: () {
|
2021-09-10 16:33:52 +06:30
|
|
|
Provider.of<MessageModel>(context, listen: false).sendMessage(
|
|
|
|
|
textEditingController.text, receiverID ?? "");
|
2020-09-20 05:34:49 +06:30
|
|
|
textEditingController.text = "";
|
|
|
|
|
},
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
decoration: BoxDecoration(
|
2021-09-10 16:33:52 +06:30
|
|
|
border:
|
|
|
|
|
Border(top: BorderSide(color: Colors.grey.shade700, width: 0.5)),
|
2020-09-20 05:34:49 +06:30
|
|
|
color: Colors.white),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_viewDetail(BuildContext context, Message message) async {
|
|
|
|
|
if (message.messageType == message_type_package &&
|
|
|
|
|
message.messageID != null &&
|
|
|
|
|
message.messageID != "") {
|
|
|
|
|
PackageModel packageModel =
|
|
|
|
|
Provider.of<PackageModel>(context, listen: false);
|
2021-09-11 08:27:27 +06:30
|
|
|
Package? p = await packageModel.getPackage(message.messageID!);
|
2020-10-12 03:34:05 +06:30
|
|
|
if (p == null) return;
|
2020-10-14 13:54:42 +06:30
|
|
|
Navigator.push<bool>(context,
|
|
|
|
|
CupertinoPageRoute(builder: (context) => PackageInfo(package: p)));
|
2020-09-20 05:34:49 +06:30
|
|
|
}
|
2020-09-20 08:06:14 +06:30
|
|
|
if (message.messageType == message_type_profile &&
|
|
|
|
|
message.messageID != null &&
|
|
|
|
|
message.messageID != "") {
|
|
|
|
|
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
|
|
|
|
|
|
2021-09-10 16:33:52 +06:30
|
|
|
if (mainModel.user?.isCustomer() ?? false) {
|
2020-10-14 13:54:42 +06:30
|
|
|
Navigator.push<bool>(
|
|
|
|
|
context, CupertinoPageRoute(builder: (context) => Profile()));
|
2020-09-20 08:06:14 +06:30
|
|
|
} else {
|
|
|
|
|
CustomerModel customerModel =
|
|
|
|
|
Provider.of<CustomerModel>(context, listen: false);
|
2025-03-21 18:19:52 +06:30
|
|
|
User? user = await customerModel.getUser(message.messageID);
|
2020-10-14 13:54:42 +06:30
|
|
|
Navigator.of(context).push(CupertinoPageRoute(
|
|
|
|
|
builder: (context) => CustomerEditor(customer: user)));
|
2020-09-20 08:06:14 +06:30
|
|
|
}
|
|
|
|
|
}
|
2020-09-20 05:34:49 +06:30
|
|
|
}
|
|
|
|
|
}
|