From faaffd0f30aefffb660f5d830197ee89a09caedc Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Sat, 23 Aug 2025 09:04:18 +0800 Subject: [PATCH] fix #1087 Signed-off-by: bggRGjQaUbCoE --- lib/pages/emote/view.dart | 32 ++++++++++++++------------ lib/pages/live_emote/view.dart | 42 ++++++++++++++++------------------ 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/lib/pages/emote/view.dart b/lib/pages/emote/view.dart index 39e19f1b..c406afa3 100644 --- a/lib/pages/emote/view.dart +++ b/lib/pages/emote/view.dart @@ -56,10 +56,13 @@ class _EmotePanelState extends State controller: _emotePanelController.tabController, children: response!.map( (e) { - double size = e.emote!.first.meta!.size == 1 - ? 40 - : 60; - bool isTextEmote = e.type == 4; + final emote = e.emote; + if (emote == null || emote.isEmpty) { + return const SizedBox.shrink(); + } + final flag = emote.first.meta?.size == 1; + final size = flag ? 40.0 : 60.0; + final isTextEmote = e.type == 4; return GridView.builder( padding: const EdgeInsets.only( left: 12, @@ -73,21 +76,21 @@ class _EmotePanelState extends State mainAxisSpacing: 8, mainAxisExtent: size, ), - itemCount: e.emote!.length, + itemCount: emote.length, itemBuilder: (context, index) { - final item = e.emote![index]; + final item = emote[index]; Widget child = Padding( padding: const EdgeInsets.all(6), child: isTextEmote ? Center( child: Text( - item.text!, + item.text ?? '', overflow: TextOverflow.clip, maxLines: 1, ), ) : NetworkImgLayer( - src: item.url!, + src: item.url, width: size, height: size, type: ImageType.emote, @@ -113,7 +116,7 @@ class _EmotePanelState extends State mainAxisSize: MainAxisSize.min, children: [ NetworkImgLayer( - src: item.url!, + src: item.url, width: 65, height: 65, type: ImageType.emote, @@ -121,10 +124,11 @@ class _EmotePanelState extends State ), Text( item.meta?.alias ?? - item.text!.substring( + item.text?.substring( 1, item.text!.length - 1, - ), + ) ?? + '', style: const TextStyle(fontSize: 12), ), ], @@ -143,7 +147,7 @@ class _EmotePanelState extends State item, isTextEmote ? null - : e.emote!.first.meta!.size == 1 + : flag ? 24 : 42, null, @@ -211,9 +215,7 @@ class _EmotePanelState extends State ), ], ), - SizedBox( - height: MediaQuery.viewPaddingOf(context).bottom, - ), + SizedBox(height: MediaQuery.viewPaddingOf(context).bottom), ], ) : _errorWidget(), diff --git a/lib/pages/live_emote/view.dart b/lib/pages/live_emote/view.dart index 5f9f9690..fcc4cae7 100644 --- a/lib/pages/live_emote/view.dart +++ b/lib/pages/live_emote/view.dart @@ -9,7 +9,6 @@ import 'package:PiliPlus/models/common/image_type.dart'; import 'package:PiliPlus/models_new/live/live_emote/datum.dart'; import 'package:PiliPlus/models_new/live/live_emote/emoticon.dart'; import 'package:PiliPlus/pages/live_emote/controller.dart'; -import 'package:PiliPlus/utils/extension.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -45,7 +44,8 @@ class _LiveEmotePanelState extends State } Widget _buildBody(LoadingState?> loadingState) { - late final color = Theme.of(context).colorScheme.onInverseSurface; + late final theme = Theme.of(context); + late final color = theme.colorScheme.onInverseSurface; return switch (loadingState) { Loading() => loadingWidget, Success(:var response) => @@ -57,17 +57,17 @@ class _LiveEmotePanelState extends State controller: _emotePanelController.tabController, children: response!.map( (item) { - if (item.emoticons.isNullOrEmpty) { + final emote = item.emoticons; + if (emote == null || emote.isEmpty) { return const SizedBox.shrink(); } - double widthFac = max( - 1, - item.emoticons!.first.width! / 80, - ); - double heightFac = max( - 1, - item.emoticons!.first.height! / 80, - ); + final first = emote.first; + final widthFac = first.width == null + ? 1.0 + : max(1.0, first.width! / 80); + final heightFac = first.height == null + ? 1.0 + : max(1.0, first.height! / 80); final width = widthFac * 38; final height = heightFac * 38; return GridView.builder( @@ -83,9 +83,9 @@ class _LiveEmotePanelState extends State crossAxisSpacing: 8, mainAxisSpacing: 8, ), - itemCount: item.emoticons!.length, + itemCount: emote.length, itemBuilder: (context, index) { - final e = item.emoticons![index]; + final e = emote[index]; return Material( type: MaterialType.transparency, child: InkWell( @@ -117,14 +117,16 @@ class _LiveEmotePanelState extends State mainAxisSize: MainAxisSize.min, children: [ NetworkImgLayer( - src: e.url!, + src: e.url, width: 65, height: 65, type: ImageType.emote, boxFit: BoxFit.contain, ), Text( - e.emoji!.startsWith('[') + e.emoji == null + ? '' + : e.emoji!.startsWith('[') ? e.emoji!.substring( 1, e.emoji!.length - 1, @@ -141,7 +143,7 @@ class _LiveEmotePanelState extends State padding: const EdgeInsets.all(6), child: NetworkImgLayer( boxFit: BoxFit.contain, - src: e.url!, + src: e.url, width: width, height: height, type: ImageType.emote, @@ -159,9 +161,7 @@ class _LiveEmotePanelState extends State ), Divider( height: 1, - color: Theme.of( - context, - ).dividerColor.withValues(alpha: 0.1), + color: theme.dividerColor.withValues(alpha: 0.1), ), TabBar( controller: _emotePanelController.tabController, @@ -183,9 +183,7 @@ class _LiveEmotePanelState extends State ) .toList(), ), - SizedBox( - height: MediaQuery.viewPaddingOf(context).bottom, - ), + SizedBox(height: MediaQuery.viewPaddingOf(context).bottom), ], ) : _errorWidget(),