import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hris_selfservice_mobile/Screens/ForgotPassword/resetPassword_post.dart'; import 'package:hris_selfservice_mobile/Screens/Login/background.dart'; import 'package:hris_selfservice_mobile/Screens/Login/inputWidget.dart'; import 'package:hris_selfservice_mobile/Screens/Login/login_screen.dart'; import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart'; class ForgotPasswordView extends StatefulWidget { @override _ForgotPasswordView createState() => _ForgotPasswordView(); } class _ForgotPasswordView extends State { @override Widget build(BuildContext context) { return Scaffold( resizeToAvoidBottomInset: false, backgroundColor: Colors.white, body: Stack( children: [ Background(), ForgotPasswordScreen(), ], )); } } class ForgotPasswordScreen extends StatelessWidget { const ForgotPasswordScreen({Key? key}) : super(key: key); @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 Column( children: [ Padding( padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 2.45), ), Column( children: [ Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Padding( padding: EdgeInsets.only(top: 0), child: Text( "Forgot Password", style: GoogleFonts.knewave( color: Colors.blueAccent, fontSize: 25), ), ), ], ), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ 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: [ InputWidgetEmail(20.0, 20.0), Padding( padding: EdgeInsets.only(right: 15), child: Row( children: [ 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 { if (emailController.text.toString().isEmpty){ Fluttertoast.showToast( msg: "Email Required", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); } else { await loading.show(); ResetPassword_Post.connectToAPI(emailController.text.toString()) .then((valueResult) async{ Map object = json.decode(valueResult); if (object.containsKey("result").toString() == "true") { String status = object['result']['status'].toString(); String message = object['result']['message'].toString(); if (status == "success") { emailController.clear(); await loading.hide(); Widget okButton = TextButton( child: Text("OK"), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.pushAndRemoveUntil( context, MaterialPageRoute( builder: (context) => LoginView()), (route) => false); }, ); // set up the AlertDialog AlertDialog alert = AlertDialog( title: Text("Employee Self Service"), content: Text(message), actions: [ okButton, ], ); // show the dialog showDialog( context: context, builder: (BuildContext context) { return alert; }, ); } 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 { Fluttertoast.showToast( msg: "Server Response Error", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); await loading.hide(); } }); } }, ) ], ), ), ], ), ], ), Padding( padding: EdgeInsets.only(bottom: 10), ), ], ) ], ); } } Widget roundedRectButton( String title, List gradient, bool isEndIconVisible) { return Builder(builder: (BuildContext mContext) { return Align( alignment: Alignment.centerLeft, child: Stack( children: [ Container( alignment: Alignment.centerRight, width: MediaQuery.of(mContext).size.width / 2.5, 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( 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, )), ), ], ), ); }); } //Alert Dialog showAlertDialog(BuildContext context) { // set up the button Widget okButton = TextButton( child: Text("OK"), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.pushAndRemoveUntil( context, MaterialPageRoute( builder: (context) => LoginView()), (route) => false); }, ); // set up the AlertDialog AlertDialog alert = AlertDialog( title: Text("Employee Self Service"), content: Text("Please check your email."), actions: [ okButton, ], ); // show the dialog showDialog( context: context, builder: (BuildContext context) { return alert; }, ); } const List Gradients1 = [ Color(0xFF0EDED2), Color(0xFF03A0FE), ]; const List Gradients2 = [ Color(0xFFFF9945), Color(0xFFFc6076), ];