346 lines
12 KiB
Dart
346 lines
12 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:aslan/app_localizations.dart';
|
|
import 'package:aslan/chatvibe_ui/theme/chatvibe_theme.dart';
|
|
import 'package:aslan/chatvibe_core/constants/at_global_config.dart';
|
|
import 'package:aslan/chatvibe_core/utilities/at_heartbeat_utils.dart';
|
|
import 'package:aslan/chatvibe_data/sources/local/floating_screen_manager.dart';
|
|
import 'package:aslan/chatvibe_data/sources/repositories/config_repository_imp.dart';
|
|
import 'package:aslan/chatvibe_features/home/index_home_page.dart';
|
|
import 'package:aslan/chatvibe_features/chat/message/at_message_page.dart';
|
|
import 'package:aslan/chatvibe_managers/rtc_manager.dart';
|
|
import 'package:aslan/chatvibe_managers/rtm_manager.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_float_ichart.dart';
|
|
import 'package:aslan/chatvibe_ui/components/text/at_text.dart';
|
|
import 'package:aslan/chatvibe_core/utilities/at_date_utils.dart';
|
|
import 'package:aslan/chatvibe_core/utilities/at_dialog_queue_manager.dart';
|
|
import 'package:aslan/chatvibe_core/utilities/at_dialog_utils.dart';
|
|
import 'package:aslan/chatvibe_data/sources/local/data_persistence.dart';
|
|
import 'package:aslan/chatvibe_data/sources/local/user_manager.dart';
|
|
import 'package:aslan/chatvibe_data/sources/repositories/user_repository_impl.dart';
|
|
import 'package:aslan/chatvibe_domain/models/res/at_index_banner_res.dart';
|
|
import 'package:aslan/chatvibe_domain/models/res/at_version_manage_latest_res.dart';
|
|
import 'package:aslan/chatvibe_managers/app_general_manager.dart';
|
|
import 'package:aslan/chatvibe_managers/user_profile_manager.dart';
|
|
import 'package:aslan/chatvibe_ui/widgets/sgin/sgin_page.dart';
|
|
import 'package:aslan/chatvibe_ui/widgets/update/app_version_update_page.dart';
|
|
import '../../chatvibe_data/models/enum/at_heartbeat_status.dart';
|
|
import '../home/game/at_index_game_page.dart';
|
|
import '../user/me_page2.dart';
|
|
|
|
/**
|
|
* 首页
|
|
*/
|
|
class ATIndexPage extends StatefulWidget {
|
|
@override
|
|
_ATIndexPageState createState() => _ATIndexPageState();
|
|
}
|
|
|
|
class _ATIndexPageState extends State<ATIndexPage> {
|
|
int _currentIndex = 0;
|
|
final List<Widget> _pages = [];
|
|
final List<BottomNavigationBarItem> _bottomItems = [];
|
|
AppGeneralManager? generalProvider;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
generalProvider = Provider.of<AppGeneralManager>(context, listen: false);
|
|
Provider.of<RtcProvider>(context, listen: false).init(context);
|
|
Provider.of<RtmProvider>(context, listen: false).init(context);
|
|
loadAppVersionAndCheckInToday();
|
|
Provider.of<ChatVibeUserProfileManager>(
|
|
context,
|
|
listen: false,
|
|
).getUserIdentity();
|
|
Provider.of<ChatVibeUserProfileManager>(context, listen: false).balance();
|
|
ATHeartbeatUtils.scheduleHeartbeat(ATHeartbeatStatus.ONLINE.name, false);
|
|
DataPersistence.setLang(ATGlobalConfig.lang);
|
|
OverlayManager().activate();
|
|
WakelockPlus.enable();
|
|
String roomId = DataPersistence.getLastTimeRoomId();
|
|
if (roomId.isNotEmpty) {
|
|
AccountRepository().quitRoom(roomId).catchError((e) {
|
|
return true; // 错误已处理
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
WakelockPlus.disable();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
ATFloatIchart().init(context);
|
|
_initWidget();
|
|
return WillPopScope(
|
|
onWillPop: _doubleExit,
|
|
child: Stack(
|
|
children: [
|
|
Image.asset(
|
|
"atu_images/index/at_icon_index_bg.png",
|
|
width: ScreenUtil().screenWidth,
|
|
height: ScreenUtil().screenHeight,
|
|
fit: BoxFit.fill,
|
|
),
|
|
SafeArea(
|
|
top: false,
|
|
child: Scaffold(
|
|
resizeToAvoidBottomInset: false,
|
|
backgroundColor: Colors.transparent,
|
|
body: _pages[_currentIndex],
|
|
bottomNavigationBar: Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.only(
|
|
topLeft: Radius.circular(12.w),
|
|
topRight: Radius.circular(12.w),
|
|
),
|
|
),
|
|
child: BottomNavigationBar(
|
|
elevation: 0,
|
|
backgroundColor: Colors.transparent,
|
|
selectedLabelStyle: TextStyle(
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 13.sp,
|
|
),
|
|
unselectedLabelStyle: TextStyle(
|
|
fontWeight: FontWeight.w500,
|
|
fontSize: 12.sp,
|
|
),
|
|
type: BottomNavigationBarType.fixed,
|
|
selectedItemColor: ChatVibeTheme.primaryLight,
|
|
showUnselectedLabels: true,
|
|
showSelectedLabels: true,
|
|
items: _bottomItems,
|
|
currentIndex: _currentIndex,
|
|
onTap: (index) => setState(() => _currentIndex = index),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
///双击退出
|
|
int _lastClickTime = 0;
|
|
|
|
Future<bool> _doubleExit() {
|
|
int nowTime = DateTime.now().microsecondsSinceEpoch;
|
|
if (_lastClickTime != 0 && nowTime - _lastClickTime > 1500) {
|
|
return Future.value(true);
|
|
} else {
|
|
_lastClickTime = DateTime.now().microsecondsSinceEpoch;
|
|
Future.delayed(const Duration(milliseconds: 1500), () {
|
|
_lastClickTime = 0;
|
|
});
|
|
return Future.value(false);
|
|
}
|
|
}
|
|
|
|
void _initWidget() {
|
|
_pages.clear();
|
|
_bottomItems.clear();
|
|
_pages.add(ATIndexHomePage());
|
|
_pages.add(ATIndexGamePage());
|
|
// _pages.add(IndexDynamicPage());
|
|
_pages.add(ATMessagePage());
|
|
_pages.add(MePage2());
|
|
|
|
_bottomItems.add(
|
|
BottomNavigationBarItem(
|
|
icon: Image.asset(
|
|
"atu_images/index/at_icon_home_no.png",
|
|
width: 25.w,
|
|
height: 25.w,
|
|
),
|
|
activeIcon: Image.asset(
|
|
"atu_images/index/at_icon_home_en.png",
|
|
width: 25.w,
|
|
height: 25.w,
|
|
),
|
|
label: ATAppLocalizations.of(context)!.home,
|
|
),
|
|
);
|
|
|
|
_bottomItems.add(
|
|
BottomNavigationBarItem(
|
|
icon: Image.asset(
|
|
"atu_images/index/at_icon_game_no.png",
|
|
width: 25.w,
|
|
height: 25.w,
|
|
),
|
|
activeIcon: Image.asset(
|
|
"atu_images/index/at_icon_game_en.png",
|
|
width: 25.w,
|
|
height: 25.w,
|
|
),
|
|
label: ATAppLocalizations.of(context)!.game,
|
|
),
|
|
);
|
|
|
|
_bottomItems.add(
|
|
BottomNavigationBarItem(
|
|
icon: Selector<RtmProvider, int>(
|
|
selector: (c, p) => p.allUnReadCount,
|
|
shouldRebuild: (prev, next) => prev != next,
|
|
builder: (_, allUnReadCount, __) {
|
|
return allUnReadCount > 0
|
|
? Badge(
|
|
backgroundColor: Colors.red,
|
|
label: text(
|
|
"${allUnReadCount > 99 ? "99+" : allUnReadCount}",
|
|
fontSize: 9.sp,
|
|
textColor: Colors.white,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
alignment: AlignmentDirectional.topEnd,
|
|
child: Image.asset(
|
|
"atu_images/index/at_icon_message_no.png",
|
|
width: 25.w,
|
|
height: 25.w,
|
|
),
|
|
)
|
|
: Image.asset(
|
|
"atu_images/index/at_icon_message_no.png",
|
|
width: 25.w,
|
|
height: 25.w,
|
|
);
|
|
},
|
|
),
|
|
activeIcon: Selector<RtmProvider, int>(
|
|
selector: (c, p) => p.allUnReadCount,
|
|
shouldRebuild: (prev, next) => prev != next,
|
|
builder: (_, allUnReadCount, __) {
|
|
return allUnReadCount > 0
|
|
? Badge(
|
|
backgroundColor: Colors.red,
|
|
label: text(
|
|
"${allUnReadCount > 99 ? "99+" : allUnReadCount}",
|
|
fontSize: 9.sp,
|
|
textColor: Colors.white,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
alignment: AlignmentDirectional.topEnd,
|
|
child: Image.asset(
|
|
"atu_images/index/at_icon_message_en.png",
|
|
width: 25.w,
|
|
height: 25.w,
|
|
),
|
|
)
|
|
: Image.asset(
|
|
"atu_images/index/at_icon_message_en.png",
|
|
width: 25.w,
|
|
height: 25.w,
|
|
);
|
|
},
|
|
),
|
|
label: ATAppLocalizations.of(context)!.message,
|
|
),
|
|
);
|
|
_bottomItems.add(
|
|
BottomNavigationBarItem(
|
|
icon: Image.asset(
|
|
"atu_images/index/at_icon_me_no.png",
|
|
width: 25.w,
|
|
height: 25.w,
|
|
),
|
|
activeIcon: Image.asset(
|
|
"atu_images/index/at_icon_me_en.png",
|
|
width: 25.w,
|
|
height: 25.w,
|
|
),
|
|
label: ATAppLocalizations.of(context)!.me,
|
|
),
|
|
);
|
|
}
|
|
|
|
void loadAppVersionAndCheckInToday() {
|
|
Future.wait([
|
|
ConfigRepositoryImp().versionManageLatest(),
|
|
AccountRepository().checkInToday(),
|
|
ConfigRepositoryImp().getBanner(types: ["AD"]),
|
|
]).then((result) {
|
|
ATVersionManageLatestRes versionManageLatestRes =
|
|
result[0] as ATVersionManageLatestRes;
|
|
bool checkInToday = result[1] as bool;
|
|
List<ATIndexBannerRes> banners = result[2] as List<ATIndexBannerRes>;
|
|
if ((versionManageLatestRes.buildVersion ?? 0) >
|
|
int.parse(ATGlobalConfig.build)) {
|
|
if (!(versionManageLatestRes.review ?? false)) {
|
|
//过审
|
|
ATModalQueue().addDialog(() {
|
|
SmartDialog.show(
|
|
tag: "showUpdateDialog",
|
|
alignment: Alignment.center,
|
|
animationType: SmartAnimationType.fade,
|
|
clickMaskDismiss: versionManageLatestRes.forceUpdate == false,
|
|
backType:
|
|
versionManageLatestRes.forceUpdate == false
|
|
? null
|
|
: SmartBackType.block,
|
|
onDismiss: () {
|
|
ATModalQueue().showComplete();
|
|
},
|
|
builder: (_) {
|
|
return AppVersionUpdatePage(versionManageLatestRes);
|
|
},
|
|
);
|
|
}, priority: 1000);
|
|
}
|
|
}
|
|
if (!checkInToday) {
|
|
ATModalQueue().addDialog(() {
|
|
SmartDialog.show(
|
|
tag: "showSginListAward",
|
|
alignment: Alignment.center,
|
|
animationType: SmartAnimationType.fade,
|
|
onDismiss: () {
|
|
ATModalQueue().showComplete();
|
|
},
|
|
builder: (_) {
|
|
return SginPage(true);
|
|
},
|
|
);
|
|
}, priority: 500);
|
|
}
|
|
Provider.of<ChatVibeUserProfileManager>(
|
|
context,
|
|
listen: false,
|
|
).getMyUserInfo().whenComplete(() {
|
|
if (!ATGlobalConfig.isReview) {
|
|
if ((AccountStorage().getCurrentUser()?.userProfile?.firstRecharge ??
|
|
false)) {
|
|
///首充弹框
|
|
ATModalQueue().addDialog(() {
|
|
ATDialogUtils.showFirstRechargeDialog(context);
|
|
}, priority: 100);
|
|
}
|
|
}
|
|
|
|
if (banners.isNotEmpty) {
|
|
///banner弹框
|
|
bool needShow = DataPersistence.getBool(
|
|
"IndexBannerTodayShow${ATMDateUtils.formatDateTime(DateTime.now())}",
|
|
);
|
|
if (!needShow) {
|
|
ATModalQueue().addDialog(() {
|
|
ATDialogUtils.revealBannerDialog(context, banners);
|
|
}, priority: 100);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|