Commit 54f62f826b7b66ea9b2232bc3470bec2c0e97fb8
1 parent
9475aa49
fix: 自适应视频标题高度避免文字裁切
Showing
1 changed file
with
28 additions
and
18 deletions
lib/pages/video/zone/video_zone_page.dart
| ... | ... | @@ -83,11 +83,19 @@ class _VideoZonePageState extends State<VideoZonePage> { |
| 83 | 83 | builder: (context, constraints) { |
| 84 | 84 | final horizontalPadding = 30.w; |
| 85 | 85 | final crossAxisSpacing = 12.w; |
| 86 | + final titleStyle = _VideoCard.createTitleStyle(context); | |
| 87 | + final titlePainter = TextPainter( | |
| 88 | + text: TextSpan(text: '视频标题', style: titleStyle), | |
| 89 | + maxLines: 1, | |
| 90 | + textDirection: Directionality.of(context), | |
| 91 | + textScaler: MediaQuery.textScalerOf(context), | |
| 92 | + )..layout(); | |
| 86 | 93 | final cardWidth = (constraints.maxWidth - |
| 87 | 94 | horizontalPadding * 2 - |
| 88 | 95 | crossAxisSpacing * 2) / |
| 89 | 96 | 3; |
| 90 | - final cardHeight = cardWidth * 9 / 16 + 5.h + 24.h; | |
| 97 | + final cardHeight = | |
| 98 | + cardWidth * 9 / 16 + 5.h + titlePainter.height; | |
| 91 | 99 | return GridView.builder( |
| 92 | 100 | physics: const AlwaysScrollableScrollPhysics(), |
| 93 | 101 | padding: EdgeInsets.fromLTRB( |
| ... | ... | @@ -106,6 +114,7 @@ class _VideoZonePageState extends State<VideoZonePage> { |
| 106 | 114 | itemBuilder: (context, index) => _VideoCard( |
| 107 | 115 | item: items[index], |
| 108 | 116 | onTap: () => _openVideo(items, index), |
| 117 | + titleStyle: titleStyle, | |
| 109 | 118 | ), |
| 110 | 119 | ); |
| 111 | 120 | }, |
| ... | ... | @@ -169,10 +178,22 @@ class _VideoLoadError extends StatelessWidget { |
| 169 | 178 | } |
| 170 | 179 | |
| 171 | 180 | class _VideoCard extends StatelessWidget { |
| 172 | - const _VideoCard({required this.item, required this.onTap}); | |
| 181 | + const _VideoCard({ | |
| 182 | + required this.item, | |
| 183 | + required this.onTap, | |
| 184 | + required this.titleStyle, | |
| 185 | + }); | |
| 173 | 186 | |
| 174 | 187 | final VideoZoneItem item; |
| 175 | 188 | final VoidCallback onTap; |
| 189 | + final TextStyle titleStyle; | |
| 190 | + | |
| 191 | + static TextStyle createTitleStyle(BuildContext context) => TextStyle( | |
| 192 | + color: const Color(0xFF222222), | |
| 193 | + fontFamily: null, | |
| 194 | + fontSize: 17.sp, | |
| 195 | + fontWeight: FontWeight.w500, | |
| 196 | + ); | |
| 176 | 197 | |
| 177 | 198 | @override |
| 178 | 199 | Widget build(BuildContext context) { |
| ... | ... | @@ -202,22 +223,11 @@ class _VideoCard extends StatelessWidget { |
| 202 | 223 | ), |
| 203 | 224 | ), |
| 204 | 225 | SizedBox(height: 5.h), |
| 205 | - SizedBox( | |
| 206 | - height: 24.h, | |
| 207 | - child: Align( | |
| 208 | - alignment: Alignment.centerLeft, | |
| 209 | - child: Text( | |
| 210 | - item.title, | |
| 211 | - maxLines: 1, | |
| 212 | - overflow: TextOverflow.ellipsis, | |
| 213 | - style: TextStyle( | |
| 214 | - color: const Color(0xFF222222), | |
| 215 | - fontFamily: null, | |
| 216 | - fontSize: 17.sp, | |
| 217 | - fontWeight: FontWeight.w500, | |
| 218 | - ), | |
| 219 | - ), | |
| 220 | - ), | |
| 226 | + Text( | |
| 227 | + item.title, | |
| 228 | + maxLines: 1, | |
| 229 | + overflow: TextOverflow.ellipsis, | |
| 230 | + style: titleStyle, | |
| 221 | 231 | ), |
| 222 | 232 | ], |
| 223 | 233 | ), | ... | ... |