friend_trend_view.dart
4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import 'package:doublefeel_flutter/data/models/friend/friend_models.dart';
import 'package:doublefeel_flutter/l10n/l10n_extensions.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import '../../health_trend/views/health_trend_content.dart';
import '../controllers/friend_trend_controller.dart';
class FriendTrendView extends GetView<FriendTrendController> {
const FriendTrendView({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF5F2FF),
extendBodyBehindAppBar: true,
appBar: AppBar(
toolbarHeight: 44,
elevation: 0,
scrolledUnderElevation: 0,
backgroundColor: Colors.transparent,
surfaceTintColor: Colors.transparent,
systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
statusBarColor: Colors.transparent,
),
leadingWidth: 44,
leading: IconButton(
onPressed: Get.back,
padding: const EdgeInsets.only(left: 12),
icon: const Icon(Icons.arrow_back_ios_new_rounded),
color: const Color(0xFF0F0F11),
iconSize: 20,
tooltip: context.l10n.friendsBack,
),
titleSpacing: 0,
title: _FriendTrendTitle(
title: context.l10n.friendsTrendTitle(
_friendDisplayName(controller.friendItem),
),
avatarUrl: controller.friendItem?.avatar ?? "",
),
),
body: Stack(
children: [
Container(
height: 300,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xFFC5B0FF), Color(0xFFF5F2FF)],
),
),
),
Column(
children: [
SizedBox(height: MediaQuery.paddingOf(context).top + 44),
Expanded(
child: Obx(
() => HealthTrendContent(
query: controller.query,
queryForType: controller.queryForType,
selectedTypeIndex: controller.selectedTypeIndex.value,
onTypeChanged: controller.changeType,
onPeriodChanged: controller.changePeriod,
onDateChanged: controller.changeDate,
),
),
),
],
),
],
),
);
}
String _friendDisplayName(FriendItem? friend) {
final remark = friend?.remarkName?.trim();
if (remark != null && remark.isNotEmpty) return remark;
final nickname = friend?.friendNickname?.trim();
if (nickname != null && nickname.isNotEmpty) return nickname;
return l10n.friendsUnknownFriend;
}
}
class _FriendTrendTitle extends StatelessWidget {
const _FriendTrendTitle({
required this.title,
required this.avatarUrl,
});
final String title;
final String? avatarUrl;
@override
Widget build(BuildContext context) {
return Row(
children: [
Container(
width: 28,
height: 28,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Colors.white, width: 0.8),
gradient: const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xFFB7A6FF), Color(0xFFFFD7EA)],
),
),
child: avatarUrl?.trim().isNotEmpty == true
? Image.network(
avatarUrl!,
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const _AvatarFallback(),
)
: const _AvatarFallback(),
),
const SizedBox(width: 8),
Expanded(
child: Text(
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: Color(0xFF0F0F11),
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
),
],
);
}
}
class _AvatarFallback extends StatelessWidget {
const _AvatarFallback();
@override
Widget build(BuildContext context) {
return const Icon(Icons.person_rounded, size: 18, color: Colors.white);
}
}