import 'dart:io'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:sport/pages/login/license.dart'; import 'package:sport/router/navigator_util.dart'; import 'package:sport/router/routes.dart'; import 'package:sport/widgets/appbar.dart'; import 'package:sport/widgets/button_cancel.dart'; import 'package:sport/widgets/button_primary.dart'; class SplashPage extends StatefulWidget { @override _SplashPageState createState() => _SplashPageState(); } class _SplashPageState extends State { @override void initState() { super.initState(); _loading(); } _loading() async { await Future.delayed(Duration(milliseconds: 1500)); SharedPreferences prefs = await SharedPreferences.getInstance(); bool? agreement = prefs.getBool("agreement"); String? token = prefs.getString("token"); if (agreement != true || token == null) { bool result = await showDialog( context: context, barrierDismissible: false, builder: (context) { return WillPopScope( onWillPop: () async => false, //关键代码 child: Dialog( backgroundColor: Colors.transparent, insetPadding: EdgeInsets.zero, child: Center( child: Container( width: 300.0, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(10.0)), color: Colors.white, ), padding: const EdgeInsets.symmetric(vertical: 25.0, horizontal: 20.0), child: Column( mainAxisSize: MainAxisSize.min, children: [ // Header Padding( padding: EdgeInsets.only(top: 5.0), child: Text( "用户协议及隐私政策概要", style: titleStyle.copyWith(fontSize: 16.0), ), ), Padding( padding: const EdgeInsets.only(top: 12.0, bottom: 25.0), child: RichText( strutStyle: StrutStyle(height: 1.8,), text: TextSpan(style: Theme.of(context).textTheme.subtitle1!, children: [ TextSpan( text: "欢迎使用趣动app!我们将通过", ), TextSpan(text: "《用户协议》", style: Theme.of(context).textTheme.subtitle1!.copyWith( color: const Color(0xffFFC400)), recognizer: TapGestureRecognizer()..onTap = () => NavigatorUtil.go(context, Routes.serviceagreement)), TextSpan( text: "及", ), TextSpan(text: "《隐私政策》", style: Theme.of(context).textTheme.subtitle1!.copyWith( color: const Color(0xffFFC400)), recognizer: TapGestureRecognizer()..onTap = () => NavigatorUtil.go(context, Routes.privacypolicy)), TextSpan( text: "帮助您了解本软件所提供的服务以及我们搜集、使用、储存和共享您个人信息的情况,并告知您所享有的相关权力及可能须承担的义务。未经您允许,我们不会主动向任何第三方共享您的个人信息。请您务必在使用本软件前仔细阅读前述法律文件。如您同意的,请点击“同意”后开始使用我们的服务", ), ])), ), PrimaryButton(height: 40.0,callback: (){ Navigator.pop(context, true);}, content: "同意"), const SizedBox(height: 16.0,), CancelButton( content: "暂不使用", callback: () { Navigator.pop(context, false); }, ), ], ), ), ), ), ); }); if (result != true) { exit(0); return; } } if (token == null) { NavigatorUtil.goLogin(context); } else { NavigatorUtil.goHomePage(context); } } @override Widget build(BuildContext context) { return Material( child: Center( child: Hero( tag: "logo", child: Image.asset( "lib/assets/img/logo_img.png", ), ), ), ); } }