splash_page.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import 'dart:async';
  2. import 'package:auto_route/auto_route.dart';
  3. import 'package:eitc_erm_dental_flutter/app_router.gr.dart';
  4. import 'package:eitc_erm_dental_flutter/dialog/app_start_agreement_dialog.dart';
  5. import 'package:eitc_erm_dental_flutter/funcs.dart';
  6. import 'package:eitc_erm_dental_flutter/generated/assets.dart';
  7. import 'package:eitc_erm_dental_flutter/sp_util.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:flutter_screenutil/flutter_screenutil.dart';
  10. ///Splash页面
  11. @RoutePage(name: "splashRoute")
  12. class SplashPage extends StatefulWidget {
  13. const SplashPage({super.key});
  14. @override
  15. State<SplashPage> createState() => _SplashPageState();
  16. }
  17. class _SplashPageState extends State<SplashPage> {
  18. @override
  19. void initState() {
  20. super.initState();
  21. //定时打开主页
  22. Timer(const Duration(seconds: 3), () => _gotoNext(context, true));
  23. }
  24. @override
  25. Widget build(BuildContext context) {
  26. return Scaffold(
  27. body: Container(
  28. alignment: Alignment.center,
  29. decoration: const BoxDecoration(
  30. image: DecorationImage(
  31. image: AssetImage(Assets.imagesSplashBg), fit: BoxFit.cover),
  32. ),
  33. child: Column(
  34. children: [
  35. Expanded(
  36. flex: 2,
  37. child: Column(
  38. mainAxisSize: MainAxisSize.min,
  39. mainAxisAlignment: MainAxisAlignment.end,
  40. children: [
  41. Text(
  42. splashTitle,
  43. textAlign: TextAlign.center,
  44. style: TextStyle(color: Colors.white, fontSize: 30.sp),
  45. ),
  46. SizedBox(
  47. height: 10.h,
  48. ),
  49. Text(
  50. getS().appSlogan,
  51. textAlign: TextAlign.center,
  52. style: TextStyle(color: Colors.white, fontSize: 20.sp),
  53. ),
  54. SizedBox(
  55. height: 25.h,
  56. ),
  57. Text(
  58. getS().appSlogan2,
  59. textAlign: TextAlign.center,
  60. style: TextStyle(
  61. color: Colors.white,
  62. fontSize: 14.sp,
  63. ),
  64. ),
  65. ],
  66. ),
  67. ),
  68. const Spacer(
  69. flex: 3,
  70. )
  71. ],
  72. ),
  73. ),
  74. );
  75. }
  76. String get splashTitle {
  77. if (isHst) {
  78. return getS().splashTitleHst;
  79. } else {
  80. return getS().splashTitle;
  81. }
  82. }
  83. ///下一步
  84. ///
  85. /// [checkAgreement] 是否检查app启动协议是否同意
  86. void _gotoNext(BuildContext context, bool checkAgreement) async {
  87. if (checkAgreement) {
  88. bool agreed = await SpUtil.isAppStartAgreementAgreed();
  89. logd("splash检查app启动协议,是否同意=$agreed");
  90. if (!agreed && context.mounted) {
  91. _showAgreement(context);
  92. return;
  93. }
  94. }
  95. if (context.mounted) {
  96. context.replaceRoute(const MainRoute());
  97. logd("splash跳转到主页");
  98. }
  99. }
  100. ///显示协议
  101. void _showAgreement(BuildContext context) async {
  102. bool? bo = await showDialog(
  103. context: context,
  104. barrierDismissible: false,
  105. builder: (ctx) {
  106. return AppStartAgreementDialog();
  107. });
  108. //同意了继续
  109. if (bo ?? false) {
  110. await SpUtil.setAppStartAgreementAgreed(true);
  111. if (context.mounted) {
  112. _gotoNext(context, false);
  113. }
  114. }
  115. //不同意就退出app
  116. else {
  117. exitApp();
  118. }
  119. }
  120. }