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.

84 lines
3.2 KiB

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