Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
3.2 KiB

  1. import 'package:Envelope/components/custom_circle_avatar.dart';
  2. import 'package:Envelope/models/conversations.dart';
  3. import 'package:flutter/material.dart';
  4. import '/views/main/conversation_detail.dart';
  5. class ConversationListItem extends StatefulWidget{
  6. final Conversation conversation;
  7. const ConversationListItem({
  8. Key? key,
  9. required this.conversation,
  10. }) : super(key: key);
  11. @override
  12. _ConversationListItemState createState() => _ConversationListItemState();
  13. }
  14. class _ConversationListItemState extends State<ConversationListItem> {
  15. late Conversation conversation;
  16. bool loaded = false;
  17. @override
  18. void initState() {
  19. super.initState();
  20. conversation = widget.conversation;
  21. loaded = true;
  22. setState(() {});
  23. }
  24. @override
  25. Widget build(BuildContext context) {
  26. return GestureDetector(
  27. behavior: HitTestBehavior.opaque,
  28. onTap: () {
  29. loaded ? Navigator.push(context, MaterialPageRoute(builder: (context){
  30. return ConversationDetail(
  31. conversation: conversation,
  32. );
  33. })).then(onGoBack) : null;
  34. },
  35. child: Container(
  36. padding: const EdgeInsets.only(left: 16,right: 16,top: 10,bottom: 10),
  37. child: !loaded ? null : Row(
  38. children: <Widget>[
  39. Expanded(
  40. child: Row(
  41. children: <Widget>[
  42. CustomCircleAvatar(
  43. initials: conversation.name[0].toUpperCase(),
  44. imagePath: null,
  45. ),
  46. const SizedBox(width: 16),
  47. Expanded(
  48. child: Align(
  49. alignment: Alignment.centerLeft,
  50. child: Container(
  51. color: Colors.transparent,
  52. child: Column(
  53. crossAxisAlignment: CrossAxisAlignment.start,
  54. children: <Widget>[
  55. Text(
  56. conversation.name,
  57. style: const TextStyle(fontSize: 16)
  58. ),
  59. //Text(widget.messageText,style: TextStyle(fontSize: 13,color: Colors.grey.shade600, fontWeight: widget.isMessageRead?FontWeight.bold:FontWeight.normal),),
  60. ],
  61. ),
  62. ),
  63. ),
  64. ),
  65. ],
  66. ),
  67. ),
  68. ],
  69. ),
  70. ),
  71. );
  72. }
  73. onGoBack(dynamic value) async {
  74. conversation = await getConversationById(widget.conversation.id);
  75. setState(() {});
  76. }
  77. }