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