152 lines
4.4 KiB
Dart
152 lines
4.4 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:Tripz/constant/style.dart';
|
|
import 'package:Tripz/controller/functions/secure_storage.dart';
|
|
import 'package:Tripz/views/widgets/my_scafold.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:Tripz/views/auth/login_page.dart';
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
// import 'package:uni_links/uni_links.dart';
|
|
|
|
import '../../constant/box_name.dart';
|
|
import '../../main.dart';
|
|
import '../../onbording_page.dart';
|
|
import '../auth/login_controller.dart';
|
|
|
|
class SplashScreenController extends GetxController
|
|
with GetTickerProviderStateMixin {
|
|
late AnimationController _animationController;
|
|
late Animation<double> animation;
|
|
final progress = 0.0.obs;
|
|
Timer? _progressTimer;
|
|
|
|
String packageInfo = '';
|
|
|
|
Future<void> _getPackageInfo() async {
|
|
final info = await PackageInfo.fromPlatform();
|
|
packageInfo = info.version;
|
|
box.write(BoxName.packagInfo, packageInfo);
|
|
update();
|
|
}
|
|
|
|
String iss = '';
|
|
@override
|
|
Future<void> onInit() async {
|
|
super.onInit();
|
|
|
|
// storage.read(key: 'iss').then((s) {
|
|
// // print(s);
|
|
// iss = s!;
|
|
// });
|
|
// if (iss == null) {
|
|
SecureStorage().saveData('iss', 'mobile-app:');
|
|
// }
|
|
|
|
_getPackageInfo();
|
|
_animationController = AnimationController(
|
|
vsync: this,
|
|
duration: const Duration(milliseconds: 1500), // Reduced duration
|
|
)..forward();
|
|
|
|
animation =
|
|
CurvedAnimation(parent: _animationController, curve: Curves.easeOut);
|
|
|
|
startTimer();
|
|
_startProgressTimer();
|
|
}
|
|
|
|
void _startProgressTimer() {
|
|
const totalTime = 3000; // 5 seconds in milliseconds
|
|
const interval = 50; // Update every 50ms
|
|
int elapsed = 0;
|
|
|
|
_progressTimer =
|
|
Timer.periodic(const Duration(milliseconds: interval), (timer) async {
|
|
elapsed += interval;
|
|
progress.value = (elapsed / totalTime).clamp(0.0, 1.0);
|
|
|
|
if (elapsed >= totalTime) {
|
|
timer.cancel();
|
|
// await SecurityHelper.performSecurityChecks();
|
|
// if (box.read('isNotTrust') ||
|
|
// box.read('isJailBroken') ||
|
|
// box.read('isTampered')) {
|
|
// Get.to(() => SecurityPage());
|
|
// } else {
|
|
box.read(BoxName.onBoarding) == null
|
|
? Get.off(() => OnBoardingPage())
|
|
: box.read(BoxName.email) != null &&
|
|
box.read(BoxName.phone) != null &&
|
|
box.read(BoxName.isVerified) == '1'
|
|
// ? Get.off(() => const MapPagePassenger())
|
|
? await Get.put(LoginController()).loginUsingCredentials(
|
|
box.read(BoxName.passengerID).toString(),
|
|
box.read(BoxName.email).toString(),
|
|
)
|
|
: Get.off(() => LoginPage());
|
|
}
|
|
// }
|
|
});
|
|
}
|
|
|
|
void startTimer() async {
|
|
Timer(const Duration(seconds: 5), () async {
|
|
// box.read(BoxName.onBoarding) == null
|
|
// ? Get.off(() => OnBoardingPage())
|
|
// : box.read(BoxName.email) != null &&
|
|
// box.read(BoxName.phone) != null &&
|
|
// box.read(BoxName.isVerified) == '1'
|
|
// // ? Get.off(() => const MapPagePassenger())
|
|
// ? await Get.put(LoginController()).loginUsingCredentials(
|
|
// box.read(BoxName.passengerID).toString(),
|
|
// box.read(BoxName.email).toString(),
|
|
// )
|
|
// : Get.off(() => LoginPage());
|
|
});
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
_progressTimer?.cancel();
|
|
_animationController.dispose();
|
|
super.onClose();
|
|
}
|
|
}
|
|
|
|
class SecurityPage extends StatelessWidget {
|
|
const SecurityPage({
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MyScafolld(
|
|
title: "security_warning".tr,
|
|
body: [
|
|
Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(20),
|
|
child: Column(
|
|
children: [
|
|
Text(
|
|
"security_message".tr,
|
|
style: AppStyle.headTitle2,
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
// await SecurityHelper.clearAllData();
|
|
},
|
|
child: Text(
|
|
"security_warning".tr,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
],
|
|
isleading: false);
|
|
}
|
|
}
|