custom_theme_card.dart
5.28 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
import 'package:flutter/material.dart';
import 'package:get/utils.dart';
import '../models/watch_theme_models.dart';
import 'watch_theme_character_avatar.dart';
import 'watch_theme_colors.dart';
import 'watch_theme_pro_badge.dart';
import 'watch_theme_selected_view.dart';
import 'watch_theme_section_card.dart';
class CustomThemeCard extends StatelessWidget {
const CustomThemeCard({
super.key,
required this.isPremium,
required this.customThemes,
required this.activeThemeId,
required this.onCreateTap,
this.onThemeTap,
});
final bool isPremium;
final List<WatchThemeItem> customThemes;
final int? activeThemeId;
final VoidCallback onCreateTap;
final ValueChanged<WatchThemeItem>? onThemeTap;
@override
Widget build(BuildContext context) {
return WatchThemeSectionCard(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
WatchThemeSectionTitle(
'自定义主题',
trailing: isPremium ? null : const WatchThemeProBadge(),
),
SizedBox(height: 4),
Text(
'用创意记录每一次情绪波动,打造懂你的专属表盘吧~',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: WatchThemeColors.textSecondary,
fontSize: 12,
fontWeight: FontWeight.w400,
height: 1.25,
),
),
SizedBox(height: 14),
_CreateThemeButton(onTap: onCreateTap),
customThemes.isEmpty
? SizedBox(height: 0)
: SizedBox(
height: 112,
child: ListView.separated(
scrollDirection: Axis.horizontal,
padding: EdgeInsets.zero,
itemBuilder: (context, index) {
return _CustomThemeItem(
item: customThemes[index],
selected: customThemes[index].id != null &&
customThemes[index].id == activeThemeId,
onTap: onThemeTap == null
? null
: () => onThemeTap!(customThemes[index]),
);
},
separatorBuilder: (context, index) {
return SizedBox(
width: 20,
);
},
itemCount: customThemes.length),
).paddingOnly(top: 12),
],
),
);
}
}
class _CreateThemeButton extends StatelessWidget {
const _CreateThemeButton({required this.onTap});
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: Container(
height: 48,
padding: EdgeInsets.symmetric(horizontal: 20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
gradient: const LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color(0xFFFFFFD0),
Color(0xFFFFD1DB),
Color(0xFFF0CDFF),
Color(0xFFCFE8FF),
],
stops: [0, 0.4, 0.7, 1],
),
),
child: Row(
children: [
Icon(
Icons.palette_outlined,
color: WatchThemeColors.overload,
size: 28,
),
SizedBox(width: 8),
Text(
'创作主题',
style: TextStyle(
color: WatchThemeColors.textPrimary,
fontSize: 14,
fontWeight: FontWeight.w600,
height: 1.25,
),
),
const Spacer(),
Icon(
Icons.chevron_right,
color: WatchThemeColors.textSecondary,
size: 20,
),
],
),
),
);
}
}
class _CustomThemeItem extends StatelessWidget {
const _CustomThemeItem({
required this.item,
required this.selected,
this.onTap,
});
final WatchThemeItem item;
final bool selected;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: SizedBox(
width: 88,
child: Column(
children: [
WatchThemeSelectedView(
selected: selected,
size: 88,
child: WatchThemeCharacterAvatar(
size: 88,
assetPath: item.infoList.firstOrNull?.assetPath,
imageUrl: item.infoList.firstOrNull?.imgUrl,
empty: item.infoList.firstOrNull?.image == null,
),
),
SizedBox(height: 8),
Text(
item.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: WatchThemeColors.textPrimary,
fontSize: 12,
fontWeight: FontWeight.w400,
height: 1.25,
),
),
],
),
),
);
}
}