feat(app): 接入首页轮播 banner
This commit is contained in:
1 parent
061aac6577
commit
7b927c794e
7 files changed
+469
-37
No files matched your search
@@ -7,6 +7,8 @@ import '../../core/data/models/drama.dart';
|
||||
import '../../core/data/services/catalog_controller.dart';
|
||||
import '../../core/data/services/download_controller.dart';
|
||||
import '../../core/data/services/wallet_controller.dart';
|
||||
import '../../core/data/repositories/catalog_repository.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../discover/discover_logic.dart';
|
||||
import '../drama_detail/drama_detail_view.dart';
|
||||
import '../mine/mine_logic.dart';
|
||||
@@ -85,6 +87,20 @@ class HomeLogic extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
/// Resolves a banner link that is not in the loaded feed, then opens detail.
|
||||
Future<void> openDramaById(BuildContext context, String dramaId) async {
|
||||
try {
|
||||
final drama = await context.read<CatalogRepository>().fetchDrama(dramaId);
|
||||
if (context.mounted) openDrama(context, drama);
|
||||
} catch (_) {
|
||||
if (!context.mounted) return;
|
||||
final message = AppLocalizations.of(context)!.detailLoadFailed;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> playDrama(BuildContext context, Drama drama) async {
|
||||
// 列表卡片只有一集预览,进入播放前补齐完整剧集,否则选集列表是空的。
|
||||
var playable = drama;
|
||||
|
||||
@@ -76,6 +76,7 @@ class HomePage extends StatelessWidget {
|
||||
key: ValueKey(catalog.dramas.first.id),
|
||||
dramas: catalog.dramas,
|
||||
sections: catalog.sections,
|
||||
banners: catalog.banners,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -100,10 +101,16 @@ class HomeFailureView extends StatelessWidget {
|
||||
|
||||
/// The three primary destinations share a single route and keep their state.
|
||||
class _HomeTabs extends StatefulWidget {
|
||||
const _HomeTabs({super.key, required this.dramas, required this.sections});
|
||||
const _HomeTabs({
|
||||
super.key,
|
||||
required this.dramas,
|
||||
required this.sections,
|
||||
required this.banners,
|
||||
});
|
||||
|
||||
final List<Drama> dramas;
|
||||
final List<FeedSection> sections;
|
||||
final List<FeedBanner> banners;
|
||||
|
||||
@override
|
||||
State<_HomeTabs> createState() => _HomeTabsState();
|
||||
@@ -182,6 +189,13 @@ class _HomeTabsState extends State<_HomeTabs> {
|
||||
onSignIn: () => openAuthPage(context),
|
||||
onCoins: logic.openProfile,
|
||||
onRewards: logic.openProfile,
|
||||
banners: widget.banners,
|
||||
onBannerSelected: (banner) {
|
||||
final dramaId = banner.dramaId;
|
||||
if (dramaId != null) {
|
||||
unawaited(logic.openDramaById(context, dramaId));
|
||||
}
|
||||
},
|
||||
onAction: (action) => logic.discoverAction(context, action),
|
||||
),
|
||||
MyPage(
|
||||
|
||||
Reference in new issue
Block a user