Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

fix(character): redesign M3E details sheet and restore character info

Predidit66d8483c0176
diff --git a/lib/bean/card/character_card.dart b/lib/bean/card/character_card.dart
index 0ca23afe..c8821769 100644
--- a/lib/bean/card/character_card.dart
+++ b/lib/bean/card/character_card.dart
@@ -35,6 +35,11 @@ class CharacterCard extends StatelessWidget {
characterID: characterItem.id,
characterName: characterItem.name,
characterRelation: characterItem.relation,
+ actorNames: characterItem.actorList
+ .map((actor) => actor.name.trim())
+ .where((name) => name.isNotEmpty)
+ .toSet()
+ .toList(),
);
},
);
diff --git a/lib/modules/character/character_full_item.dart b/lib/modules/character/character_full_item.dart
index c9d2fed6..3406b8f2 100644
--- a/lib/modules/character/character_full_item.dart
+++ b/lib/modules/character/character_full_item.dart
@@ -1,4 +1,3 @@
-/// One `key: value` row of a character's infobox, e.g. `性别: 男`.
class CharacterInfoField {
final String key;
final String value;
@@ -14,25 +13,52 @@ class CharacterFullItem {
final List<CharacterInfoField> infobox;
final String summary;
final String image;
+ final String name;
+ final String nameCn;
+ final String unstructuredInfo;
- CharacterFullItem({
+ CharacterFullItem._({
required this.id,
required this.infobox,
required this.summary,
required this.image,
+ this.name = '',
+ this.nameCn = '',
+ this.unstructuredInfo = '',
});
factory CharacterFullItem.fromJson(Map<String, dynamic> json) {
- return CharacterFullItem(
+ var fields = _parseInfobox(json['infobox']);
+ var unstructuredInfo = '';
+ if (fields.isEmpty) {
+ (fields, unstructuredInfo) = _parseInfo(_text(json['info']));
+ }
+ var nameCn = _text(json['nameCN'] ?? json['name_cn']);
+ if (nameCn.isEmpty) {
+ nameCn = fields
+ .where((field) => field.key == '简体中文名')
+ .map((field) => field.value)
+ .firstOrNull ??
+ '';
+ }
+ final images = json['images'];
+ return CharacterFullItem._(
id: json['id'] ?? 0,
- infobox: _parseInfobox(json['infobox']),
- summary: json['summary'] ?? '',
- image: json['images']['large'] ?? '',
+ infobox: List.unmodifiable(fields),
+ summary: _text(json['summary']),
+ image: images is Map
+ ? ['large', 'medium', 'small']
+ .map((size) => _text(images[size]))
+ .firstWhere((url) => url.isNotEmpty, orElse: () => '')
+ : '',
+ name: _text(json['name']),
+ nameCn: nameCn,
+ unstructuredInfo: unstructuredInfo,
);
}
factory CharacterFullItem.fromTemplate() {
- return CharacterFullItem(
+ return CharacterFullItem._(
id: 0,
infobox: const [],
summary: '',
@@ -40,25 +66,49 @@ class CharacterFullItem {
);
}
- /// Entries arrive as `{key, values: [{v, k?}]}`. Rows whose values are all
- /// blank are common — the wiki template ships empty slots — and are dropped.
- static List<CharacterInfoField> _parseInfobox(dynamic raw) {
+ static String _text(Object? value) =>
+ value is String || value is num ? value.toString().trim() : '';
+
+ // /p1 uses `values`; /v0 uses `value`, including labeled aliases.
+ static List<CharacterInfoField> _parseInfobox(Object? raw) {
if (raw is! List) return const [];
final fields = <CharacterInfoField>[];
for (final entry in raw) {
if (entry is! Map) continue;
- final key = (entry['key'] ?? '').toString().trim();
- final values = entry['values'];
- if (key.isEmpty || values is! List) continue;
+ final key = _text(entry['key']);
+ final rawValues = entry['values'] ?? entry['value'];
+ if (key.isEmpty) continue;
+ final values = rawValues is List ? rawValues : [rawValues];
final parts = <String>[];
for (final value in values) {
- if (value is! Map) continue;
- final text = (value['v'] ?? '').toString().trim();
- if (text.isNotEmpty) parts.add(text);
+ final text = _text(value is Map ? value['v'] : value);
+ if (text.isEmpty) continue;
+ final label = value is Map ? _text(value['k']) : '';
+ parts.add(label.isEmpty ? text : '$label:$text');
}
if (parts.isEmpty) continue;
fields.add(CharacterInfoField(key: key, value: parts.join(' / ')));
}
return fields;
}
+
+ // The mirror replaces infobox with text; preserve lines without a field key.
+ static (List<CharacterInfoField>, String) _parseInfo(String info) {
+ final fields = <CharacterInfoField>[];
+ final remaining = <String>[];
+ for (final line in info.split(RegExp(r'\r?\n'))) {
+ if (line.trim().isEmpty) continue;
+ final separator = line.indexOf(RegExp('[::]'));
+ if (separator < 1) {
+ remaining.add(line.trim());
+ continue;
+ }
+ final key = line.substring(0, separator).trim();
+ final value = line.substring(separator + 1).trim();
+ if (key.isNotEmpty && value.isNotEmpty) {
+ fields.add(CharacterInfoField(key: key, value: value));
+ }
+ }
+ return (fields, remaining.join('\n'));
+ }
}
diff --git a/lib/pages/info/character_info_view.dart b/lib/pages/info/character_info_view.dart
new file mode 100644
index 00000000..9599011e
--- /dev/null
+++ b/lib/pages/info/character_info_view.dart
@@ -0,0 +1,324 @@
+import 'package:cached_network_image/cached_network_image.dart';
+import 'package:flutter/material.dart';
+
+import 'package:kazumi/bean/dialog/material_bottom_sheet.dart';
+import 'package:kazumi/bean/widget/content_section.dart';
+import 'package:kazumi/bean/widget/image_preview.dart';
+import 'package:kazumi/bean/widget/tonal_card.dart';
+import 'package:kazumi/modules/character/character_full_item.dart';
+import 'package:kazumi/utils/image_extension.dart';
+
+class CharacterInfoView extends StatelessWidget {
+ const CharacterInfoView({
+ super.key,
+ required this.character,
+ required this.characterName,
+ required this.characterRelation,
+ this.actorNames = const [],
+ });
+
+ final CharacterFullItem character;
+ final String characterName;
+ final String characterRelation;
+ final List<String> actorNames;
+
+ static const _quickKeys = {'性别', '生日', '年龄', '身高', '体重', '血型'};
+
+ @override
+ Widget build(BuildContext context) {
+ final theme = Theme.of(context);
+ final fields =
+ character.infobox.where((field) => field.key != '引用来源').toList();
+ final quickFields = fields
+ .where((field) => _quickKeys.contains(field.key))
+ .take(4)
+ .toList();
+ final moreFields = fields
+ .where((field) => field.key != '简体中文名' && !quickFields.contains(field))
+ .toList();
+ final tappedName = characterName.trim();
+ final originalName =
+ character.name.isNotEmpty ? character.name : tappedName;
+ final name = character.nameCn.isNotEmpty
+ ? character.nameCn
+ : tappedName.isNotEmpty
+ ? tappedName
+ : originalName;
+ final useCompactColumns = MediaQuery.textScalerOf(context).scale(14) <= 20;
+ final relation = characterRelation.trim();
+
+ final profile = Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ TonalCard(
+ padding: const EdgeInsets.all(20),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ if (relation.isNotEmpty && relation != '未知') ...[
+ Container(
+ padding:
+ const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
+ decoration: ShapeDecoration(
+ color: theme.colorScheme.secondaryContainer,
+ shape: const StadiumBorder(),
+ ),
+ child: Text(relation,
+ style: theme.textTheme.labelLarge?.copyWith(
+ color: theme.colorScheme.onSecondaryContainer,
+ )),
+ ),
+ const SizedBox(height: 12),
+ ],
+ SelectableText(
+ name.isEmpty ? '人物' : name,
+ style: theme.textTheme.headlineSmall?.copyWith(
+ fontWeight: FontWeight.w700,
+ color: theme.colorScheme.onSurface,
+ ),
+ ),
+ if (originalName.isNotEmpty && originalName != name) ...[
+ const SizedBox(height: 8),
+ SelectableText(originalName,
+ style: theme.textTheme.bodyMedium?.copyWith(
+ color: theme.colorScheme.onSurfaceVariant,
+ )),
+ ],
+ if (actorNames.isNotEmpty) ...[
+ const SizedBox(height: 20),
+ _buildInfoField(context, '配音', actorNames.join(' / ')),
+ ],
+ ],
+ ),
+ ),
+ if (quickFields.isNotEmpty) ...[
+ const SizedBox(height: 16),
+ ContentSection(
+ title: '基本资料',
+ child: LayoutBuilder(builder: (context, constraints) {
+ final columns =
+ constraints.maxWidth >= 240 && useCompactColumns ? 2 : 1;
+ return Wrap(
+ spacing: 16,
+ runSpacing: 16,
+ children: [
+ for (final field in quickFields)
+ SizedBox(
+ width:
+ (constraints.maxWidth - 16 * (columns - 1)) / columns,
+ child: _buildInfoField(context, field.key, field.value),
+ ),
+ ],
+ );
+ }),
+ ),
+ ],
+ ],
+ );
+
+ return SingleChildScrollView(
+ key: const PageStorageKey('character-info'),
+ padding: materialBottomSheetContentPadding,
+ child: LayoutBuilder(builder: (context, constraints) {
+ final sideBySide = constraints.maxWidth >= 480 && useCompactColumns;
+ final portraitWidth =
+ sideBySide ? constraints.maxWidth * 0.40 : constraints.maxWidth;
+ final screenHeight = MediaQuery.sizeOf(context).height;
+ final portraitHeight = sideBySide
+ ? (screenHeight * 0.42).clamp(240.0, 400.0)
+ : (screenHeight * 0.30).clamp(200.0, 300.0);
+ final portrait = _CharacterPortrait(
+ imageUrl: character.image,
+ width: portraitWidth,
+ height: portraitHeight,
+ );
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ if (sideBySide)
+ Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SizedBox(width: portraitWidth, child: portrait),
+ const SizedBox(width: 16),
+ Expanded(child: profile),
+ ],
+ )
+ else ...[
+ portrait,
+ const SizedBox(height: 16),
+ profile,
+ ],
+ if (character.summary.isNotEmpty) ...[
+ const SizedBox(height: 24),
+ ContentSection(
+ title: '人物简介',
+ child: SelectableText(character.summary,
+ style: theme.textTheme.bodyLarge?.copyWith(height: 1.65)),
+ ),
+ ],
+ if (moreFields.isNotEmpty) ...[
+ const SizedBox(height: 24),
+ ContentSection.group(
+ title: '更多资料',
+ children: [
+ for (final field in moreFields)
+ Padding(
+ padding: const EdgeInsets.all(16),
+ child: _buildInfoField(context, field.key, field.value),
+ ),
+ ],
+ ),
+ ],
+ if (character.unstructuredInfo.isNotEmpty) ...[
+ const SizedBox(height: 24),
+ ContentSection(
+ title: '人物资料',
+ child: SelectableText(character.unstructuredInfo,
+ style: theme.textTheme.bodyMedium?.copyWith(height: 1.6)),
+ ),
+ ],
+ if (fields.isEmpty &&
+ character.unstructuredInfo.isEmpty &&
+ character.summary.isEmpty) ...[
+ const SizedBox(height: 24),
+ TonalCard(
+ padding: const EdgeInsets.all(20),
+ child: Text('这个人物还没有补充资料',
+ style: theme.textTheme.bodyMedium?.copyWith(
+ color: theme.colorScheme.onSurfaceVariant,
+ )),
+ ),
+ ],
+ ],
+ );
+ }),
+ );
+ }
+}
+
+Widget _buildInfoField(BuildContext context, String label, String value) {
+ final theme = Theme.of(context);
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(label,
+ style: theme.textTheme.labelLarge?.copyWith(
+ color: theme.colorScheme.onSurfaceVariant,
+ )),
+ const SizedBox(height: 4),
+ SelectableText(value,
+ style: theme.textTheme.bodyLarge?.copyWith(height: 1.5)),
+ ],
+ );
+}
+
+class _CharacterPortrait extends StatelessWidget {
+ const _CharacterPortrait({
+ required this.imageUrl,
+ required this.width,
+ required this.height,
+ });
+
+ final String imageUrl;
+ final double width;
+ final double height;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = Theme.of(context).colorScheme;
+ if (imageUrl.isEmpty) {
+ return TonalCard(
+ child: SizedBox(
+ height: 160,
+ child: _imageMessage(context, Icons.person_outline_rounded, '暂无人物图片'),
+ ),
+ );
+ }
+ final heroTag = ImageViewer.heroTagFor(imageUrl, 0);
+
+ return Semantics(
+ button: true,
+ label: '查看人物原图',
+ child: Material(
+ color: colors.surfaceContainerLow,
+ borderRadius: BorderRadius.circular(28),
+ clipBehavior: Clip.antiAlias,
+ child: InkWell(
+ onTap: () => ImageViewer.show(
+ context,
+ imageUrls: [imageUrl],
+ heroTag: heroTag,
+ ),
+ child: Column(
+ children: [
+ Padding(
+ padding: const EdgeInsets.fromLTRB(12, 12, 12, 0),
+ child: Hero(
+ tag: heroTag,
+ child: CachedNetworkImage(
+ imageUrl: imageUrl,
+ width: width - 24,
+ height: height,
+ // Single-axis decoding and contain preserve extreme aspect ratios.
+ memCacheHeight: height.cacheSize(context),
+ fit: BoxFit.contain,
+ fadeInDuration: const Duration(milliseconds: 120),
+ fadeOutDuration: const Duration(milliseconds: 120),
+ placeholder: (context, _) => Center(
+ child: CircularProgressIndicator(
+ strokeWidth: 2,
+ semanticsLabel: '正在加载人物图片',
+ ),
+ ),
+ errorWidget: (context, url, error) => _imageMessage(
+ context, Icons.broken_image_outlined, '图片加载失败'),
+ ),
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.all(16),
+ child: ExcludeSemantics(
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Icon(Icons.zoom_in_rounded,
+ size: 20, color: colors.primary),
+ const SizedBox(width: 8),
+ Flexible(
+ child: Text('查看原图',
+ style: Theme.of(context)
+ .textTheme
+ .labelLarge
+ ?.copyWith(color: colors.primary)),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+
+ Widget _imageMessage(BuildContext context, IconData icon, String message) {
+ final colors = Theme.of(context).colorScheme;
+ return Center(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(icon, size: 32, color: colors.onSurfaceVariant),
+ const SizedBox(height: 8),
+ Text(message,
+ style: Theme.of(context)
+ .textTheme
+ .bodyMedium
+ ?.copyWith(color: colors.onSurfaceVariant)),
+ ],
+ ),
+ );
+ }
+}
diff --git a/lib/pages/info/character_page.dart b/lib/pages/info/character_page.dart
index 8a7e50ea..bb476c94 100644
--- a/lib/pages/info/character_page.dart
+++ b/lib/pages/info/character_page.dart
@@ -3,20 +3,14 @@ import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:skeletonizer/skeletonizer.dart';
-import 'package:kazumi/bean/card/network_img_layer.dart';
import 'package:kazumi/bean/card/user_comments_card.dart';
import 'package:kazumi/bean/dialog/material_bottom_sheet.dart';
import 'package:kazumi/bean/widget/connected_tabs.dart';
-import 'package:kazumi/bean/widget/content_section.dart';
import 'package:kazumi/bean/widget/error_widget.dart';
-import 'package:kazumi/bean/widget/image_preview.dart';
-import 'package:kazumi/bean/widget/tonal_card.dart';
import 'package:kazumi/modules/character/character_full_item.dart';
import 'package:kazumi/modules/comments/comment_item.dart';
+import 'package:kazumi/pages/info/character_info_view.dart';
import 'package:kazumi/request/apis/bangumi_api.dart';
-import 'package:kazumi/utils/constants.dart';
-
-const Set<String> _hiddenInfoKeys = {'引用来源'};
class CharacterPage extends StatefulWidget {
const CharacterPage({
@@ -24,56 +18,55 @@ class CharacterPage extends StatefulWidget {
required this.characterID,
required this.characterName,
required this.characterRelation,
+ this.actorNames = const [],
});
final int characterID;
-
- // Use the tapped name to keep the header height stable while loading.
final String characterName;
final String characterRelation;
+ final List<String> actorNames;
@override
State<CharacterPage> createState() => _CharacterPageState();
}
class _CharacterPageState extends State<CharacterPage> {
- CharacterFullItem? characterFullItem;
- List<CharacterCommentItem> commentsList = [];
- bool loadingComments = true;
- bool commentsError = false;
+ CharacterFullItem? _character;
+ List<CharacterCommentItem> _comments = [];
+ bool _loadingComments = true;
+ bool _commentsError = false;
- Future<void> loadCharacter() async {
+ Future<void> _loadCharacter() async {
setState(() {
- characterFullItem = null;
+ _character = null;
});
final character =
await BangumiApi.getCharacterByCharacterID(widget.characterID);
if (mounted) {
setState(() {
- characterFullItem = character;
+ _character = character;
});
}
}
- Future<void> loadComments() async {
+ Future<void> _loadComments() async {
setState(() {
- loadingComments = true;
- commentsError = false;
+ _loadingComments = true;
+ _commentsError = false;
});
try {
- final value = await BangumiApi.getCharacterCommentsByCharacterID(
+ final response = await BangumiApi.getCharacterCommentsByCharacterID(
widget.characterID);
- commentsList = value.commentList;
- } catch (e) {
- if (mounted) {
- setState(() {
- commentsError = true;
- });
- }
- }
- if (mounted) {
+ if (!mounted) return;
setState(() {
- loadingComments = false;
+ _comments = response.commentList;
+ _loadingComments = false;
+ });
+ } catch (_) {
+ if (!mounted) return;
+ setState(() {
+ _commentsError = true;
+ _loadingComments = false;
});
}
}
@@ -82,13 +75,15 @@ class _CharacterPageState extends State<CharacterPage> {
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
- loadCharacter();
- loadComments();
+ if (!mounted) return;
+ _loadCharacter();
+ _loadComments();
});
}
@override
Widget build(BuildContext context) {
+ final name = widget.characterName.trim();
return DefaultTabController(
length: 2,
child: Scaffold(
@@ -96,8 +91,7 @@ class _CharacterPageState extends State<CharacterPage> {
body: Column(
children: [
MaterialBottomSheetHeader(
- title: _headerTitle,
- description: _headerDescription,
+ title: name.isEmpty ? '人物' : name,
onClose: () => Navigator.of(context).pop(),
),
const ConnectedTabs(
@@ -106,7 +100,7 @@ class _CharacterPageState extends State<CharacterPage> {
),
Expanded(
child: TabBarView(
- children: [characterInfoBody, characterCommentsBody],
+ children: [_characterInfoBody, _characterCommentsBody],
),
),
],
@@ -115,25 +109,14 @@ class _CharacterPageState extends State<CharacterPage> {
);
}
- String get _headerTitle {
- final name = widget.characterName.trim();
- return name.isEmpty ? '人物' : name;
- }
-
- String? get _headerDescription {
- final relation = widget.characterRelation.trim();
- if (relation.isEmpty || relation == '未知') return null;
- return relation;
- }
-
- Widget get characterInfoBody {
- final character = characterFullItem;
+ Widget get _characterInfoBody {
+ final character = _character;
if (character != null && character.id == 0) {
return GeneralErrorWidget(
- errMsg: '什么都没有找到 (´;ω;`)',
+ errMsg: '人物资料加载失败',
actions: [
GeneralErrorButton(
- onPressed: loadCharacter,
+ onPressed: _loadCharacter,
text: '点击重试',
),
],
@@ -147,143 +130,22 @@ class _CharacterPageState extends State<CharacterPage> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
- Bone(height: 180, width: 120, uniRadius: 16),
+ Bone(height: 300, width: double.infinity, uniRadius: 28),
SizedBox(height: 24),
Bone.multiText(lines: 5),
],
)),
);
}
- final fields = character.infobox
- .where((f) => !_hiddenInfoKeys.contains(f.key))
- .toList();
- return SingleChildScrollView(
- padding: materialBottomSheetContentPadding,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- TonalCard(
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _buildPortrait(context, character, 104, 176),
- const SizedBox(width: 20),
- Expanded(
- child: SelectionArea(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- for (final field in fields.take(3)) ...[
- _buildBlock(context, field),
- const SizedBox(height: 12),
- ],
- if (fields.isEmpty)
- Text('暂无资料',
- style: Theme.of(context).textTheme.bodyMedium),
- ],
- ))),
- ],
- ),
- ),
- ),
- if (character.summary.trim().isNotEmpty) ...[
- const SizedBox(height: 24),
- ContentSection(
- title: '简介',
- child: SelectableText(character.summary.trim(),
- style: Theme.of(context)
- .textTheme
- .bodyMedium
- ?.copyWith(height: 1.6)),
- ),
- ],
- if (fields.length > 3) ...[
- const SizedBox(height: 24),
- ContentSection(
- title: '更多资料',
- child: SelectionArea(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- for (final field in fields.skip(3)) ...[
- _buildBlock(context, field),
- const SizedBox(height: 16),
- ],
- ],
- )),
- ),
- ],
- ],
- ),
+ return CharacterInfoView(
+ character: character,
+ characterName: widget.characterName,
+ characterRelation: widget.characterRelation,
+ actorNames: widget.actorNames,
);
}
- Widget _buildPortrait(
- BuildContext context,
- CharacterFullItem character,
- double width,
- double height,
- ) {
- final heroTag = ImageViewer.heroTagFor(character.image, 0);
-
- return Semantics(
- button: true,
- label: '查看人物图片',
- child: Tooltip(
- message: '查看原图',
- child: Material(
- color: Theme.of(context).colorScheme.surface,
- borderRadius: const BorderRadius.all(StyleString.imgRadius),
- clipBehavior: Clip.antiAlias,
- child: InkWell(
- onTap: () => ImageViewer.show(
- context,
- imageUrls: [character.image],
- heroTag: heroTag,
- ),
- child: Hero(
- tag: heroTag,
- child: NetworkImgLayer(
- width: width,
- height: height,
- src: character.image,
- ),
- ),
- ),
- ),
- ),
- );
- }
-
- Widget _buildBlock(BuildContext context, CharacterInfoField field) {
- final theme = Theme.of(context);
- final colorScheme = theme.colorScheme;
-
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- field.key,
- style: theme.textTheme.titleSmall?.copyWith(
- color: colorScheme.primary,
- fontWeight: FontWeight.w600,
- ),
- ),
- const SizedBox(height: 4),
- Text(
- field.value,
- style: theme.textTheme.bodyMedium?.copyWith(
- color: colorScheme.onSurface,
- height: 1.6,
- ),
- ),
- ],
- );
- }
-
- Widget get characterCommentsBody {
+ Widget get _characterCommentsBody {
return CustomScrollView(
scrollBehavior: const ScrollBehavior().copyWith(
scrollbars: false,
@@ -295,56 +157,56 @@ class _CharacterPageState extends State<CharacterPage> {
slivers: [
SliverPadding(
padding: materialBottomSheetContentPadding,
- sliver: Builder(builder: (context) {
- if (loadingComments) {
- return SliverList.builder(
- itemCount: 3,
- itemBuilder: (context, _) => const UserCommentsCardBone(),
- );
- }
- if (commentsError) {
- return SliverFillRemaining(
- child: GeneralErrorWidget(
- errMsg: '什么都没有找到 (´;ω;`)',
- actions: [
- GeneralErrorButton(
- onPressed: () {
- loadComments();
- },
- text: '点击重试',
- ),
- ],
- ),
- );
- }
- if (commentsList.isEmpty) {
- return const SliverFillRemaining(
- child: Center(
- child: Text('什么都没有找到 (´;ω;`)'),
- ),
- );
- }
- return SliverList(
- delegate: SliverChildBuilderDelegate(
- (context, index) {
- // Keep loaded images alive to prevent scroll jumps.
- return KeepAlive(
- keepAlive: true,
- child: IndexedSemantics(
- index: index,
- child: UserCommentsCard.character(commentsList[index]),
- ),
- );
- },
- childCount: commentsList.length,
- addAutomaticKeepAlives: false,
- addRepaintBoundaries: false,
- addSemanticIndexes: false,
- ),
- );
- }),
+ sliver: _commentsSliver,
),
],
);
}
+
+ Widget get _commentsSliver {
+ if (_loadingComments) {
+ return SliverList.builder(
+ itemCount: 3,
+ itemBuilder: (context, _) => const UserCommentsCardBone(),
+ );
+ }
+ if (_commentsError) {
+ return SliverFillRemaining(
+ child: GeneralErrorWidget(
+ errMsg: '什么都没有找到 (´;ω;`)',
+ actions: [
+ GeneralErrorButton(
+ onPressed: _loadComments,
+ text: '点击重试',
+ ),
+ ],
+ ),
+ );
+ }
+ if (_comments.isEmpty) {
+ return const SliverFillRemaining(
+ child: Center(
+ child: Text('什么都没有找到 (´;ω;`)'),
+ ),
+ );
+ }
+ return SliverList(
+ delegate: SliverChildBuilderDelegate(
+ (context, index) {
+ // Keep loaded images alive to prevent scroll jumps.
+ return KeepAlive(
+ keepAlive: true,
+ child: IndexedSemantics(
+ index: index,
+ child: UserCommentsCard.character(_comments[index]),
+ ),
+ );
+ },
+ childCount: _comments.length,
+ addAutomaticKeepAlives: false,
+ addRepaintBoundaries: false,
+ addSemanticIndexes: false,
+ ),
+ );
+ }
}