Created
November 27, 2018 22:07
-
-
Save samarthagarwal/269455f5266ad25f340382296bbf5d1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:jesuskids/models/message.dart'; | |
import 'package:jesuskids/utilities/utilities.dart'; | |
class ChatMessageLeft extends StatelessWidget { | |
ChatMessageLeft({this.message, this.animationController}); | |
final Message message; | |
final AnimationController animationController; | |
@override | |
Widget build(BuildContext context) { | |
return SizeTransition( | |
sizeFactor: CurvedAnimation( | |
parent: animationController, | |
curve: Curves.easeOut, | |
), | |
axisAlignment: 0.0, | |
child: Container( | |
padding: EdgeInsets.all(16.0), | |
margin: EdgeInsets.only( | |
right: 40.0, | |
top: 8.0, | |
bottom: 8.0, | |
), | |
decoration: BoxDecoration( | |
color: Colors.white, | |
borderRadius: BorderRadius.circular( | |
20.0, | |
), | |
), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: <Widget>[ | |
Row( | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
Container( | |
margin: const EdgeInsets.only(right: 8.0), | |
child: CircleAvatar( | |
backgroundColor: Colors.red, | |
foregroundColor: Colors.white, | |
child: Text( | |
Utilities().getInitials(message.senderName), | |
), | |
), | |
), | |
Expanded( | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
Text( | |
"You", | |
style: Theme.of(context).textTheme.caption, | |
), | |
Text( | |
message.messageText, | |
), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.end, | |
children: <Widget>[ | |
Text( | |
message.messageTime | |
.toLocal() | |
.toString() | |
.split(' ')[1] | |
.substring(0, 5), | |
style: TextStyle( | |
fontSize: 12.0, | |
fontWeight: FontWeight.bold, | |
fontStyle: FontStyle.italic, | |
), | |
), | |
], | |
) | |
], | |
), | |
) | |
], | |
), | |
], | |
), | |
), | |
); | |
} | |
} | |
class ChatMessageRight extends StatelessWidget { | |
ChatMessageRight({this.message, this.animationController}); | |
final Message message; | |
final AnimationController animationController; | |
@override | |
Widget build(BuildContext context) { | |
return SizeTransition( | |
sizeFactor: | |
CurvedAnimation(parent: animationController, curve: Curves.easeOut), | |
axisAlignment: 0.0, | |
child: Container( | |
padding: EdgeInsets.all(16.0), | |
margin: EdgeInsets.only( | |
left: 40.0, | |
top: 8.0, | |
bottom: 8.0, | |
), | |
decoration: BoxDecoration( | |
color: Colors.black12.withOpacity(0.05), | |
borderRadius: BorderRadius.circular( | |
20.0, | |
), | |
), | |
child: Row( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: <Widget>[ | |
Expanded( | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.end, | |
children: <Widget>[ | |
Text( | |
"You", | |
style: Theme.of(context).textTheme.caption, | |
), | |
Text(message.messageText), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.start, | |
children: <Widget>[ | |
Text( | |
message.messageTime | |
.toLocal() | |
.toString() | |
.split(' ')[1] | |
.substring(0, 5), | |
style: TextStyle( | |
fontSize: 12.0, | |
fontWeight: FontWeight.bold, | |
fontStyle: FontStyle.italic, | |
), | |
), | |
], | |
) | |
], | |
), | |
), | |
SizedBox( | |
width: 20.0, | |
), | |
Container( | |
margin: const EdgeInsets.only(right: 16.0), | |
child: CircleAvatar( | |
backgroundColor: Colors.red, | |
foregroundColor: Colors.white, | |
child: Text( | |
Utilities().getInitials(message.senderName), | |
), | |
), | |
), | |
], | |
), | |
//), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment