123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- import 'dart:async';
- import 'dart:convert';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:fluttertoast/fluttertoast.dart';
- import 'package:google_fonts/google_fonts.dart';
- import 'package:hris_selfservice_mobile/Screens/Login/login_screen.dart';
- import 'package:hris_selfservice_mobile/Screens/Splash/loginstatus_post.dart';
- import 'package:lottie/lottie.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import '../Home/home_screen.dart';
- import '../Splash/background.dart';
- import 'package:url_launcher/url_launcher.dart';
- import 'dart:developer' as logDev;
-
- class Splash extends StatefulWidget {
- const Splash({Key? key}) : super(key: key);
-
- @override
- _SplashState createState() => _SplashState();
- }
-
- class _SplashState extends State<Splash> {
- @override
- void initState() {
- super.initState();
- Timer(Duration(seconds: 10), () => loginStatus(context));
- }
-
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- resizeToAvoidBottomInset: false,
- body: Stack(
- children: <Widget>[
- Background(),
- SplashScreen(),
- ],
- ));
- }
- }
-
- class SplashScreen extends StatelessWidget {
- const SplashScreen({Key? key}) : super(key: key);
-
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: Container(
- width: double.infinity,
- height: double.infinity,
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topRight,
- end: Alignment.bottomRight,
- colors: [
- Color(0xFFD21404),
- Color(0xFFFD7267),
- ])),
- child: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Container(
- /*decoration: BoxDecoration(
- shape: BoxShape.circle,
- color: Colors.white
- ),*/
- child: SizedBox(
- width: 250,
- height: 250,
- child: LottieBuilder.asset('assets/animation/animation_4.json',
- repeat: true),
- ),
- ),
- Text('Employee Self Service',
- style: GoogleFonts.knewave(fontSize: 22, color: Colors.white))
- ],
- ),
- ),
- ));
- }
- }
-
- Future<void> loginStatus(BuildContext context) async {
- final SharedPreferences prefs = await SharedPreferences.getInstance();
- String? version = prefs.getString('version');
- String? device = prefs.getString('device');
- String? session = prefs.getString('session');
- String? notif_token = prefs.getString('notif_token');
-
- if (session == null) {
- session = "";
- version = "";
- device = "";
- notif_token = "";
- }
-
- logDev.log(session, name: "SESSIONNYA");
-
- LoginStatus_Post.connectToAPI(version!, device!, session, notif_token!)
- .then((valueResult) async {
- Map<String, dynamic> object = json.decode(valueResult);
- logDev.log(valueResult, name: "LOGIN STATUS!");
- if (object.containsKey("result").toString() == "true") {
- String status = object['result']['status'].toString();
- if (status == "success") {
- Fluttertoast.showToast(
- msg: "You are already logged in",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- Navigator.pushReplacement(
- context, MaterialPageRoute(builder: (context) => HomeView()));
- } else if (status == "failed") {
- String message = object['result']['message'].toString();
- if (message == "Not Logged In") {
- Fluttertoast.showToast(
- msg: message,
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- Navigator.pushReplacement(
- context, MaterialPageRoute(builder: (context) => LoginView()));
- } else {
- String title = object['result']['title'].toString();
- String action = object['result']['action'].toString();
- String block = object['result']['block'].toString();
- if (block == "false") {
- Widget okButton = TextButton(
- child: Text(action),
- onPressed: () {
- _launchURL(Uri.parse("https://play.google.com/store/apps"));
- SystemChannels.platform.invokeMethod('SystemNavigator.pop');
- },
- );
-
- Widget noButton = TextButton(
- child: Text("Later"),
- onPressed: () {
- if (session == ""){
- Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => LoginView()));
- } else {
- Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => HomeView()));
- }
- },
- );
-
- // set up the AlertDialog
- AlertDialog alert = AlertDialog(
- title: Text("Employee Self Service"),
- content: Text(title + "\n" + message),
- actions: [noButton, okButton],
- );
-
- // show the dialog
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return alert;
- },
- );
- } else if (block == "true") {
- Widget okButton = TextButton(
- child: Text(action),
- onPressed: () {
- if (action == "update") {
- _launchURL(Uri.parse("https://play.google.com/store/apps"));
- SystemChannels.platform.invokeMethod('SystemNavigator.pop');
- } else if (action == "close") {
- SystemChannels.platform.invokeMethod('SystemNavigator.pop');
- }
- },
- );
-
- // set up the AlertDialog
- AlertDialog alert = AlertDialog(
- title: Text("Employee Self Service"),
- content: Text(title + "\n" + message),
- actions: [okButton],
- );
-
- // show the dialog
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return alert;
- },
- );
- }
- }
- }
- } else {
- alertDialogFailedResponse(context);
- /*Fluttertoast.showToast(
- msg: "Server Response Error",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);*/
- }
- });
- }
-
- _launchURL(Uri url) async {
- if (await canLaunchUrl(url)) {
- await launchUrl(url);
- } else {
- throw 'Could not launch $url';
- }
- }
-
- alertDialogFailedResponse(BuildContext context){
- Widget okButton = TextButton(
- child: Text("Refresh"),
- onPressed: () {
- Navigator.of(context, rootNavigator: true).pop();
- Navigator.pushReplacement(context, MaterialPageRoute(
- builder: (context) => SplashScreen()));
- },
- );
-
- Widget noButton = TextButton(
- child: Text("Back"),
- onPressed: () {
- Navigator.of(context, rootNavigator: true).pop();
- Navigator.pop(context);
-
- },
- );
-
- // set up the AlertDialog
- AlertDialog alert = AlertDialog(
- title: Text("Employee Self Service"),
- content: Text("Server Response Error"),
- actions: [
- noButton,
- okButton,
- ],
- );
-
- // show the dialog
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return alert;
- },
- );
- }
|