together_mobile/lib/screens/friend_profile/friend_profile_screen.dart

230 lines
7.7 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:go_router/go_router.dart';
import 'package:together_mobile/common/constants.dart';
import 'package:together_mobile/models/init_get_it.dart';
import 'package:together_mobile/models/contact_model.dart';
import 'package:together_mobile/models/route_state_model.dart';
import 'package:together_mobile/request/server.dart';
import 'components/friend_profile_card.dart';
import 'components/row_floating_buttons.dart';
class FriendProfileScreen extends StatelessWidget {
const FriendProfileScreen({
super.key,
required this.friendId,
});
final String friendId;
@override
Widget build(BuildContext context) {
Timer(
const Duration(milliseconds: 300),
() => getIt.get<RouteState>().changeRoute('FriendProfile'),
);
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(
getIt.get<Contact>().friends[friendId]!.friendRemark.isEmpty
? getIt.get<ContactAccountProfile>().friends[friendId]!.nickname
: getIt.get<Contact>().friends[friendId]!.friendRemark,
),
actions: [
TextButton(
onPressed: () {
getIt.get<RouteState>().changeRoute('FriendSetting');
context.pushNamed(
'FriendSetting',
queryParameters: {'friendId': friendId},
);
},
style: TextButton.styleFrom(
foregroundColor: kContentColorDark,
),
child: const Text('设置'),
),
],
),
body: GridView.count(
padding: const EdgeInsets.all(10.0),
childAspectRatio: 0.9,
crossAxisCount: 2,
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
children: [
FriendProfileCard(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.avatar
.isEmpty
? const CircleAvatar(
radius: 65,
backgroundImage: AssetImage('assets/images/user_3.png'),
)
: CircleAvatar(
radius: 65,
backgroundImage: CachedNetworkImageProvider(
'$userAvatarsUrl/${getIt.get<ContactAccountProfile>().friends[friendId]!.avatar}',
),
),
const Chip(
label: Text('状态'),
visualDensity: VisualDensity.compact,
),
],
),
),
FriendProfileCard(
tag: '基本信息',
child: Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(
getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.nickname,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 16),
),
getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.location
.isEmpty
? const Text(
'(未设置位置)',
style: TextStyle(
fontSize: 16,
color: kUnActivatedColor,
),
)
: Text(getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.location),
getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.birthday
.isEmpty
? const Text(
'(未设置生日)',
style: TextStyle(
fontSize: 16,
color: kUnActivatedColor,
),
)
: Text(
getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.birthday,
style: const TextStyle(fontSize: 16),
),
getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.gender
.isEmpty
? const Text(
'(未设置性别)',
style: TextStyle(
fontSize: 16,
color: kUnActivatedColor,
),
)
: Text(
getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.gender ==
'man'
? ''
: '',
style: const TextStyle(
fontSize: 16,
),
),
],
),
),
),
FriendProfileCard(
tag: '签名',
child: Expanded(
child: getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.sign
.isEmpty
? const Text(
'(未设置签名)',
style: TextStyle(
fontSize: 16,
color: kUnActivatedColor,
),
)
: Text(
getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.sign,
style: const TextStyle(
fontSize: 16,
),
),
),
),
FriendProfileCard(
tag: '账号信息',
child: Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
getIt
.get<ContactAccountProfile>()
.friends[friendId]!
.username,
style: const TextStyle(
fontSize: 16,
),
),
const SizedBox(
height: 20,
),
Text(
getIt.get<ContactAccountProfile>().friends[friendId]!.email,
style: const TextStyle(
fontSize: 16,
),
),
],
),
),
),
],
),
floatingActionButton: RowFloatingButtons(
friendId: friendId,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
);
}
}