GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

386 lines
14 KiB

import 'dart:async';
import 'dart:convert';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_udid/flutter_udid.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:employee_selfservice_mobile/Screens/ForgotPassword/forgotPassword_screen.dart';
import 'package:employee_selfservice_mobile/Screens/Login/background.dart';
import 'package:employee_selfservice_mobile/Screens/Login/login_post.dart';
import 'package:employee_selfservice_mobile/Screens/Splash/splash_screen.dart';
import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../Home/home_screen.dart';
import 'inputWidget.dart';
import 'dart:developer' as logDev;
//import 'package:plain_notification_token/plain_notification_token.dart';
class LoginView extends StatefulWidget {
@override
_LoginView createState() => _LoginView();
}
class _LoginView extends State<LoginView> {
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
body: Stack(
children: <Widget>[
Background(),
LoginScreen(),
],
));
}
}
class LoginScreen extends StatefulWidget {
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
late LoginPostResult loginPostResult;
String version = "1.0.0";
String notif_token = "";
late StreamSubscription onTokenRefreshSubscription;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
ProgressDialog loading = ProgressDialog(context);
loading = ProgressDialog(context,
type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
loading.style(
message: 'Please Wait .....',
borderRadius: 5,
backgroundColor: Colors.white,
progressWidget: CircularProgressIndicator(),
elevation: 10.0,
padding: EdgeInsets.all(10),
insetAnimCurve: Curves.easeInOut,
progress: 0.0,
maxProgress: 100.0,
progressTextStyle: TextStyle(
color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
messageTextStyle: TextStyle(
color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
return SingleChildScrollView(
reverse: true,
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: Column(
children: <Widget>[
Padding(
padding:
EdgeInsets.only(top: MediaQuery.of(context).size.height / 2.45),
),
Column(
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 0),
child: Text(
"Login",
style: GoogleFonts.knewave(
color: Colors.blueAccent, fontSize: 25),
),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 40, bottom: 5, top: 20),
child: Text(
"Email",
style: TextStyle(fontSize: 16, color: Colors.black87),
),
),
Stack(
alignment: Alignment.bottomRight,
children: <Widget>[
InputWidgetEmail(20.0, 20.0),
Padding(
padding: EdgeInsets.only(right: 50),
),
],
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 40, bottom: 5),
child: Text(
"Password",
style: TextStyle(fontSize: 16, color: Colors.black87),
),
),
Stack(
alignment: Alignment.bottomRight,
children: <Widget>[
InputWidgetPassword(20.0, 20.0),
Padding(
padding: EdgeInsets.only(right: 15),
child: Row(
children: <Widget>[
Expanded(
child: Padding(
padding: EdgeInsets.only(top: 0),
)),
InkWell(
child: Container(
padding: EdgeInsets.all(10),
decoration: ShapeDecoration(
shape: CircleBorder(),
gradient: LinearGradient(
colors: Gradients2,
begin: Alignment.topLeft,
end: Alignment.bottomRight),
),
child: ImageIcon(
AssetImage("assets/images/ic_forward.png"),
size: 40,
color: Colors.white,
),
),
onTap: () async {
/*String imei;
try {
imei = await FlutterUdid.udid;
} on PlatformException {
imei = 'Failed to get UDID.';
}
logDev.log(imei, name: "IMEI");*/
if (!validateForm(context)) {
return;
} else {
await loading.show();
final notif_token = await FirebaseMessaging.instance.getToken();
logDev.log(notif_token.toString(), name: "NOTIFICATION TOKEN");
LoginPostResult.connectToAPI(
emailController.text.toString(),
passwordController.text.toString(),
notif_token!,
version,
platform(),)
.then((valueResult) async {
Map<String, dynamic> object = json.decode(valueResult);
if (object.containsKey("result").toString() == "true") {
String status = object['result']['status'].toString();
if (status == "success") {
Fluttertoast.showToast(
msg: "Login Success",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
textColor: Colors.white,
fontSize: 16.0);
var prefs = await SharedPreferences.getInstance();
await prefs.setString('version', version);
await prefs.setString('device', object['result']['device'].toString());
await prefs.setString('session', object['result']['hash'].toString());
await prefs.setString('name', object['result']['name'].toString());
await prefs.setString('notif_token', notif_token);
emailController.clear();
passwordController.clear();
await loading.hide();
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => HomeView()));
} else if (status == "failed") {
String message = object['result']['message'].toString();
Fluttertoast.showToast(
msg: message,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
textColor: Colors.white,
fontSize: 16.0);
await loading.hide();
}
} else {
await loading.hide();
alertDialogFailedResponse(context);
}
});
}
},
)
],
),
),
/*Padding(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom)
)*/
],
),
],
),
Padding(
padding: EdgeInsets.only(bottom: 10),
),
InkWell(
child:
roundedRectButton("Forgot Password?", Gradients1, false),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ForgotPasswordView()));
})
],
)
],
),
);
}
}
Widget roundedRectButton(
String title, List<Color> gradient, bool isEndIconVisible) {
return Builder(builder: (BuildContext mContext) {
return Align(
alignment: Alignment.centerLeft,
child: Stack(
children: <Widget>[
Container(
alignment: Alignment.centerRight,
width: MediaQuery.of(mContext).size.width / 2.45,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(20.0),
bottomRight: Radius.circular(20.0))),
gradient: LinearGradient(
colors: gradient,
begin: Alignment.topLeft,
end: Alignment.bottomRight),
),
child: Text(title,
style: TextStyle(
decoration: TextDecoration.underline,
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.w500)),
padding: EdgeInsets.all(10),
),
Visibility(
visible: isEndIconVisible,
child: Padding(
padding: EdgeInsets.only(right: 10),
child: ImageIcon(
AssetImage("assets/images/ic_forward.png"),
size: 30,
color: Colors.white,
)),
),
],
),
);
});
}
const List<Color> Gradients1 = [
/*Color(0xFFFFFFFF),
Color(0xFFFFFFFF),*/
Color(0xFF03A0FE),
Colors.pink,
];
const List<Color> Gradients2 = [
Color(0xFFFF9945),
Color(0xFFFc6076),
];
bool validateForm(BuildContext context) {
bool result = true;
if (emailController.text.toString().isEmpty) {
/*final snackBar = SnackBar(content: Text("Email Required"));
ScaffoldMessenger.of(context).showSnackBar(snackBar);*/
Fluttertoast.showToast(
msg: "Email Required",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
textColor: Colors.white,
fontSize: 16.0);
result = false;
} else if (!emailController.text.toString().contains("@")) {
Fluttertoast.showToast(
msg: "Incorrect email format",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
textColor: Colors.white,
fontSize: 16.0);
result = false;
} else if (passwordController.text.toString().isEmpty) {
Fluttertoast.showToast(
msg: "Password Required",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
textColor: Colors.white,
fontSize: 16.0);
result = false;
}
return result;
}
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,
barrierDismissible: false,
builder: (BuildContext context) {
return alert;
},
);
}