Merge remote-tracking branch 'upstream/master'

This commit is contained in:
PhyoThandar
2020-06-02 14:59:05 +06:30
5 changed files with 297 additions and 48 deletions

View File

@@ -1,5 +1,7 @@
import 'package:fcs/model/shipment_model.dart';
import 'package:fcs/model_fcs/message_model.dart';
import 'package:fcs/model_fcs/package_model.dart';
import 'package:fcs/vo/message.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
@@ -69,6 +71,7 @@ class _AppState extends State<App> {
final ShipmentRateModel shipmentRateModel = new ShipmentRateModel();
final ShipmentModel shipmentModel = new ShipmentModel();
final PackageModel packageModel=new PackageModel();
final MessageModel messageModel=new MessageModel();
final InvoiceModel invoiceModel = new InvoiceModel();
final CustomerModel customerModel = new CustomerModel();
@@ -105,6 +108,7 @@ class _AppState extends State<App> {
..addModel(shipmentRateModel)
..addModel(shipmentModel)
..addModel(packageModel)
..addModel(messageModel)
..addModel(shipmentRateModel)
..addModel(invoiceModel)
..addModel(customerModel);
@@ -160,6 +164,7 @@ class _AppState extends State<App> {
ChangeNotifierProvider(builder: (context) => shipmentRateModel),
ChangeNotifierProvider(builder: (context) => shipmentModel),
ChangeNotifierProvider(builder: (context) => packageModel),
ChangeNotifierProvider(builder: (context) => messageModel),
ChangeNotifierProvider(builder: (context) => invoiceModel),
ChangeNotifierProvider(builder: (context) => customerModel),
ChangeNotifierProvider(

View File

@@ -0,0 +1,101 @@
import 'dart:async';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fcs/model/base_model.dart';
import 'package:fcs/vo/message.dart';
import 'package:fcs/vo/package.dart';
import 'package:logging/logging.dart';
class MessageModel extends BaseModel {
final log = Logger('MessageModel');
StreamSubscription<QuerySnapshot> listener;
List<Message> messages = [
Message(
senderName: "FCS System",
receiverName: "Online Buyer",
date: DateTime(2020, 6, 1, 1, 1, 1),
message:
"Hi Online Buyer, we received your goods. Please see in 'A202-3 #1'",
),
Message(
senderName: "FCS System",
receiverName: "Online Buyer",
date: DateTime(2020, 6, 1, 1, 5, 1),
message: "Thank you. Will see the photos and check.",
isMe: false),
Message(
senderName: "FCS System",
receiverName: "Online Buyer",
date: DateTime(2020, 6, 1, 2, 1, 1),
message:
"Hi Online Buyer, we successfully processed your goods and ready for payment. Please see in 'INV202005010387'",
),
Message(
senderName: "FCS System",
receiverName: "Online Buyer",
date: DateTime(2020, 6, 1, 2, 10, 1),
message:
"Hi Online Buyer, we have confirmed your payment and ready to ship your packages.",
),
Message(
senderName: "FCS System",
receiverName: "Shipper",
date: DateTime(2020, 6, 1, 1, 1, 1),
message:
"Hi Online Buyer, we received your goods. Please see in 'A202-3 #1'",
),
Message(
senderName: "FCS System",
receiverName: "Shipper",
date: DateTime(2020, 6, 1, 2, 1, 1),
message:
"Hi Online Buyer, we successfully processed your goods and ready for payment. Please see in 'INV202005010387'",
),
Message(
senderName: "FCS System",
receiverName: "Shipper",
date: DateTime(2020, 6, 1, 2, 10, 1),
message:
"Hi Online Buyer, we have confirmed your payment and ready to ship your packages.",
),
];
List<Message> get lastMessage {
return [messages[2], messages[5]];
}
List<Message> getMessage(String receiver) {
return messages.where((e) => e.receiverName == receiver).toList();
}
// List<Package> get completed {
// return packages.where((e) => e.status == "Delivered").toList()
// ..sort((e1, e2) {
// return e2.packageNumber.compareTo(e1.packageNumber);
// });
// }
// List<Package> get upcoming {
// return packages
// .where((e) =>
// e.status == "Processing" ||
// e.status == "Received" ||
// e.status == "Ready to ship")
// .toList()
// ..sort((e1, e2) {
// return e2.packageNumber.compareTo(e1.packageNumber);
// });
// }
void initUser(user) {
super.initUser(user);
}
@override
logout() async {
if (listener != null) await listener.cancel();
messages = [];
}
}

View File

@@ -0,0 +1,140 @@
import 'package:fcs/model_fcs/message_model.dart';
import 'package:fcs/theme/theme.dart';
import 'package:fcs/vo/message.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
class Bubble extends StatelessWidget {
Bubble({this.message, this.time, this.delivered, this.isMe});
final String message, time;
final delivered, isMe;
@override
Widget build(BuildContext context) {
final bg = isMe ? Colors.white : Colors.greenAccent.shade100;
final align = isMe ? CrossAxisAlignment.start : CrossAxisAlignment.end;
final icon = delivered ? Icons.done_all : Icons.done;
final radius = isMe
? BorderRadius.only(
topRight: Radius.circular(5.0),
bottomLeft: Radius.circular(10.0),
bottomRight: Radius.circular(5.0),
)
: BorderRadius.only(
topLeft: Radius.circular(5.0),
bottomLeft: Radius.circular(5.0),
bottomRight: Radius.circular(10.0),
);
return Column(
crossAxisAlignment: align,
children: <Widget>[
Container(
margin: const EdgeInsets.all(3.0),
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: .5,
spreadRadius: 1.0,
color: Colors.black.withOpacity(.12))
],
color: bg,
borderRadius: radius,
),
child: Stack(
children: <Widget>[
Padding(
padding: EdgeInsets.only(right: 48.0),
child: Text(message),
),
Positioned(
bottom: 0.0,
right: 0.0,
child: Row(
children: <Widget>[
Text(time,
style: TextStyle(
color: Colors.black38,
fontSize: 10.0,
)),
SizedBox(width: 3.0),
Icon(
icon,
size: 12.0,
color: Colors.black38,
)
],
),
)
],
),
)
],
);
}
}
class MessageDetail extends StatelessWidget {
final Message msg;
const MessageDetail({Key key, this.msg}) : super(key: key);
@override
Widget build(BuildContext context) {
DateFormat dateFormat=DateFormat("HH:mm");
MessageModel messageModel = Provider.of<MessageModel>(context);
List<Message> messages = messageModel.getMessage(msg.receiverName);
List<Bubble> bubbles = messages
.map((e) => Bubble(
message: e.message,
time: dateFormat.format(e.date),
delivered: true,
isMe: e.isMe != null ? e.isMe : true))
.toList();
return Scaffold(
appBar: AppBar(
backgroundColor: primaryColor,
elevation: .9,
title: Text(
msg.receiverName,
),
actions: <Widget>[],
),
body: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: bubbles,
// children: <Widget>[
// Bubble(
// message: 'Hi there, this is a message',
// time: '12:00',
// delivered: true,
// isMe: false,
// ),
// Bubble(
// message: 'Whatsapp like bubble talk',
// time: '12:01',
// delivered: true,
// isMe: true,
// ),
// Bubble(
// message: 'Nice one, Flutter is awesome',
// time: '12:00',
// delivered: true,
// isMe: true,
// ),
// Bubble(
// message: 'I\'ve told you so dude!',
// time: '12:00',
// delivered: true,
// isMe: false,
// ),
// ],
),
),
);
}
}

