233 lines
8.5 KiB
Dart
233 lines
8.5 KiB
Dart
import 'package:fcs/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_search.dart';
|
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:share/share.dart';
|
|
|
|
import '../../pagination/paginator_listview.dart';
|
|
import 'invitation_create.dart';
|
|
|
|
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
|
|
void initState() {
|
|
context.read<CustomerModel>().loadPaginationCustomers();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var customerModel = Provider.of<CustomerModel>(context);
|
|
|
|
return LocalProgress(
|
|
inAsyncCall: _isLoading,
|
|
child: Scaffold(
|
|
appBar: LocalAppBar(
|
|
labelKey: "customer.list.title",
|
|
actions: [
|
|
IconButton(
|
|
icon: Icon(Icons.search, color: Colors.white),
|
|
onPressed: () => searchUser(context, onUserSelect: (u) {
|
|
_select(u);
|
|
})),
|
|
],
|
|
),
|
|
floatingActionButton: FloatingActionButton.extended(
|
|
onPressed: () {
|
|
Navigator.of(context).push(
|
|
CupertinoPageRoute(builder: (context) => InvitationCreate()));
|
|
},
|
|
icon: Icon(Icons.add),
|
|
label: LocalText(context, "invitation.new", color: Colors.white),
|
|
backgroundColor: primaryColor,
|
|
),
|
|
body: PaginatorListView<User>(
|
|
paginatorListener: customerModel.getCustomers!,
|
|
rowBuilder: (p) => _item(p),
|
|
color: primaryColor)),
|
|
);
|
|
}
|
|
|
|
Widget _item(User customer) {
|
|
return InkWell(
|
|
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: 8.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: 20, color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
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: 15.0, color: Colors.black),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 2.0),
|
|
child: new Text(
|
|
customer.getLastMessage,
|
|
style: new TextStyle(
|
|
fontSize: 15.0, color: Colors.grey),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
customer.status == user_invited_status
|
|
? Padding(
|
|
padding: const EdgeInsets.only(right: 10),
|
|
child: SizedBox(
|
|
height: 30,
|
|
child: TextButton(
|
|
onPressed: () => _share(customer),
|
|
style: TextButton.styleFrom(
|
|
padding: EdgeInsets.all(0),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(20.0),
|
|
side: BorderSide(
|
|
color: primaryColor.withOpacity(0.2)))),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
"Share",
|
|
style:
|
|
TextStyle(fontSize: 12, color: primaryColor),
|
|
),
|
|
Icon(Icons.share, color: primaryColor, size: 17),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
)
|
|
: Container(),
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 5),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
_status(customer.status ?? ""),
|
|
Text(
|
|
customer.getLastMessageTime,
|
|
style: TextStyle(color: Colors.grey, fontSize: 12),
|
|
),
|
|
getCount(customer),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget getCount(User customer) {
|
|
return 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, fontSize: 12)),
|
|
)
|
|
: Container();
|
|
}
|
|
|
|
Widget _status(String status) {
|
|
return user_requested_status == status || user_disabled_status == status
|
|
? Text(status, style: TextStyle(color: primaryColor, fontSize: 12))
|
|
: Container();
|
|
}
|
|
|
|
_select(User customer) {
|
|
Navigator.of(context).push(CupertinoPageRoute(
|
|
builder: (context) => CustomerEditor(customer: customer)));
|
|
}
|
|
|
|
_gotoMsg(User customer) {
|
|
MessageModel messageModel =
|
|
Provider.of<MessageModel>(context, listen: false);
|
|
messageModel.initQuery(customer.id);
|
|
Navigator.of(context)
|
|
.push(CupertinoPageRoute(
|
|
builder: (context) => MessageDetail(
|
|
receiverID: customer.id,
|
|
receiverName: customer.name,
|
|
messageModel: messageModel,
|
|
)))
|
|
.then((value) {
|
|
if (customer.fcsUnseenCount > 0) {
|
|
messageModel.seenMessages(customer.id ?? "", false);
|
|
}
|
|
});
|
|
if (customer.fcsUnseenCount > 0) {
|
|
messageModel.seenMessages(customer.id ?? "", false);
|
|
}
|
|
}
|
|
|
|
_share(User user) async {
|
|
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
|
|
String appUrl = mainModel.setting?.appUrl ?? "";
|
|
final RenderBox? box = context.findRenderObject() as RenderBox;
|
|
await Share.share(
|
|
"Join us on FCS Logistics App. Here is the link:\n $appUrl\n" +
|
|
user.share,
|
|
subject: "Invitation to FCS Logistics App",
|
|
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size);
|
|
}
|
|
}
|