2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/domain/constants.dart';
|
|
|
|
|
import 'package:fcs/domain/entities/user.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/pages/chat/message_detail.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';
|
|
|
|
|
import 'package:fcs/pages/user_search/user_serach.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
2020-09-18 04:04:21 +06:30
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-09-11 16:14:36 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
2020-09-18 04:04:21 +06:30
|
|
|
import 'package:share/share.dart';
|
2020-09-11 16:14:36 +06:30
|
|
|
|
2020-09-17 06:02:48 +06:30
|
|
|
import 'invitation_create.dart';
|
2020-09-11 16:14:36 +06:30
|
|
|
|
|
|
|
|
class CustomerList extends StatefulWidget {
|
|
|
|
|
@override
|
|
|
|
|
_CustomerListState createState() => _CustomerListState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _CustomerListState extends State<CustomerList> {
|
|
|
|
|
var dateFormatter = new DateFormat('dd MMM yyyy - hh:mm:ss a');
|
|
|
|
|
final double dotSize = 15.0;
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
var customerModel = Provider.of<CustomerModel>(context);
|
|
|
|
|
|
|
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
leading: new IconButton(
|
2020-09-18 04:04:21 +06:30
|
|
|
icon: new Icon(CupertinoIcons.back),
|
2020-09-11 16:14:36 +06:30
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
|
),
|
|
|
|
|
actions: <Widget>[
|
2020-09-18 21:33:41 +06:30
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(Icons.search, color: Colors.white),
|
2021-01-10 15:56:27 +06:30
|
|
|
onPressed: () => searchUser(context, onUserSelect: (u) {
|
2020-09-18 21:33:41 +06:30
|
|
|
_select(u);
|
|
|
|
|
})),
|
2020-09-11 16:14:36 +06:30
|
|
|
],
|
|
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
title: LocalText(
|
|
|
|
|
context,
|
2020-09-18 04:04:21 +06:30
|
|
|
"customer.list.title",
|
2020-09-11 16:14:36 +06:30
|
|
|
fontSize: 20,
|
2020-09-18 04:04:21 +06:30
|
|
|
color: Colors.white,
|
2020-09-11 16:14:36 +06:30
|
|
|
),
|
|
|
|
|
),
|
2020-09-17 06:02:48 +06:30
|
|
|
floatingActionButton: FloatingActionButton.extended(
|
|
|
|
|
onPressed: () {
|
2020-10-17 01:40:24 +06:30
|
|
|
Navigator.of(context).push(
|
|
|
|
|
CupertinoPageRoute(builder: (context) => InvitationCreate()));
|
2020-09-17 06:02:48 +06:30
|
|
|
},
|
|
|
|
|
icon: Icon(Icons.add),
|
|
|
|
|
label: LocalText(context, "invitation.new", color: Colors.white),
|
|
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
),
|
2020-09-13 21:49:39 +06:30
|
|
|
body: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ListView.separated(
|
|
|
|
|
separatorBuilder: (context, index) => Divider(
|
2020-09-20 05:34:49 +06:30
|
|
|
color: Colors.grey,
|
2020-09-13 21:49:39 +06:30
|
|
|
),
|
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemCount: customerModel.customers.length,
|
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
|
User customer = customerModel.customers[index];
|
|
|
|
|
return _item(customer);
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _item(User customer) {
|
2020-09-18 04:04:21 +06:30
|
|
|
return InkWell(
|
2020-09-20 05:34:49 +06:30
|
|
|
onTap: () => _gotoMsg(customer),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 12.0, right: 12),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Expanded(
|
|
|
|
|
child: new Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 2.0),
|
|
|
|
|
child: new Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
InkWell(
|
|
|
|
|
onTap: () => _select(customer),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(5.0),
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
|
left: 10.0, right: 10, top: 6, bottom: 6),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
borderRadius:
|
|
|
|
|
BorderRadius.all(Radius.circular(35.0))),
|
|
|
|
|
child: Text(
|
|
|
|
|
customer.initial,
|
|
|
|
|
style: TextStyle(fontSize: 30, color: Colors.white),
|
2020-09-18 04:04:21 +06:30
|
|
|
),
|
2020-09-11 16:14:36 +06:30
|
|
|
),
|
2020-09-20 05:34:49 +06:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
new Expanded(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 8.0),
|
|
|
|
|
child: new Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 2.0),
|
|
|
|
|
child: new Text(
|
|
|
|
|
customer.name,
|
|
|
|
|
style: new TextStyle(
|
|
|
|
|
fontSize: 20.0, color: primaryColor),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 2.0),
|
|
|
|
|
child: new Text(
|
|
|
|
|
customer.getLastMessage,
|
|
|
|
|
style: new TextStyle(
|
|
|
|
|
fontSize: 15.0, color: Colors.grey),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
2020-09-18 04:04:21 +06:30
|
|
|
),
|
2020-09-20 05:34:49 +06:30
|
|
|
],
|
|
|
|
|
),
|
2020-09-13 21:49:39 +06:30
|
|
|
),
|
2020-09-18 04:04:21 +06:30
|
|
|
),
|
2020-10-17 01:40:24 +06:30
|
|
|
customer.status == user_invited_status
|
|
|
|
|
? Padding(
|
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
|
child: FlatButton(
|
|
|
|
|
onPressed: () => _share(customer),
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(18.0),
|
|
|
|
|
side: BorderSide(color: primaryColor)),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
"Share",
|
|
|
|
|
style: TextStyle(fontSize: 12),
|
|
|
|
|
),
|
|
|
|
|
Icon(Icons.share, color: primaryColor),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Container(),
|
2020-09-20 05:34:49 +06:30
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(right: 5),
|
|
|
|
|
child: _status(customer.status),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(right: 5),
|
|
|
|
|
child: Text(customer.getLastMessageTime),
|
|
|
|
|
),
|
|
|
|
|
getCount(customer),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2020-09-18 04:04:21 +06:30
|
|
|
),
|
2020-09-13 21:49:39 +06:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-20 05:34:49 +06:30
|
|
|
Widget getCount(User customer) {
|
|
|
|
|
return customer.fcsUnseenCount != null && customer.fcsUnseenCount > 0
|
|
|
|
|
? Container(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
decoration:
|
|
|
|
|
BoxDecoration(shape: BoxShape.circle, color: secondaryColor),
|
|
|
|
|
child: Text(customer.getFcsUnseenCount,
|
|
|
|
|
style: TextStyle(color: Colors.white)),
|
|
|
|
|
)
|
|
|
|
|
: Container();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-13 21:49:39 +06:30
|
|
|
Widget _status(String status) {
|
2020-10-17 01:40:24 +06:30
|
|
|
return user_requested_status == status || user_disabled_status == status
|
2020-09-18 04:04:21 +06:30
|
|
|
? Text(status, style: TextStyle(color: primaryColor, fontSize: 14))
|
|
|
|
|
: Container();
|
2020-09-11 16:14:36 +06:30
|
|
|
}
|
2020-09-13 21:49:39 +06:30
|
|
|
|
|
|
|
|
_select(User customer) {
|
2020-10-17 01:40:24 +06:30
|
|
|
Navigator.of(context).push(CupertinoPageRoute(
|
|
|
|
|
builder: (context) => CustomerEditor(customer: customer)));
|
2020-09-13 21:49:39 +06:30
|
|
|
}
|
|
|
|
|
|
2020-09-20 05:34:49 +06:30
|
|
|
_gotoMsg(User customer) {
|
|
|
|
|
MessageModel messageModel =
|
|
|
|
|
Provider.of<MessageModel>(context, listen: false);
|
|
|
|
|
messageModel.initQuery(customer.id);
|
|
|
|
|
Navigator.of(context)
|
2020-10-17 01:40:24 +06:30
|
|
|
.push(CupertinoPageRoute(
|
|
|
|
|
builder: (context) => MessageDetail(
|
|
|
|
|
receiverID: customer.id,
|
|
|
|
|
receiverName: customer.name,
|
|
|
|
|
messageModel: messageModel,
|
|
|
|
|
)))
|
2020-09-20 05:34:49 +06:30
|
|
|
.then((value) {
|
|
|
|
|
if (customer.fcsUnseenCount > 0) {
|
|
|
|
|
messageModel.seenMessages(customer.id, false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (customer.fcsUnseenCount > 0) {
|
|
|
|
|
messageModel.seenMessages(customer.id, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 04:04:21 +06:30
|
|
|
_share(User user) async {
|
|
|
|
|
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
|
|
|
|
|
String appUrl = mainModel.setting.appUrl;
|
2021-09-10 12:00:08 +06:30
|
|
|
final RenderBox? box = context.findRenderObject() as RenderBox;
|
2020-09-18 04:04:21 +06:30
|
|
|
await Share.share(
|
|
|
|
|
"Join us on FCS Logistics App. Here is the link:\n $appUrl\n" +
|
|
|
|
|
user.share,
|
|
|
|
|
subject: "Invitation to FCS Logistics App",
|
2021-09-10 12:00:08 +06:30
|
|
|
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size);
|
2020-09-13 21:49:39 +06:30
|
|
|
}
|
2020-09-11 16:14:36 +06:30
|
|
|
}
|