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.

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