View File

@@ -1,3 +1,7 @@
import 'package:fcs/model_fcs/message_model.dart';
import 'package:fcs/pages/message_detail.dart';
import 'package:fcs/vo/message.dart';
import 'package:fcs/widget/bottom_up_page_route.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
@@ -16,15 +20,14 @@ class NotificationList extends StatefulWidget {
class _NotificationListState extends State<NotificationList> {
var timeFormatter = new DateFormat('KK:mm a');
var dateFormatter = new DateFormat('dd MMM yyyy');
final double dotSize = 15.0;
final double dotSize = 25.0;
int _selectedIndex = 0;
bool _isLoading = false;
bool _isClicked = false;
@override
Widget build(BuildContext context) {
NotificationModel notificationModel =
Provider.of<NotificationModel>(context);
MessageModel messageModel = Provider.of<MessageModel>(context);
return LocalProgress(
inAsyncCall: _isLoading,
@@ -40,7 +43,7 @@ class _NotificationListState extends State<NotificationList> {
backgroundColor: primaryColor,
title: LocalText(
context,
'noti.list.title',
'message.title',
fontSize: 20,
color: Colors.white,
),
@@ -50,15 +53,15 @@ class _NotificationListState extends State<NotificationList> {
color: Colors.black,
),
scrollDirection: Axis.vertical,
padding: EdgeInsets.only(left: 15, right: 15, top: 15),
padding: EdgeInsets.only(top: 5),
shrinkWrap: true,
itemCount: notificationModel.notifications.length,
itemCount: messageModel.lastMessage.length,
itemBuilder: (BuildContext context, int index) {
Noti.Notification noti = notificationModel.notifications[index];
Message msg = messageModel.lastMessage[index];
return Stack(
children: <Widget>[
InkWell(
onTap: () => _display(noti),
onTap: () => _display(msg),
child: Row(
children: <Widget>[
Expanded(
@@ -68,8 +71,12 @@ class _NotificationListState extends State<NotificationList> {
children: <Widget>[
new Padding(
padding: new EdgeInsets.symmetric(
horizontal: 32.0 - dotSize / 2),
child: Icon(Icons.message,color: primaryColor,),
horizontal: 22.0 - dotSize / 2),
child: Icon(
Icons.account_circle,
color: primaryColor,
size: 60,
),
),
new Expanded(
child: new Column(
@@ -77,53 +84,32 @@ class _NotificationListState extends State<NotificationList> {
CrossAxisAlignment.start,
children: <Widget>[
new Text(
noti.getDesc,
msg.receiverName,
style: new TextStyle(
fontSize: 15.0,
color: primaryColor),
),
noti.marketPlace == null
? Container()
: Padding(
padding: const EdgeInsets.only(
top: 8.0),
child: new Text(
noti.marketPlace,
style: new TextStyle(
fontSize: 15.0,
color: primaryColor),
],
),
),
],
),
),
),
Padding(
padding:
const EdgeInsets.only(top: 8.0),
child: new Text(
noti.status == null
? ""
: noti.status,
style: new TextStyle(
fontSize: 15.0,
color: Colors.grey),
),
),
],
),
),
],
),
),
),
Column(
padding: const EdgeInsets.only(right: 18.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(timeFormatter.format(noti.time)),
child: Text(timeFormatter.format(msg.date)),
),
noti.fromToday()
msg.fromToday()
? Container()
: Text(dateFormatter.format(noti.time)),
: Text(dateFormatter.format(msg.date)),
],
),
)
],
),
@@ -135,5 +121,8 @@ class _NotificationListState extends State<NotificationList> {
);
}
_display(Noti.Notification noti) {}
_display(Message msg) {
Navigator.push(context, BottomUpPageRoute(MessageDetail(msg:msg))
);
}
}

14
lib/vo/message.dart Normal file
View File

@@ -0,0 +1,14 @@
class Message {
String receiverName;
String message;
DateTime date;
String senderName;
bool isMe;
Message({this.receiverName, this.message, this.date, this.senderName,this.isMe});
bool fromToday() {
var now = DateTime.now();
return date.day == now.day &&
date.month == now.month &&
date.year == now.year;
}
}