import 'dart:async'; import 'dart:math'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:aslan/chatvibe_ui/components/at_compontent.dart'; import 'package:aslan/chatvibe_core/constants/at_global_config.dart'; import 'package:aslan/chatvibe_core/utilities/at_version_utils.dart'; import 'package:aslan/chatvibe_data/sources/local/user_manager.dart'; import 'package:marquee/marquee.dart'; import 'package:aslan/chatvibe_core/routes/at_routes.dart'; import 'package:aslan/chatvibe_core/routes/at_fluro_navigator.dart'; import 'package:aslan/chatvibe_data/sources/local/file_cache_manager.dart'; import 'package:aslan/chatvibe_data/sources/repositories/config_repository_imp.dart'; import 'package:aslan/chatvibe_domain/models/res/at_start_page_res.dart'; import 'package:aslan/chatvibe_features/auth/login_route.dart'; class SplashPage extends StatefulWidget { @override _SplashPageState createState() => _SplashPageState(); } class _SplashPageState extends State { Timer? _timer; int countdown = 6; int status = 0; ATStartPageRes? currentStartPage; List startPages = []; @override void initState() { super.initState(); FileCacheManager.getInstance().getFilePath(); getStartPage(); _startTimer(context); } ///加载启动页配置 void getStartPage() { ConfigRepositoryImp().getStartPage().then((result) { startPages = result; if (startPages.length > 1) { int index = Random().nextInt(startPages.length); currentStartPage = result[index]; } else { currentStartPage = result.first; } status = 1; setState(() {}); }); } @override void dispose() { _cancelTimer(); super.dispose(); } /// 启动倒计时 void _startTimer(BuildContext context) { // 计时器(`Timer`)组件的定期(`periodic`)构造函数,创建一个新的重复计时器。 _timer = Timer.periodic(Duration(seconds: 1), (timer) { if (countdown == 0) { _cancelTimer(); _goMainPage(context); return; } countdown--; setState(() {}); }); } @override Widget build(BuildContext context) { return Material( child: Stack( alignment: Alignment.center, children: [ Image.asset( ATGlobalConfig.businessLogicStrategy.getSplashPageBackgroundImage(), width: ScreenUtil().screenWidth, height: ScreenUtil().screenHeight, fit: BoxFit.cover, ), Image.asset( ATGlobalConfig.businessLogicStrategy.getSplashPageIcon(), width: 107.w, height: 159.w, ), // status == 0 ? Container() : KingGamesScreenWidget(currentStartPage), // status == 0 // ? Container() // : (currentStartPage?.type == "CP" // ? CPScreenWidget(currentStartPage) // : (currentStartPage?.type == "KING_GAMES" // ? KingGamesScreenWidget(currentStartPage) // : Container())), // status == 1 // ? PositionedDirectional( // top: 45.w, // end: 15.w, // child: ATDebounceWidget( // debounceTime: Duration(milliseconds: 1000), // onTap: () { // _cancelTimer(); // _goMainPage(context); // }, // child: Container( // alignment: Alignment.center, // width: 60.w, // height: 24.w, // decoration: BoxDecoration( // image: DecorationImage( // image: AssetImage( // ATGlobalConfig.businessLogicStrategy.getSplashPageSkipButtonBackground(), // ), // fit: BoxFit.fill, // ), // ), // child: text( // ATAppLocalizations.of(context)!.skip("$countdown"), // textColor: ATGlobalConfig.businessLogicStrategy.getSplashPageSkipButtonTextColor(), // fontSize: 12.sp, // ), // ), // ), // ) // : Container(), ], ), ); } void _goMainPage(BuildContext context) async { try { await ATVersionUtils.checkReview(); var user = AccountStorage().getCurrentUser(); var token = AccountStorage().getToken(); if (user != null && token.isNotEmpty) { ATNavigatorUtils.push(context, ATRoutes.home, replace: true); } else { ATNavigatorUtils.push(context, LoginRouter.login, replace: true); } } catch (e) { ATNavigatorUtils.push(context, LoginRouter.login, replace: true); } } /// 取消倒计时的计时器。 void _cancelTimer() { // 计时器(`Timer`)组件的取消(`cancel`)方法,取消计时器。 _timer?.cancel(); } } class KingGamesScreenWidget extends StatefulWidget { ATStartPageRes? startPage; KingGamesScreenWidget(this.startPage); @override _KingGamesScreenWidgetState createState() => _KingGamesScreenWidgetState(); } class _KingGamesScreenWidgetState extends State { StartPageUser? user1; @override void initState() { super.initState(); user1 = widget.startPage?.user?.first; } @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Stack( alignment: AlignmentDirectional.center, children: [ netImage( url: user1?.avatar ?? "", defaultImg: "atu_images/general/at_icon_avar_defalt.png", shape: BoxShape.circle, height: 105.w, width: 105.w, ), netImage( url: widget.startPage?.cover ?? "", width: ScreenUtil().screenWidth, height: ScreenUtil().screenHeight, noDefaultImg: true, fit: BoxFit.cover, ), Column( mainAxisAlignment: MainAxisAlignment.end, mainAxisSize: MainAxisSize.max, children: [ Container( alignment: Alignment.center, padding: EdgeInsetsDirectional.only( start: 32.w, end: 32.w, top: 10.w, ), width: 250.w, height: 58.w, decoration: BoxDecoration( image: DecorationImage( image: AssetImage( ATGlobalConfig.businessLogicStrategy.getSplashPageKingGamesNameBackground(), ), fit: BoxFit.fill, ), ), child: (user1?.nickName?.length ?? 0) > 10 ? Marquee( text: user1?.nickName ?? "", style: TextStyle( fontSize: 26.sp, color: ATGlobalConfig.businessLogicStrategy.getSplashPageKingGamesTextColor(), fontWeight: FontWeight.bold, decoration: TextDecoration.none, ), scrollAxis: Axis.horizontal, crossAxisAlignment: CrossAxisAlignment.start, blankSpace: 20.0, velocity: 40.0, pauseAfterRound: Duration(seconds: 1), accelerationDuration: Duration(seconds: 1), accelerationCurve: Curves.easeOut, decelerationDuration: Duration(milliseconds: 550), decelerationCurve: Curves.easeOut, ) : Text( user1?.nickName ?? "", maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 26.sp, color: ATGlobalConfig.businessLogicStrategy.getSplashPageKingGamesTextColor(), fontWeight: FontWeight.bold, decoration: TextDecoration.none, ), ), ), SizedBox(height: 150.w), ], ), ], ), ), ); } } class CPScreenWidget extends StatefulWidget { ATStartPageRes? startPage; CPScreenWidget(this.startPage); @override _CPScreenWidgetState createState() => _CPScreenWidgetState(); } class _CPScreenWidgetState extends State { StartPageUser? user1; StartPageUser? user2; @override void initState() { super.initState(); user1 = widget.startPage?.user?.first; user2 = widget.startPage?.user?.last; } @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Stack( alignment: AlignmentDirectional.center, children: [ Row( mainAxisSize: MainAxisSize.min, children: [ netImage( url: user1?.avatar ?? "", defaultImg: "atu_images/general/at_icon_avar_defalt.png", shape: BoxShape.circle, height: 125.w, width: 125.w, ), SizedBox(width: 38.w), netImage( url: user2?.avatar ?? "", defaultImg: "atu_images/general/at_icon_avar_defalt.png", shape: BoxShape.circle, height: 125.w, width: 125.w, ), ], ), netImage( url: widget.startPage?.cover ?? "", width: ScreenUtil().screenWidth, height: ScreenUtil().screenHeight, noDefaultImg: true, fit: BoxFit.cover, ), Column( mainAxisAlignment: MainAxisAlignment.end, mainAxisSize: MainAxisSize.max, children: [ Container( alignment: Alignment.center, margin: EdgeInsetsDirectional.symmetric(horizontal: 15.w), height: 35.w, decoration: BoxDecoration( image: DecorationImage( image: AssetImage( ATGlobalConfig.businessLogicStrategy.getSplashPageCpNameBackground(), ), fit: BoxFit.fill, ), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Container( width: 130.w, alignment: Alignment.center, child: (user1?.nickName?.length ?? 0) > 12 ? Marquee( text: user1?.nickName ?? "", style: TextStyle( fontSize: 22.sp, color: ATGlobalConfig.businessLogicStrategy.getSplashPageCpTextColor(), fontWeight: FontWeight.bold, decoration: TextDecoration.none, ), scrollAxis: Axis.horizontal, crossAxisAlignment: CrossAxisAlignment.start, blankSpace: 20.0, velocity: 40.0, pauseAfterRound: Duration(seconds: 1), accelerationDuration: Duration(seconds: 1), accelerationCurve: Curves.easeOut, decelerationDuration: Duration( milliseconds: 500, ), decelerationCurve: Curves.easeOut, ) : Text( user1?.nickName ?? "", maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 22.sp, color: ATGlobalConfig.businessLogicStrategy.getSplashPageCpTextColor(), fontWeight: FontWeight.bold, decoration: TextDecoration.none, ), ), ), SizedBox(width: 30.w), Container( alignment: Alignment.center, width: 130.w, child: (user2?.nickName?.length ?? 0) > 12 ? Marquee( text: user2?.nickName ?? "", style: TextStyle( fontSize: 22.sp, color: ATGlobalConfig.businessLogicStrategy.getSplashPageCpTextColor(), fontWeight: FontWeight.bold, decoration: TextDecoration.none, ), scrollAxis: Axis.horizontal, crossAxisAlignment: CrossAxisAlignment.start, blankSpace: 20.0, velocity: 40.0, pauseAfterRound: Duration(seconds: 1), accelerationDuration: Duration(seconds: 1), accelerationCurve: Curves.easeOut, decelerationDuration: Duration( milliseconds: 500, ), decelerationCurve: Curves.easeOut, ) : Text( user2?.nickName ?? "", maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 22.sp, color: ATGlobalConfig.businessLogicStrategy.getSplashPageCpTextColor(), fontWeight: FontWeight.bold, decoration: TextDecoration.none, ), ), ), ], ), ), SizedBox(height: ScreenUtil().screenHeight/2-122.w), ], ), ], ), ), ); } }