together_mobile/lib/screens/contact/components/friend_tile.dart

112 lines
3.5 KiB
Dart
Raw Normal View History

2023-06-21 17:44:28 +08:00
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
2023-06-21 17:44:28 +08:00
import 'package:go_router/go_router.dart';
2024-04-09 17:23:28 +08:00
import '/models/user_model.dart';
import '/request/server.dart';
import '/models/contact_model.dart';
import '/models/init_get_it.dart';
2023-06-21 17:44:28 +08:00
class FriendTile extends StatelessWidget {
const FriendTile({super.key, required this.friendId});
final String friendId;
2023-06-21 17:44:28 +08:00
@override
Widget build(BuildContext context) {
2023-10-06 16:43:51 +08:00
final bool isMyself = friendId == getIt.get<UserAccount>().id;
2023-06-21 17:44:28 +08:00
return InkWell(
onTap: () {
if (friendId == getIt.get<UserAccount>().id) {
context.pushNamed('MyProfile');
} else {
context.pushNamed(
'FriendProfile',
queryParameters: {'friendId': friendId},
);
}
},
2023-06-21 17:44:28 +08:00
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(
width: 10.0,
),
CircleAvatar(
backgroundImage: CachedNetworkImageProvider(
'$userAvatarsUrl/${getIt.get<ContactAccountProfile>().friends[friendId]!.avatar}',
),
),
2023-06-21 17:44:28 +08:00
const SizedBox(
width: 10.0,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// nickname
Text(
getIt.get<Contact>().friends[friendId]!.friendRemark.isEmpty
? getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.nickname
: getIt.get<Contact>().friends[friendId]!.friendRemark,
style: const TextStyle(fontSize: 17),
2023-06-21 17:44:28 +08:00
),
// sign
2023-08-10 19:08:46 +08:00
if (getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.sign
.isNotEmpty)
Text(
getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.sign,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Theme.of(context).textTheme.displayLarge?.color,
),
2023-06-21 17:44:28 +08:00
),
],
),
),
const SizedBox(
width: 10.0,
),
2023-10-06 16:43:51 +08:00
if (isMyself)
if (getIt.get<UserProfile>().status.isNotEmpty)
Chip(
visualDensity: VisualDensity.compact,
label: Text(getIt.get<UserProfile>().status),
),
if (!isMyself)
if (getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.status
.isNotEmpty)
Chip(
visualDensity: VisualDensity.compact,
label: Text(getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.status),
),
2023-06-21 17:44:28 +08:00
const SizedBox(
width: 10.0,
),
],
),
),
);
}
}