Files
tripz/lib/controller/home/splash_screen_controlle.dart
Hamza-Ayed 74abae1b38 7/23/2
2024-07-23 15:58:11 +03:00

125 lines
3.7 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:SEFER/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 SingleGetTickerProviderMixin {
late AnimationController animationController;
late Animation<double> zoomInAnimation;
late Animation<double> zoomOutAnimation;
String packageInfo = '';
late String version = '1.5.48';
Future<void> checkForUpdate() async {
final packageInfo = await PackageInfo.fromPlatform();
final currentVersion = packageInfo.buildNumber;
final version1 = packageInfo.version;
print('currentVersion is : $currentVersion');
// Fetch the latest version from your server
version = version1.toString();
print('version: ${version}');
update();
}
StreamSubscription? _sub;
// Future<void> initUniLinks() async {
// // Handle initial URI if the app was launched from a link
// try {
// final initialUri = await getInitialUri();
// if (initialUri != null) {
// handleLink(initialUri);
// }
// } on PlatformException {
// // Handle exception by warning the user their action did not succeed
// print("Failed to get initial uri");
// }
// // Listen to new links while the app is running
// _sub = uriLinkStream.listen((Uri? uri) {
// if (uri != null) {
// handleLink(uri);
// }
// }, onError: (Object err) {
// print('Error occurred: $err');
// });
// }
void handleLink(Uri uri) {
if (uri.host == 'sefer.live' && uri.path == '/tripmonitor') {
final rideId = uri.queryParameters['rideId'];
final driverId = uri.queryParameters['driverId'];
if (rideId != null && driverId != null) {
Get.toNamed('/tripmonitor', parameters: {
'rideId': rideId,
'driverId': driverId,
});
} else {
// Handle the case where rideId or driverId is null
print('Invalid parameters in the deep link');
// You might want to show an error message to the user or handle this case differently
}
}
}
@override
void onInit() async {
super.onInit();
checkForUpdate();
// initUniLinks();
animationController = AnimationController(
vsync: this,
duration: const Duration(seconds: 4),
);
zoomInAnimation = Tween<double>(begin: 1.0, end: 1.5).animate(
CurvedAnimation(
parent: animationController,
curve: Curves.easeInOut,
),
);
zoomOutAnimation = Tween<double>(begin: 1.5, end: 1.0).animate(
CurvedAnimation(
parent: animationController,
curve: Curves.easeInOut,
),
);
animationController.repeat(reverse: true);
startTimer();
}
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() {
animationController.dispose();
super.onClose();
}
}