This commit is contained in:
Sai Naw Wun
2020-10-07 02:33:06 +06:30
parent 01a2798a74
commit 65dda16fe6
475 changed files with 1543 additions and 90780 deletions

View File

@@ -0,0 +1,120 @@
import 'package:fcs/domain/entities/user.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/customer/model/customer_model.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/display_text.dart';
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
typedef void FindCallBack();
class CustomerEditor extends StatefulWidget {
final User customer;
const CustomerEditor({this.customer});
@override
_CustomerEditorState createState() => _CustomerEditorState();
}
class _CustomerEditorState extends State<CustomerEditor> {
bool _isLoading = false;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
var phoneNumberBox = Row(
children: <Widget>[
Expanded(
child: DisplayText(
text: widget.customer.phoneNumber,
labelText: getLocalString(context, "customer.phone"),
iconData: Icons.phone,
)),
IconButton(
icon: Icon(Icons.open_in_new, color: primaryColor),
onPressed: () => call(context, widget.customer.phoneNumber)),
],
);
return LocalProgress(
inAsyncCall: _isLoading,
child: SafeArea(
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
shadowColor: Colors.transparent,
centerTitle: true,
leading: new IconButton(
icon: new Icon(
Icons.close,
color: primaryColor,
size: 30,
),
onPressed: () => Navigator.of(context).pop(),
),
title: Text(
widget.customer.name,
style: TextStyle(
fontSize: 20,
color: primaryColor,
),
),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
children: <Widget>[
phoneNumberBox,
DisplayText(
text: widget.customer.fcsID,
labelText: getLocalString(context, "customer.fcs.id"),
icon: FcsIDIcon(),
),
DisplayText(
text: widget.customer.status,
labelText: getLocalString(context, "customer.status"),
iconData: Icons.add_alarm,
),
SizedBox(
height: 20,
),
widget.customer.requested
? fcsButton(
context,
getLocalString(
context, "customer.invitation.request.confirm"),
callack: _add)
: Container()
],
),
),
),
));
}
_add() async {
showConfirmDialog(context, "customer.invitation.request.confirm", () async {
setState(() {
_isLoading = true;
});
if (widget.customer == null) return;
CustomerModel customerModel =
Provider.of<CustomerModel>(context, listen: false);
try {
await customerModel.acceptRequest(widget.customer.id);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
});
}
}

View File

@@ -0,0 +1,240 @@
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/bottom_up_page_route.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:flutter_icons/flutter_icons.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:share/share.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
Widget build(BuildContext context) {
var customerModel = Provider.of<CustomerModel>(context);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
icon: new Icon(CupertinoIcons.back),
onPressed: () => Navigator.of(context).pop(),
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.search, color: Colors.white),
onPressed: () => searchUser(context, callbackUserSelect: (u) {
_select(u);
})),
],
backgroundColor: primaryColor,
title: LocalText(
context,
"customer.list.title",
fontSize: 20,
color: Colors.white,
),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
Navigator.of(context).push(BottomUpPageRoute(InvitationCreate()));
},
icon: Icon(Icons.add),
label: LocalText(context, "invitation.new", color: Colors.white),
backgroundColor: primaryColor,
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: ListView.separated(
separatorBuilder: (context, index) => Divider(
color: Colors.grey,
),
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) {
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: 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),
),
),
),
),
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),
),
),
],
),
),
),
],
),
),
),
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),
customer.status == user_invited_status
? 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(),
],
),
],
),
),
);
}
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();
}
Widget _status(String status) {
return user_requested_status == status
? Text(status, style: TextStyle(color: primaryColor, fontSize: 14))
: Container();
}
_select(User customer) {
Navigator.of(context)
.push(BottomUpPageRoute(CustomerEditor(customer: customer)));
}
_gotoMsg(User customer) {
MessageModel messageModel =
Provider.of<MessageModel>(context, listen: false);
messageModel.initQuery(customer.id);
Navigator.of(context)
.push(BottomUpPageRoute(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();
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);
}
}

View File

