fix(flutter): 修复详情页首帧闪屏
This commit is contained in:
1 parent
a11ba50b13
commit
bb92996db5
4 files changed
+390
-13
No files matched your search
@@ -28,6 +28,7 @@ import 'drama_detail_logic.dart';
|
||||
import 'widgets/drama_detail_bottom_bar.dart';
|
||||
import 'widgets/drama_detail_header.dart';
|
||||
import 'widgets/drama_detail_sections.dart';
|
||||
import 'widgets/drama_episode_states.dart';
|
||||
|
||||
const String _menuFavorite = 'favorite';
|
||||
const String _menuDownload = 'download';
|
||||
@@ -93,17 +94,23 @@ class _DramaDetailPageState extends State<DramaDetailPage> {
|
||||
|
||||
Widget _page(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
if (logic.loading) return _loading(l10n);
|
||||
if (logic.failed) return _failed(l10n);
|
||||
final drama = logic.drama;
|
||||
if (drama.episodes.isEmpty) return _empty(l10n, drama);
|
||||
final hasCardContent =
|
||||
drama.title.trim().isNotEmpty || drama.posterUrl.trim().isNotEmpty;
|
||||
if (!hasCardContent && logic.loading) return _loading(l10n);
|
||||
if (!hasCardContent && logic.failed) return _failed(l10n);
|
||||
if (drama.episodes.isEmpty && !logic.loading && !logic.failed) {
|
||||
return _empty(l10n, drama);
|
||||
}
|
||||
final saved = context.watch<FavoriteController>().isSaved(drama.id);
|
||||
final continueIndex = logic.continueIndex;
|
||||
final episodesReady = drama.detailLoaded && drama.episodes.isNotEmpty;
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.ink,
|
||||
bottomNavigationBar: DramaDetailBottomBar(
|
||||
l10n: l10n,
|
||||
continueIndex: continueIndex,
|
||||
continueIndex: episodesReady ? continueIndex : null,
|
||||
enabled: episodesReady,
|
||||
onPlay: () => logic.openPlayer(context, continueIndex ?? 0),
|
||||
resume: _resume(l10n),
|
||||
),
|
||||
@@ -134,20 +141,32 @@ class _DramaDetailPageState extends State<DramaDetailPage> {
|
||||
),
|
||||
if (_tagValues(drama).isNotEmpty)
|
||||
SliverToBoxAdapter(child: DramaTags(tags: _tagValues(drama))),
|
||||
SliverToBoxAdapter(
|
||||
child: DramaEpisodeGrid(
|
||||
l10n: l10n,
|
||||
drama: drama,
|
||||
continueIndex: continueIndex,
|
||||
onOpen: (index) => logic.openPlayer(context, index),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(child: _episodes(l10n, drama, continueIndex)),
|
||||
const SliverToBoxAdapter(child: SizedBox(height: 24)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _episodes(AppLocalizations l10n, Drama drama, int? continueIndex) {
|
||||
if (!drama.detailLoaded && logic.failed) {
|
||||
return DramaEpisodesLoadError(
|
||||
l10n: l10n,
|
||||
message: logic.failureMessage,
|
||||
onRetry: _load,
|
||||
);
|
||||
}
|
||||
if (!drama.detailLoaded && logic.loading && drama.episodes.isEmpty) {
|
||||
return DramaEpisodesLoading(l10n: l10n, episodeCount: drama.episodeCount);
|
||||
}
|
||||
return DramaEpisodeGrid(
|
||||
l10n: l10n,
|
||||
drama: drama,
|
||||
continueIndex: continueIndex,
|
||||
onOpen: (index) => logic.openPlayer(context, index),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _loading(AppLocalizations l10n) => _statePage(
|
||||
localizedDramaTitle(l10n, widget.drama),
|
||||
const Center(child: CircularProgressIndicator()),
|
||||
|
||||
Reference in new issue
Block a user