Skip to content

Instantly share code, notes, and snippets.

@adityadroid
Created August 15, 2019 19:40
Show Gist options
  • Save adityadroid/16c3ed1fa0885380f849db6e69e3b6e2 to your computer and use it in GitHub Desktop.
Save adityadroid/16c3ed1fa0885380f849db6e69e3b6e2 to your computer and use it in GitHub Desktop.
chatitemwidget
import 'package:flutter/material.dart';
import 'package:messio/config/Palette.dart';
import 'package:intl/intl.dart';
class ChatItemWidget extends StatelessWidget{
var index;
ChatItemWidget(this.index);
@override
Widget build(BuildContext context) {
// TODO: implement build
if (index % 2 == 0) {
//This is the sent message. We'll later use data from firebase instead of index to determine the message is sent or received.
return Container(
child: Column(children: <Widget>[
Row(
children: <Widget>[
Container(
child: Text(
'This is a sent message',
style: TextStyle(color: Palette.selfMessageColor),
),
padding: EdgeInsets.fromLTRB(15.0, 10.0, 15.0, 10.0),
width: 200.0,
decoration: BoxDecoration(
color: Palette.selfMessageBackgroundColor,
borderRadius: BorderRadius.circular(8.0)),
margin: EdgeInsets.only(right: 10.0),
)
],
mainAxisAlignment:
MainAxisAlignment.end, // aligns the chatitem to right end
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Container(
child: Text(
DateFormat('dd MMM kk:mm')
.format(DateTime.fromMillisecondsSinceEpoch(1565888474278)),
style: TextStyle(
color: Palette.greyColor,
fontSize: 12.0,
fontStyle: FontStyle.normal),
),
margin: EdgeInsets.only(left: 5.0, top: 5.0, bottom: 5.0),
)])
]));
} else {
// This is a received message
return Container(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
child: Text(
'This is a received message',
style: TextStyle(color: Palette.otherMessageColor),
),
padding: EdgeInsets.fromLTRB(15.0, 10.0, 15.0, 10.0),
width: 200.0,
decoration: BoxDecoration(
color: Palette.otherMessageBackgroundColor,
borderRadius: BorderRadius.circular(8.0)),
margin: EdgeInsets.only(left: 10.0),
)
],
),
Container(
child: Text(
DateFormat('dd MMM kk:mm')
.format(DateTime.fromMillisecondsSinceEpoch(1565888474278)),
style: TextStyle(
color: Palette.greyColor,
fontSize: 12.0,
fontStyle: FontStyle.normal),
),
margin: EdgeInsets.only(left: 5.0, top: 5.0, bottom: 5.0),
)
],
crossAxisAlignment: CrossAxisAlignment.start,
),
margin: EdgeInsets.only(bottom: 10.0),
);
} }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment