home_trend_view.dart
5.14 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import 'package:cached_network_image/cached_network_image.dart';
import 'package:doublefeel_flutter/data/local/user_preferences_storage.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../health_trend/views/health_trend_content.dart';
import '../../controllers/trend/trend_controller.dart';
class HomeTrendView extends GetView<TrendController> {
const HomeTrendView({super.key});
@override
Widget build(BuildContext context) {
return const _TrendPageBackground(
child: Column(
children: [
SafeArea(
bottom: false,
child: _HomeTrendHeader(),
),
Expanded(child: _HomeTrendBody()),
],
),
);
}
}
class _HomeTrendBody extends GetView<TrendController> {
const _HomeTrendBody();
@override
Widget build(BuildContext context) {
return Obx(
() => HealthTrendContent(
query: controller.query,
queryForType: controller.queryForType,
selectedTypeIndex: controller.selectedTypeIndex.value,
refreshToken: controller.refreshToken.value,
onTypeChanged: controller.changeType,
onQueryChanged: controller.changeQuery,
),
);
}
}
class _HomeTrendHeader extends GetView<TrendController> {
const _HomeTrendHeader();
@override
Widget build(BuildContext context) {
return SizedBox(
height: 48,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: Stack(
alignment: Alignment.center,
children: [
const Align(
alignment: Alignment.centerLeft,
child: Text(
'趋势',
style: TextStyle(
color: Color(0xFF0F0F11),
fontSize: 24,
fontWeight: FontWeight.w600,
),
),
),
Obx(() {
final friendAvatar = controller.targetFriendInfo.value?.avatar;
final selfAvatar = Get.find<UserPreferencesStorage>()
.preferences
.value
.meUserInfo
?.avatar;
return _TrendHeaderAvatar(
avatarUrl: friendAvatar?.trim().isNotEmpty == true
? friendAvatar
: selfAvatar,
onTap: controller.canSwitchFriend
? controller.showFriendListBottomSheet
: null,
);
}),
Obx(
() => !controller.canSwitchFriend
? const SizedBox.shrink()
: Align(
alignment: Alignment.centerRight,
child: IconButton(
highlightColor: Colors.transparent,
padding: EdgeInsets.zero,
onPressed: controller.showFriendListBottomSheet,
icon: Image.asset(
'assets/images/common/ic_replace.png',
width: 20,
height: 20,
),
),
),
),
],
),
),
);
}
}
class _TrendHeaderAvatar extends StatelessWidget {
const _TrendHeaderAvatar({this.avatarUrl, this.onTap});
final String? avatarUrl;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
final imageUrl = avatarUrl?.trim();
final avatar = Container(
width: 36,
height: 36,
decoration: ShapeDecoration(
image: imageUrl?.isNotEmpty == true
? DecorationImage(
image: CachedNetworkImageProvider(imageUrl!),
fit: BoxFit.cover,
)
: null,
shape: RoundedRectangleBorder(
side: const BorderSide(width: 0.78, color: Colors.white),
borderRadius: BorderRadius.circular(35.78),
),
),
child: imageUrl?.isNotEmpty == true ? null : const _AvatarFallback(),
);
if (onTap == null) return avatar;
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: SizedBox(
width: 44,
height: 44,
child: Center(child: avatar),
),
);
}
}
class _AvatarFallback extends StatelessWidget {
const _AvatarFallback();
@override
Widget build(BuildContext context) {
return const Icon(
Icons.person_rounded,
color: Colors.white,
size: 22,
);
}
}
class _TrendPageBackground extends StatelessWidget {
const _TrendPageBackground({required this.child});
final Widget child;
@override
Widget build(BuildContext context) {
return ColoredBox(
color: const Color(0xFFF5F2FF),
child: Stack(
children: [
Container(
height: 300,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xFFC5B0FF), Color(0xFFF5F2FF)],
),
),
),
child,
],
),
);
}
}