select_friend_view.dart
5.24 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
import 'package:doublefeel_flutter/core/theme/app_colors.dart';
import 'package:doublefeel_flutter/core/util/size_extensions.dart';
import 'package:doublefeel_flutter/l10n/l10n_extensions.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/select_friend_logic.dart';
import '../widgets/friend_health_card.dart';
class SelectFriendView extends StatefulWidget {
const SelectFriendView({super.key});
@override
State<SelectFriendView> createState() => _SelectFriendViewState();
}
class _SelectFriendViewState extends State<SelectFriendView> {
late final SelectFriendLogic _logic;
@override
void initState() {
super.initState();
_logic = SelectFriendLogic();
_logic.initialize();
}
@override
void dispose() {
_logic.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
decoration: BoxDecoration(
color: const Color(0xFFF5F2FF),
borderRadius: BorderRadius.vertical(top: Radius.circular(12.dp)),
),
child: Stack(
children: [
Column(
children: [
_SelectFriendHeader(onClose: () => Get.back<void>()),
Expanded(
child: Obx(() {
if (_logic.isLoading.value && _logic.friends.isEmpty) {
return const Center(child: CircularProgressIndicator());
}
final selectedIndex = _logic.selectedIndex.value;
return ListView.separated(
padding: EdgeInsets.fromLTRB(
16.dp,
0,
16.dp,
118.dp + MediaQuery.viewPaddingOf(context).bottom,
),
itemBuilder: (context, index) {
final friend = _logic.friends[index];
final isSelected = selectedIndex == index;
return FriendHealthCard(
name: friend.name,
remark: friend.remark,
avatarUrl: friend.avatarUrl,
updatedAt: friend.updatedAt,
sleepQualityScore: friend.sleepQualityScore,
steps: friend.steps,
activeCalories: friend.activeCalories,
stressState: friend.stressState,
isOnWatchFace: friend.isOnWatchFace,
isSelected: isSelected,
showCheckbox: true,
onTap: () => _logic.selectFriendAt(index),
);
},
separatorBuilder: (_, __) => SizedBox(height: 12.dp),
itemCount: _logic.friends.length,
);
}),
),
],
),
Positioned(
left: 49.dp,
right: 49.dp,
bottom: 36.dp + MediaQuery.viewPaddingOf(context).bottom,
child: _SyncButton(onTap: _syncSelectedFriend),
),
],
),
);
}
Future<void> _syncSelectedFriend() async {
final selectedFriend = await _logic.syncSelectedFriendToWatchFace();
Get.back(result: selectedFriend);
}
}
class _SelectFriendHeader extends StatelessWidget {
const _SelectFriendHeader({required this.onClose});
final VoidCallback onClose;
@override
Widget build(BuildContext context) {
return SizedBox(
height: 56.dp,
child: Row(
children: [
Padding(
padding: EdgeInsets.only(left: 22.dp),
child: GestureDetector(
onTap: onClose,
behavior: HitTestBehavior.opaque,
child: SizedBox(
width: 40.dp,
height: 40.dp,
child: const Center(
child: Icon(
Icons.close,
color: AppColors.primary,
size: 20,
),
),
),
),
),
Expanded(
child: Center(
child: Text(
context.l10n.friendsSelect,
style: const TextStyle(
color: AppColors.textPrimary,
fontSize: 16,
fontWeight: FontWeight.w600,
height: 1.4,
),
),
),
),
SizedBox(width: 62.dp),
],
),
);
}
}
class _SyncButton extends StatelessWidget {
const _SyncButton({required this.onTap});
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
behavior: HitTestBehavior.opaque,
child: Container(
height: 48.dp,
alignment: Alignment.center,
decoration: BoxDecoration(
color: AppColors.primary,
borderRadius: BorderRadius.circular(24.dp),
),
child: Text(
context.l10n.friendsSelectAndSync,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w600,
height: 1.4,
),
),
),
);
}
}