@@ -0,0 +1,159 @@
import 'package:country_code_picker/country_code_picker.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/customer/model/customer_model.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class InvitationCreate extends StatefulWidget {
@override
_InvitationCreateState createState() => _InvitationCreateState();
}
class _InvitationCreateState extends State<InvitationCreate> {
TextEditingController _nameController = new TextEditingController();
TextEditingController _phoneController = new TextEditingController();
bool _isLoading = false;
String dialCode;
@override
void initState() {
super.initState();
dialCode = "+95";
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
shadowColor: Colors.transparent,
centerTitle: true,
leading: new IconButton(
icon: new Icon(
Icons.close,
color: primaryColor,
),
onPressed: () => Navigator.of(context).pop(),
),
title: LocalText(
context,
"invitation.new",
fontSize: 20,
color: primaryColor,
),
),
body: Container(
padding: EdgeInsets.all(18),
child: ListView(
children: <Widget>[
fcsInput(getLocalString(context, "customer.name"), Icons.person,
controller: _nameController, autoFocus: false),
SizedBox(height: 10),
Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
Icons.phone,
color: primaryColor,
),
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey[400], width: 1),
borderRadius: BorderRadius.all(Radius.circular(12.0))),
child: CountryCodePicker(
onChanged: _countryChange,
initialSelection: dialCode,
countryFilter: ['+95', '+1'],
showCountryOnly: false,
showOnlyCountryWhenClosed: false,
alignLeft: false,
textStyle: TextStyle(
fontSize: 16,
),
),
),
SizedBox(
width: 10,
),
Flexible(
child: Container(
padding: EdgeInsets.only(top: 10, bottom: 10),
child: TextFormField(
controller: _phoneController,
cursorColor: primaryColor,
textAlign: TextAlign.left,
keyboardType: TextInputType.phone,
style: TextStyle(
fontSize: 18,
),
decoration: InputDecoration(
fillColor: Colors.white,
labelText: getLocalString(context, "customer.phone"),
labelStyle:
TextStyle(fontSize: 16, color: Colors.grey),
filled: true,
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.grey, width: 1.0)),
),
),
),
),
],
),
SizedBox(height: 20),
fcsButton(context, getLocalString(context, "invite.btn"),
callack: _invite),
],
),
),
),
);
}
_countryChange(CountryCode countryCode) {
setState(() {
dialCode = countryCode.dialCode;
});
}
_invite() async {
String userName = _nameController.text;
String phoneNumber = dialCode + _phoneController.text;
if (userName == null ||
userName == "" ||
phoneNumber == null ||
phoneNumber == "") {
showMsgDialog(context, "Error", "Invalid name or phone number");
return;
}
setState(() {
_isLoading = true;
});
try {
CustomerModel customerModel =
Provider.of<CustomerModel>(context, listen: false);
await customerModel.inviteUser(userName, phoneNumber);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
}

View File

@@ -0,0 +1,100 @@
import 'package:fcs/domain/entities/user.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/customer/model/customer_model.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/display_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
typedef void FindCallBack();
class InvitationEditor extends StatefulWidget {
final User customer;
const InvitationEditor({this.customer});
@override
_InvitationEditorState createState() => _InvitationEditorState();
}
class _InvitationEditorState extends State<InvitationEditor> {
bool _isLoading = false;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
var phoneNumberBox = Row(
children: <Widget>[
Expanded(
child: DisplayText(
text: widget.customer.phoneNumber,
labelText: getLocalString(context, "customer.phone"),
iconData: Icons.phone,
)),
IconButton(
icon: Icon(Icons.open_in_new, color: primaryColor),
onPressed: () => call(context, widget.customer.phoneNumber)),
],
);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
shadowColor: Colors.transparent,
centerTitle: true,
leading: new IconButton(
icon: new Icon(
Icons.close,
color: primaryColor,
size: 30,
),
onPressed: () => Navigator.of(context).pop(),
),
title: Text(
widget.customer.name,
style: TextStyle(fontSize: 20, color: primaryColor),
),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Expanded(
child: ListView(
children: [phoneNumberBox],
),
),
fcsButton(context, getLocalString(context, "btn.delete"),
callack: _delete)
],
),
),
));
}
_delete() async {
showConfirmDialog(context, "invitation.confirm.delete", () async {
setState(() {
_isLoading = true;
});
if (widget.customer == null) return;
CustomerModel customerModel =
Provider.of<CustomerModel>(context, listen: false);
try {
await customerModel.deleteInvite(widget.customer.phoneNumber);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
});
}
}

View File

@@ -0,0 +1,98 @@
import 'dart:async';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fcs/data/services/services.dart';
import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/user.dart';
import 'package:fcs/pages/main/model/base_model.dart';
import 'package:logging/logging.dart';
class CustomerModel extends BaseModel {
final log = Logger('CustomerModel');
List<User> customers = [];
List<User> invitations = [];
StreamSubscription<QuerySnapshot> customerListener;
StreamSubscription<QuerySnapshot> invitationListener;
@override
void privilegeChanged() {
super.privilegeChanged();
_loadCustomer();
_loadInvitations();
}
@override
logout() async {
if (customerListener != null) customerListener.cancel();
if (invitationListener != null) invitationListener.cancel();
customers = [];
invitations = [];
}
Future<void> inviteUser(String userName, String phoneNumber) {
return Services.instance.userService.inviteUser(userName, phoneNumber);
}
Future<void> deleteInvite(String phoneNumber) {
return Services.instance.userService.deleteInvite(phoneNumber);
}
Future<void> acceptRequest(String userID) {
return Services.instance.userService.acceptRequest(userID);
}
Future<void> _loadCustomer() async {
if (user == null || !user.hasCustomers()) return;
try {
if (customerListener != null) customerListener.cancel();
customerListener = Firestore.instance
.collection("/$user_collection")
.where("is_sys_admin", isEqualTo: false)
.orderBy("message_time", descending: true)
.snapshots()
.listen((QuerySnapshot snapshot) {
customers.clear();
customers = snapshot.documents.map((documentSnapshot) {
var user =
User.fromMap(documentSnapshot.data, documentSnapshot.documentID);
return user;
}).toList();
notifyListeners();
});
} catch (e) {
log.warning("error:$e");
}
}
Future<void> _loadInvitations() async {
if (user == null || !user.hasCustomers()) return;
try {
if (invitationListener != null) invitationListener.cancel();
invitationListener = Firestore.instance
.collection("/$invitations_collection")
.snapshots()
.listen((QuerySnapshot snapshot) {
invitations.clear();
invitations = snapshot.documents.map((documentSnapshot) {
var user =
User.fromMap(documentSnapshot.data, documentSnapshot.documentID);
return user;
}).toList();
notifyListeners();
});
} catch (e) {
log.warning("error:$e");
}
}
Future<User> getUser(String id) async {
String path = "/$user_collection";
var snap = await Firestore.instance.collection(path).document(id).get();
return User.fromMap(snap.data, snap.documentID);
}
}