142 lines
4.0 KiB
Dart
142 lines
4.0 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:hgdj/hj_page/short_video/short_main_video_page.dart';
|
||
import 'package:hgdj/tools_base/widget/lazy_indexed_stack.dart';
|
||
|
||
import '../../alert/vip_guide/guide_push_banner.dart';
|
||
import '../../config/config.dart';
|
||
import '../../main.dart';
|
||
import '../ai/ai_home_page.dart';
|
||
import '../community/community_main_page_page/community_main_page.dart';
|
||
import '../home/dark_home_page.dart';
|
||
import '../home/home_main_page.dart';
|
||
import '../home/widget/home_txt_marquee.dart';
|
||
import '../mine/home_mine_page.dart';
|
||
import 'drama_tip_bubble.dart';
|
||
import 'main_logic.dart';
|
||
import 'main_tabbar.dart';
|
||
|
||
class MainPage extends StatefulWidget {
|
||
static const routeName = '/MainPage';
|
||
|
||
const MainPage({super.key});
|
||
|
||
@override
|
||
State<MainPage> createState() => _MainPageState();
|
||
}
|
||
|
||
class _MainPageState extends State<MainPage> with RouteAware {
|
||
// 懒加载:MainPage 可能在 binding 未跑时就被构造,
|
||
// 用 getter 让 logic 只在 build 访问时才 Get.find,避免构造期 not found 崩溃
|
||
MainPageLogic get logic => Get.find<MainPageLogic>();
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
GuidePushBanner.start(); //进 app 满3分钟后开始推 VIP「特享内容」横幅
|
||
DramaTipBubble.start(); //「AI爽剧来袭」引导气泡,装机维度只亮一次
|
||
}
|
||
|
||
@override
|
||
void didChangeDependencies() {
|
||
super.didChangeDependencies();
|
||
final route = ModalRoute.of(context);
|
||
if (route != null) routeObserver.subscribe(this, route);
|
||
}
|
||
|
||
/// 二级页面/弹窗关闭回到本页:满3分钟后每次都拉一次「特享内容」,有数据就弹横幅
|
||
@override
|
||
void didPopNext() {
|
||
super.didPopNext();
|
||
GuidePushBanner.onBackToMainPage();
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
routeObserver.unsubscribe(this);
|
||
GuidePushBanner.stop(); //退登/重进流程销毁本页时,别留着定时任务空跑
|
||
super.dispose();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return PopScope(
|
||
canPop: false,
|
||
onPopInvokedWithResult: (didPop, _) {
|
||
if (didPop) return;
|
||
if (logic.confirmExit()) SystemNavigator.pop();
|
||
},
|
||
child: Scaffold(
|
||
resizeToAvoidBottomInset: false,
|
||
body: Column(
|
||
children: [
|
||
Expanded(
|
||
child: Stack(
|
||
fit: StackFit.expand,
|
||
children: [
|
||
_buildPages(),
|
||
//引导气泡贴着底栏上沿,尾巴指短剧 tab
|
||
const Positioned(
|
||
left: 0, right: 0, bottom: 0, child: DramaTipBubble()),
|
||
],
|
||
),
|
||
),
|
||
const MainPageTabbar(),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildPages() {
|
||
return Obx(() {
|
||
final cur = logic.curPageIndex.value;
|
||
return LazyIndexedStack(
|
||
index: cur,
|
||
children: [
|
||
// 主页
|
||
Stack(
|
||
fit: StackFit.expand,
|
||
children: [
|
||
const HomeMainPage(),
|
||
_bottomMarquee(),
|
||
],
|
||
),
|
||
// 短视频
|
||
Obx(() => ShortVideoMainPage(index: logic.shortIndex.value)),
|
||
// 暗网
|
||
if (Config.darkWebEnable)
|
||
Obx(() => DarkHomePage(defaultId: logic.darkInitTabId.value)),
|
||
// AI
|
||
const AiHomePage(),
|
||
// 社区
|
||
Stack(
|
||
children: [
|
||
Obx(
|
||
() => CommunityMainPage(
|
||
index: logic.communityIndex.value,
|
||
subTabIndex: logic.communitySubIndex.value,
|
||
),
|
||
),
|
||
_bottomMarquee(),
|
||
],
|
||
),
|
||
// 我的(IndexedStack 天然保活,不需要 keepAlive)
|
||
const HomeMinePage(),
|
||
],
|
||
);
|
||
});
|
||
}
|
||
|
||
/// 首页/社区底部的文字跑马灯
|
||
Widget _bottomMarquee() {
|
||
return Positioned(
|
||
bottom: 0,
|
||
left: 0,
|
||
right: 0,
|
||
child: HomeTxtMarQuee(typeValue: 1),
|
||
);
|
||
}
|
||
}
|