splash_page.dart 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import 'dart:io';
  2. import 'package:flutter/gestures.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:shared_preferences/shared_preferences.dart';
  5. import 'package:sport/pages/login/license.dart';
  6. import 'package:sport/router/navigator_util.dart';
  7. import 'package:sport/router/routes.dart';
  8. import 'package:sport/widgets/appbar.dart';
  9. import 'package:sport/widgets/button_cancel.dart';
  10. import 'package:sport/widgets/button_primary.dart';
  11. class SplashPage extends StatefulWidget {
  12. @override
  13. _SplashPageState createState() => _SplashPageState();
  14. }
  15. class _SplashPageState extends State<SplashPage> {
  16. @override
  17. void initState() {
  18. super.initState();
  19. _loading();
  20. }
  21. _loading() async {
  22. await Future.delayed(Duration(milliseconds: 1500));
  23. SharedPreferences prefs = await SharedPreferences.getInstance();
  24. bool? agreement = prefs.getBool("agreement");
  25. String? token = prefs.getString("token");
  26. if (agreement != true || token == null) {
  27. bool result = await showDialog(
  28. context: context,
  29. barrierDismissible: false,
  30. builder: (context) {
  31. return WillPopScope(
  32. onWillPop: () async => false, //关键代码
  33. child: Dialog(
  34. backgroundColor: Colors.transparent,
  35. insetPadding: EdgeInsets.zero,
  36. child: Center(
  37. child: Container(
  38. width: 300.0,
  39. decoration: BoxDecoration(
  40. borderRadius: BorderRadius.all(Radius.circular(10.0)),
  41. color: Colors.white,
  42. ),
  43. padding: const EdgeInsets.symmetric(vertical: 25.0, horizontal: 20.0),
  44. child: Column(
  45. mainAxisSize: MainAxisSize.min,
  46. children: <Widget>[
  47. // Header
  48. Padding(
  49. padding: EdgeInsets.only(top: 5.0),
  50. child: Text(
  51. "用户协议及隐私政策概要",
  52. style: titleStyle.copyWith(fontSize: 16.0),
  53. ),
  54. ),
  55. Padding(
  56. padding: const EdgeInsets.only(top: 12.0, bottom: 25.0),
  57. child: RichText(
  58. strutStyle: StrutStyle(height: 1.8,),
  59. text: TextSpan(style: Theme.of(context).textTheme.subtitle1!, children: <InlineSpan>[
  60. TextSpan(
  61. text: "欢迎使用趣动app!我们将通过",
  62. ),
  63. TextSpan(text: "《用户协议》", style: Theme.of(context).textTheme.subtitle1!.copyWith( color: const Color(0xffFFC400)), recognizer: TapGestureRecognizer()..onTap = () => NavigatorUtil.go(context, Routes.serviceagreement)),
  64. TextSpan(
  65. text: "及",
  66. ),
  67. TextSpan(text: "《隐私政策》", style: Theme.of(context).textTheme.subtitle1!.copyWith( color: const Color(0xffFFC400)), recognizer: TapGestureRecognizer()..onTap = () => NavigatorUtil.go(context, Routes.privacypolicy)),
  68. TextSpan(
  69. text: "帮助您了解本软件所提供的服务以及我们搜集、使用、储存和共享您个人信息的情况,并告知您所享有的相关权力及可能须承担的义务。未经您允许,我们不会主动向任何第三方共享您的个人信息。请您务必在使用本软件前仔细阅读前述法律文件。如您同意的,请点击“同意”后开始使用我们的服务",
  70. ),
  71. ])),
  72. ),
  73. PrimaryButton(height: 40.0,callback: (){
  74. Navigator.pop(context, true);}, content: "同意"),
  75. const SizedBox(height: 16.0,),
  76. CancelButton(
  77. content: "暂不使用",
  78. callback: () { Navigator.pop(context, false); },
  79. ),
  80. ],
  81. ),
  82. ),
  83. ),
  84. ),
  85. );
  86. });
  87. if (result != true) {
  88. exit(0);
  89. return;
  90. }
  91. }
  92. if (token == null) {
  93. NavigatorUtil.goLogin(context);
  94. } else {
  95. NavigatorUtil.goHomePage(context);
  96. }
  97. }
  98. @override
  99. Widget build(BuildContext context) {
  100. return Material(
  101. child: Center(
  102. child: Hero(
  103. tag: "logo",
  104. child: Image.asset(
  105. "lib/assets/img/logo_img.png",
  106. ),
  107. ),
  108. ),
  109. );
  110. }
  111. }