import 'package:Envelope/components/custom_circle_avatar.dart'; import 'package:Envelope/components/flash_message.dart'; import 'package:Envelope/models/conversations.dart'; import 'package:Envelope/models/friends.dart'; import 'package:Envelope/utils/storage/conversations.dart'; import 'package:Envelope/utils/storage/messages.dart'; import 'package:Envelope/utils/strings.dart'; import 'package:Envelope/views/main/conversation/detail.dart'; import 'package:flutter/material.dart'; class FriendListItem extends StatefulWidget{ final Friend friend; const FriendListItem({ Key? key, required this.friend, }) : super(key: key); @override _FriendListItemState createState() => _FriendListItemState(); } class _FriendListItemState extends State { @override Widget build(BuildContext context) { return GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { findOrCreateConversation(context); }, child: Container( padding: const EdgeInsets.only(left: 16,right: 16,top: 0,bottom: 20), child: Row( children: [ Expanded( child: Row( children: [ CustomCircleAvatar( initials: widget.friend.username[0].toUpperCase(), ), const SizedBox(width: 16), Expanded( child: Align( alignment: Alignment.centerLeft, child: Container( color: Colors.transparent, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(widget.friend.username, style: const TextStyle(fontSize: 16)), ], ), ), ), ), ], ), ), ], ), ), ); } Future findOrCreateConversation(BuildContext context) async { Conversation? conversation = await getTwoUserConversation(widget.friend.friendId); conversation ??= await createConversation( generateRandomString(32), [ widget.friend ], true, ); uploadConversation(conversation) .catchError((dynamic d) async { showMessage('Failed to create conversation', context); }); Navigator.push(context, MaterialPageRoute(builder: (context){ return ConversationDetail( conversation: conversation!, ); })); } }