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.

79 lines
2.4 KiB

  1. import 'package:Envelope/components/custom_circle_avatar.dart';
  2. import 'package:Envelope/models/conversations.dart';
  3. import 'package:Envelope/models/friends.dart';
  4. import 'package:Envelope/utils/storage/conversations.dart';
  5. import 'package:Envelope/utils/strings.dart';
  6. import 'package:Envelope/views/main/conversation/detail.dart';
  7. import 'package:flutter/material.dart';
  8. class FriendListItem extends StatefulWidget{
  9. final Friend friend;
  10. const FriendListItem({
  11. Key? key,
  12. required this.friend,
  13. }) : super(key: key);
  14. @override
  15. _FriendListItemState createState() => _FriendListItemState();
  16. }
  17. class _FriendListItemState extends State<FriendListItem> {
  18. @override
  19. Widget build(BuildContext context) {
  20. return GestureDetector(
  21. behavior: HitTestBehavior.opaque,
  22. onTap: () { findOrCreateConversation(context); },
  23. child: Container(
  24. padding: const EdgeInsets.only(left: 16,right: 16,top: 0,bottom: 20),
  25. child: Row(
  26. children: <Widget>[
  27. Expanded(
  28. child: Row(
  29. children: <Widget>[
  30. CustomCircleAvatar(
  31. initials: widget.friend.username[0].toUpperCase(),
  32. imagePath: null,
  33. ),
  34. const SizedBox(width: 16),
  35. Expanded(
  36. child: Align(
  37. alignment: Alignment.centerLeft,
  38. child: Container(
  39. color: Colors.transparent,
  40. child: Column(
  41. crossAxisAlignment: CrossAxisAlignment.start,
  42. children: <Widget>[
  43. Text(widget.friend.username, style: const TextStyle(fontSize: 16)),
  44. ],
  45. ),
  46. ),
  47. ),
  48. ),
  49. ],
  50. ),
  51. ),
  52. ],
  53. ),
  54. ),
  55. );
  56. }
  57. Future<void> findOrCreateConversation(BuildContext context) async {
  58. Conversation? conversation = await getTwoUserConversation(widget.friend.friendId);
  59. conversation ??= await createConversation(
  60. generateRandomString(32),
  61. [ widget.friend ],
  62. true,
  63. );
  64. uploadConversation(conversation, context);
  65. Navigator.push(context, MaterialPageRoute(builder: (context){
  66. return ConversationDetail(
  67. conversation: conversation!,
  68. );
  69. }));
  70. }
  71. }