139 lines
4.2 KiB
Dart
139 lines
4.2 KiB
Dart
import 'dart:io';
|
||
|
||
import 'package:flustars/flustars.dart' hide ScreenUtil;
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_kinetra/kt_pages/kt_routes.dart';
|
||
import 'package:flutter_kinetra/kt_utils/kt_keys.dart';
|
||
import 'package:flutter_kinetra/kt_utils/kt_string_extend.dart';
|
||
import 'package:flutter_kinetra/kt_utils/kt_utils.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:permission_handler/permission_handler.dart';
|
||
|
||
import '../kt_utils/kt_user_utils.dart';
|
||
|
||
class KtSplashPage extends StatefulWidget {
|
||
const KtSplashPage({super.key});
|
||
|
||
@override
|
||
State<KtSplashPage> createState() => _KtSplashPageState();
|
||
}
|
||
|
||
class _KtSplashPageState extends State<KtSplashPage> {
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
body: Container(
|
||
padding: EdgeInsets.symmetric(horizontal: 15.sp),
|
||
width: ScreenUtil().screenWidth,
|
||
height: ScreenUtil().screenHeight,
|
||
decoration: BoxDecoration(
|
||
image: DecorationImage(
|
||
image: AssetImage(
|
||
(SpUtil.getBool(KtKeys.isFirstIn) ?? false
|
||
? 'splash_bg2.png'
|
||
: 'splash_bg.png')
|
||
.ktIcon,
|
||
),
|
||
fit: BoxFit.fill,
|
||
),
|
||
),
|
||
child: Visibility(
|
||
visible: !(SpUtil.getBool(KtKeys.isFirstIn) ?? false),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.center,
|
||
mainAxisAlignment: MainAxisAlignment.end,
|
||
children: [
|
||
GestureDetector(
|
||
onTap: () {
|
||
SpUtil.putBool(KtKeys.isFirstIn, true);
|
||
KtUserUtil().register();
|
||
},
|
||
child: Container(
|
||
width: 200.w,
|
||
margin: EdgeInsets.only(bottom: 110.h),
|
||
padding: EdgeInsets.only(top: 21.w, bottom: 30.w),
|
||
alignment: Alignment.center,
|
||
decoration: BoxDecoration(
|
||
image: DecorationImage(
|
||
image: AssetImage('ic_splash_btn.png'.ktIcon),
|
||
fit: BoxFit.fill,
|
||
),
|
||
),
|
||
child: Text(
|
||
'Get start',
|
||
style: TextStyle(
|
||
fontSize: 16.sp,
|
||
color: Color(0xFF1E1E20),
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
// initHeader();
|
||
initRoute();
|
||
}
|
||
|
||
initRoute() async {
|
||
await Future.delayed(const Duration(milliseconds: 1000));
|
||
setState(() {});
|
||
// _requestPermission();
|
||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||
String? token = SpUtil.getString(KtKeys.token);
|
||
if (!token.isNullString) {
|
||
try {
|
||
// HttpClient()(token!);
|
||
// KtUserUtil().enterAppPost();
|
||
} catch (e) {
|
||
debugPrint('---err:$e');
|
||
}
|
||
Get.offNamed(KtRoutes.home);
|
||
setState(() {});
|
||
} else {
|
||
if (SpUtil.getBool(KtKeys.isFirstIn) ?? false) {
|
||
KtUserUtil().register();
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
// Future<void> _requestPermission() async {
|
||
// if (Platform.isIOS) {
|
||
// _initTracking();
|
||
// } else if (Platform.isAndroid) {
|
||
// _getGoogleAdId();
|
||
// }
|
||
// await Permission.notification.request();
|
||
// }
|
||
|
||
// _initTracking() async {
|
||
// await AppTrackingTransparency.requestTrackingAuthorization();
|
||
// // 获取 IDFA(需授权同意后才能获取)
|
||
// final idfa = await AppTrackingTransparency.getAdvertisingIdentifier();
|
||
// SpUtils().setString(SpKeys.iosIDFA, idfa);
|
||
// }
|
||
//
|
||
// _getGoogleAdId() async {
|
||
// String? advertisingId;
|
||
// // Platform messages may fail, so we use a try/catch PlatformException.
|
||
// try {
|
||
// advertisingId = await AdvertisingId.id(true);
|
||
// } on PlatformException {
|
||
// advertisingId = null;
|
||
// }
|
||
// if (advertisingId != null) SpUtils().setString(SpKeys.googleAid, advertisingId);
|
||
//
|
||
// return advertisingId;
|
||
// }
|
||
}
|