From 5bc34b34084f928af41513b50f25e76ebdda77e3 Mon Sep 17 00:00:00 2001 From: sainw Date: Tue, 2 Jun 2020 14:56:38 +0630 Subject: [PATCH] add message --- lib/app.dart | 5 ++ lib/model_fcs/message_model.dart | 101 ++++++++++++++++++++++ lib/pages/message_detail.dart | 140 +++++++++++++++++++++++++++++++ lib/pages/notification_list.dart | 83 ++++++++---------- lib/vo/message.dart | 14 ++++ 5 files changed, 296 insertions(+), 47 deletions(-) create mode 100644 lib/model_fcs/message_model.dart create mode 100644 lib/pages/message_detail.dart create mode 100644 lib/vo/message.dart diff --git a/lib/app.dart b/lib/app.dart index 257fb3c..89b489a 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -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'; @@ -67,6 +69,7 @@ class _AppState extends State { final ShipmentRateModel shipmentRateModel = new ShipmentRateModel(); final ShipmentModel shipmentModel = new ShipmentModel(); final PackageModel packageModel=new PackageModel(); + final MessageModel messageModel=new MessageModel(); AppTranslationsDelegate _newLocaleDelegate; @@ -102,6 +105,7 @@ class _AppState extends State { ..addModel(shipmentRateModel) ..addModel(shipmentModel) ..addModel(packageModel) + ..addModel(messageModel) ..addModel(shipmentRateModel); this.mainModel.init(); } @@ -155,6 +159,7 @@ class _AppState extends State { ChangeNotifierProvider(builder: (context) => shipmentRateModel), ChangeNotifierProvider(builder: (context) => shipmentModel), ChangeNotifierProvider(builder: (context) => packageModel), + ChangeNotifierProvider(builder: (context) => messageModel), ChangeNotifierProvider( builder: (context) => testModel, ), diff --git a/lib/model_fcs/message_model.dart b/lib/model_fcs/message_model.dart new file mode 100644 index 0000000..cc8c995 --- /dev/null +++ b/lib/model_fcs/message_model.dart @@ -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 listener; + + List 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 get lastMessage { + return [messages[2], messages[5]]; + } + + List getMessage(String receiver) { + return messages.where((e) => e.receiverName == receiver).toList(); + } + + // List get completed { + // return packages.where((e) => e.status == "Delivered").toList() + // ..sort((e1, e2) { + // return e2.packageNumber.compareTo(e1.packageNumber); + // }); + // } + + // List 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 = []; + } +} diff --git a/lib/pages/message_detail.dart b/lib/pages/message_detail.dart new file mode 100644 index 0000000..82ce76b --- /dev/null +++ b/lib/pages/message_detail.dart @@ -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: [ + 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: [ + Padding( + padding: EdgeInsets.only(right: 48.0), + child: Text(message), + ), + Positioned( + bottom: 0.0, + right: 0.0, + child: Row( + children: [ + 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(context); + List messages = messageModel.getMessage(msg.receiverName); + List 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: [], + ), + body: Padding( + padding: EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: bubbles, + // children: [ + // 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, + // ), + // ], + ), + ), + ); + } +} diff --git a/lib/pages/notification_list.dart b/lib/pages/notification_list.dart index 0bb0ac3..ae196ff 100644 --- a/lib/pages/notification_list.dart +++ b/lib/pages/notification_list.dart @@ -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 { 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(context); + MessageModel messageModel = Provider.of(context); return LocalProgress( inAsyncCall: _isLoading, @@ -40,7 +43,7 @@ class _NotificationListState extends State { backgroundColor: primaryColor, title: LocalText( context, - 'noti.list.title', + 'message.title', fontSize: 20, color: Colors.white, ), @@ -50,15 +53,15 @@ class _NotificationListState extends State { 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: [ InkWell( - onTap: () => _display(noti), + onTap: () => _display(msg), child: Row( children: [ Expanded( @@ -68,8 +71,12 @@ class _NotificationListState extends State { children: [ 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,35 +84,11 @@ class _NotificationListState extends State { CrossAxisAlignment.start, children: [ 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), - ), - ), ], ), ), @@ -113,17 +96,20 @@ class _NotificationListState extends State { ), ), ), - Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Padding( - padding: const EdgeInsets.all(8.0), - child: Text(timeFormatter.format(noti.time)), - ), - noti.fromToday() - ? Container() - : Text(dateFormatter.format(noti.time)), - ], + Padding( + padding: const EdgeInsets.only(right: 18.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.all(8.0), + child: Text(timeFormatter.format(msg.date)), + ), + msg.fromToday() + ? Container() + : Text(dateFormatter.format(msg.date)), + ], + ), ) ], ), @@ -135,5 +121,8 @@ class _NotificationListState extends State { ); } - _display(Noti.Notification noti) {} + _display(Message msg) { + Navigator.push(context, BottomUpPageRoute(MessageDetail(msg:msg)) + ); + } } diff --git a/lib/vo/message.dart b/lib/vo/message.dart new file mode 100644 index 0000000..144fe81 --- /dev/null +++ b/lib/vo/message.dart @@ -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; + } +}