diff --git a/lib/pages/video/module/attention.dart b/lib/pages/video/module/attention.dart index 90b7ff7..92a1f99 100644 --- a/lib/pages/video/module/attention.dart +++ b/lib/pages/video/module/attention.dart @@ -1294,61 +1294,68 @@ class _AttentionModuleState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( + if (videoModuleController.videoPlayIndex.value < videoList.length) + Text( '@${videoList[videoModuleController.videoPlayIndex.value]['nickname'] ?? '未知'}', style: const TextStyle(color: Colors.white, fontSize: 16.0), - ), - LayoutBuilder( - builder: (context, constraints) { - final text = videoList[videoModuleController.videoPlayIndex.value]['title'] ?? '未知'; - final span = TextSpan( - text: text, - style: const TextStyle(color: Colors.white, fontSize: 14.0), - ); - final tp = TextPainter( - text: span, - maxLines: 3, - textDirection: TextDirection.ltr, - ); - tp.layout(maxWidth: constraints.maxWidth); - final isOverflow = tp.didExceedMaxLines; + ) else + Text( + '@未知', + style: const TextStyle(color: Colors.white, fontSize: 16.0), + ), + if (videoModuleController.videoPlayIndex.value < videoList.length) + LayoutBuilder( + builder: (context, constraints) { + final text = videoList[videoModuleController.videoPlayIndex.value]['title'] ?? '未知'; + final span = TextSpan( + text: text, + style: const TextStyle(color: Colors.white, fontSize: 14.0), + ); + final tp = TextPainter( + text: span, + maxLines: 3, + textDirection: TextDirection.ltr, + ); + tp.layout(maxWidth: constraints.maxWidth); + final isOverflow = tp.didExceedMaxLines; - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - text, - maxLines: videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? null : 3, - overflow: videoList[videoModuleController.videoPlayIndex.value]['expanded'] - ? TextOverflow.visible - : TextOverflow.ellipsis, - style: const TextStyle(color: Colors.white, fontSize: 14.0), - ), - if (isOverflow) - Padding( - padding: const EdgeInsets.only(top: 6.0), - child: GestureDetector( - onTap: () { - setState(() { - videoList[videoModuleController.videoPlayIndex.value]['expanded'] = - !videoList[videoModuleController.videoPlayIndex.value]['expanded']; - }); - }, - child: Text( - videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? '收起' : '展开更多', - textAlign: TextAlign.right, - style: const TextStyle( - color: Colors.white, - fontSize: 14, - fontWeight: FontWeight.bold, + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + text, + maxLines: videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? null : 3, + overflow: videoList[videoModuleController.videoPlayIndex.value]['expanded'] + ? TextOverflow.visible + : TextOverflow.ellipsis, + style: const TextStyle(color: Colors.white, fontSize: 14.0), + ), + if (isOverflow) + Padding( + padding: const EdgeInsets.only(top: 6.0), + child: GestureDetector( + onTap: () { + setState(() { + videoList[videoModuleController.videoPlayIndex.value]['expanded'] = + !videoList[videoModuleController.videoPlayIndex.value]['expanded']; + }); + }, + child: Text( + videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? '收起' : '展开更多', + textAlign: TextAlign.right, + style: const TextStyle( + color: Colors.white, + fontSize: 14, + fontWeight: FontWeight.bold, + ), ), ), ), - ), - ], - ); - }, - ), + ], + ); + }, + )else + SizedBox() ], )), Positioned( diff --git a/lib/pages/video/module/friend.dart b/lib/pages/video/module/friend.dart index cff5207..96cf1b2 100644 --- a/lib/pages/video/module/friend.dart +++ b/lib/pages/video/module/friend.dart @@ -1299,61 +1299,70 @@ class _FriendModuleState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - '@${videoList[videoModuleController.videoPlayIndex.value]['nickname'] ?? '未知'}', - style: const TextStyle(color: Colors.white, fontSize: 16.0), - ), - LayoutBuilder( - builder: (context, constraints) { - final text = videoList[videoModuleController.videoPlayIndex.value]['title'] ?? '未知'; - final span = TextSpan( - text: text, - style: const TextStyle(color: Colors.white, fontSize: 14.0), - ); - final tp = TextPainter( - text: span, - maxLines: 3, - textDirection: TextDirection.ltr, - ); - tp.layout(maxWidth: constraints.maxWidth); - final isOverflow = tp.didExceedMaxLines; + if (videoModuleController.videoPlayIndex.value < videoList.length) + Text( + '@${videoList[videoModuleController.videoPlayIndex.value]['nickname'] ?? '未知'}', + style: const TextStyle(color: Colors.white, fontSize: 16.0), + ) + else + Text( + '@未知', + style: const TextStyle(color: Colors.white, fontSize: 16.0), + ), + // 对下面的 LayoutBuilder 也需要同样的检查 + if (videoModuleController.videoPlayIndex.value < videoList.length) + LayoutBuilder( + builder: (context, constraints) { + final text = videoList[videoModuleController.videoPlayIndex.value]['title'] ?? '未知'; + final span = TextSpan( + text: text, + style: const TextStyle(color: Colors.white, fontSize: 14.0), + ); + final tp = TextPainter( + text: span, + maxLines: 3, + textDirection: TextDirection.ltr, + ); + tp.layout(maxWidth: constraints.maxWidth); + final isOverflow = tp.didExceedMaxLines; - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - text, - maxLines: videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? null : 3, - overflow: videoList[videoModuleController.videoPlayIndex.value]['expanded'] - ? TextOverflow.visible - : TextOverflow.ellipsis, - style: const TextStyle(color: Colors.white, fontSize: 14.0), - ), - if (isOverflow) - Padding( - padding: const EdgeInsets.only(top: 6.0), - child: GestureDetector( - onTap: () { - setState(() { - videoList[videoModuleController.videoPlayIndex.value]['expanded'] = - !videoList[videoModuleController.videoPlayIndex.value]['expanded']; - }); - }, - child: Text( - videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? '收起' : '展开更多', - textAlign: TextAlign.right, - style: const TextStyle( - color: Colors.white, - fontSize: 14, - fontWeight: FontWeight.bold, + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + text, + maxLines: videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? null : 3, + overflow: videoList[videoModuleController.videoPlayIndex.value]['expanded'] + ? TextOverflow.visible + : TextOverflow.ellipsis, + style: const TextStyle(color: Colors.white, fontSize: 14.0), + ), + if (isOverflow) + Padding( + padding: const EdgeInsets.only(top: 6.0), + child: GestureDetector( + onTap: () { + setState(() { + videoList[videoModuleController.videoPlayIndex.value]['expanded'] = + !videoList[videoModuleController.videoPlayIndex.value]['expanded']; + }); + }, + child: Text( + videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? '收起' : '展开更多', + textAlign: TextAlign.right, + style: const TextStyle( + color: Colors.white, + fontSize: 14, + fontWeight: FontWeight.bold, + ), ), ), ), - ), - ], - ); - }, - ), + ], + ); + }, + )else + SizedBox() ], )), Positioned( diff --git a/lib/pages/video/module/recommend.dart b/lib/pages/video/module/recommend.dart index 1180a8b..0d81013 100644 --- a/lib/pages/video/module/recommend.dart +++ b/lib/pages/video/module/recommend.dart @@ -1300,60 +1300,67 @@ class _RecommendModuleState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - '@${videoList[videoModuleController.videoPlayIndex.value]['nickname'] ?? '未知'}', - style: const TextStyle(color: Colors.white, fontSize: 16.0), - ), - LayoutBuilder( - builder: (context, constraints) { - final text = videoList[videoModuleController.videoPlayIndex.value]['title'] ?? '未知'; - final span = TextSpan( - text: text, - style: const TextStyle(color: Colors.white, fontSize: 14.0), - ); - final tp = TextPainter( - text: span, - maxLines: 3, - textDirection: TextDirection.ltr, - ); - tp.layout(maxWidth: constraints.maxWidth); - final isOverflow = tp.didExceedMaxLines; + if (videoModuleController.videoPlayIndex.value < videoList.length) + Text( + '@${videoList[videoModuleController.videoPlayIndex.value]['nickname'] ?? '未知'}', + style: const TextStyle(color: Colors.white, fontSize: 16.0), + ) else + Text( + '@未知', + style: const TextStyle(color: Colors.white, fontSize: 16.0), + ), + if (videoModuleController.videoPlayIndex.value < videoList.length) + LayoutBuilder( + builder: (context, constraints) { + final text = videoList[videoModuleController.videoPlayIndex.value]['title'] ?? '未知'; + final span = TextSpan( + text: text, + style: const TextStyle(color: Colors.white, fontSize: 14.0), + ); + final tp = TextPainter( + text: span, + maxLines: 3, + textDirection: TextDirection.ltr, + ); + tp.layout(maxWidth: constraints.maxWidth); + final isOverflow = tp.didExceedMaxLines; - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - text, - maxLines: videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? null : 3, - overflow: - videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? TextOverflow.visible : TextOverflow.ellipsis, - style: const TextStyle(color: Colors.white, fontSize: 14.0), - ), - if (isOverflow) - Padding( - padding: const EdgeInsets.only(top: 6.0), - child: GestureDetector( - onTap: () { - setState(() { - videoList[videoModuleController.videoPlayIndex.value]['expanded'] = - !videoList[videoModuleController.videoPlayIndex.value]['expanded']; - }); - }, - child: Text( - videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? '收起' : '展开更多', - textAlign: TextAlign.right, - style: const TextStyle( - color: Colors.white, - fontSize: 14, - fontWeight: FontWeight.bold, + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + text, + maxLines: videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? null : 3, + overflow: + videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? TextOverflow.visible : TextOverflow.ellipsis, + style: const TextStyle(color: Colors.white, fontSize: 14.0), + ), + if (isOverflow) + Padding( + padding: const EdgeInsets.only(top: 6.0), + child: GestureDetector( + onTap: () { + setState(() { + videoList[videoModuleController.videoPlayIndex.value]['expanded'] = + !videoList[videoModuleController.videoPlayIndex.value]['expanded']; + }); + }, + child: Text( + videoList[videoModuleController.videoPlayIndex.value]['expanded'] ? '收起' : '展开更多', + textAlign: TextAlign.right, + style: const TextStyle( + color: Colors.white, + fontSize: 14, + fontWeight: FontWeight.bold, + ), ), ), ), - ), - ], - ); - }, - ), + ], + ); + }, + )else + SizedBox() ], )), Positioned(