1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021 |
- import 'dart:convert';
- import 'dart:io';
- 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/Settings/RequestHttp/changePassword_post.dart';
- import 'package:hris_selfservice_mobile/Screens/Settings/RequestHttp/changeprofileimage_post.dart';
- import 'package:hris_selfservice_mobile/Screens/Settings/RequestHttp/getDetail_post.dart';
- import 'package:hris_selfservice_mobile/Screens/Settings/RequestHttp/getProfileImage_post.dart';
- import 'package:hris_selfservice_mobile/Screens/Settings/RequestHttp/logout_post.dart';
- import 'package:image_picker/image_picker.dart';
- import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import '../Login/login_screen.dart';
- import '../Settings/inputWidget.dart';
- import 'dart:developer' as logDev;
-
- class SettingsScreen extends StatefulWidget {
- const SettingsScreen({Key? key}) : super(key: key);
-
- @override
- State<SettingsScreen> createState() => _SettingsScreenState();
- }
-
- class _SettingsScreenState extends State<SettingsScreen> {
- bool visible = false;
- bool visiblePersonalInformation = false;
- File? _imagePath;
-
- String name = "",
- statusDetail = "",
- dateOfBirth = "",
- phone = "",
- email = "",
- address = "",
- position = "";
-
- var _imageToShow;
-
- @override
- initState() {
- super.initState();
- passwordController.clear();
- newPasswordController.clear();
- retypeNewPasswordController.clear();
- getDetail();
- _imageToShow = AssetImage('assets/images/ic_administrator.png');
- WidgetsBinding.instance.addPostFrameCallback((_) {
- 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));
- loading.show();
- _imageToShow = getProfileImage();
- });
- }
-
- //Get Profile image
- getProfileImage() async {
- final SharedPreferences prefs = await SharedPreferences.getInstance();
- final session = prefs.getString('session');
-
- 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));
-
- GetProfileImage_Post.connectToAPI(session!).then((valueResult) async {
- Map<String, dynamic> object = json.decode(valueResult);
- if (object.containsKey("result").toString() == "true") {
- String status = object['result']['status'].toString();
- logDev.log(status, name: "STATUS GET PROFILE");
- if (status == "success") {
- String photo = object['result']['photo'].toString();
- if (photo == "false") {
- setState(() {
- _imageToShow = AssetImage('assets/images/ic_administrator.png');
- });
- } else if (photo != "false") {
- Uint8List decodedBytes = Base64Decoder().convert(photo);
- logDev.log(decodedBytes.toString(), name: "DECODED BYTES photo");
- setState(() {
- _imageToShow = Image.memory(decodedBytes, gaplessPlayback: true).image;
- });
- }
- } else if (status == "failed") {
- String message = object['result']['message'].toString();
- Fluttertoast.showToast(
- msg: message,
- toastLength: Toast.LENGTH_LONG,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- }
- loading.hide();
- } else {
- Fluttertoast.showToast(
- msg: "Server Response Error",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- loading.hide();
- }
- });
- loading.hide();
- return _imageToShow;
- }
-
- //Get Detail
- getDetail() async {
- GetDetail_Post.connectToAPI().then((valueResult) async {
- Map<String, dynamic> object = json.decode(valueResult);
- if (object.containsKey("result").toString() == "true") {
- statusDetail = object['result']['status'].toString();
- String message = object['result']['message'].toString();
- if (statusDetail == "failed" || message == "User Not Found") {
- Fluttertoast.showToast(
- msg: message + ", Please restart the Application!",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- } else if (statusDetail != "failed") {
- name = object['result']['name'].toString();
- dateOfBirth = object['result']['date_of_birth'].toString();
- phone = object['result']['phone'].toString();
- email = object['result']['email'].toString();
- address = object['result']['address'].toString();
- position = object['result']['position'].toString();
-
- if (name == "false"){
- name = "-";
- }
- if (dateOfBirth == "false"){
- dateOfBirth = "-";
- }
- if (phone == "false"){
- phone = "-";
- }
- if (email == "false"){
- email = "-";
- }
- if (address == "false"){
- address = "-";
- }
- }
- } else {
- Fluttertoast.showToast(
- msg: "Server Response Error",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
-
- }
- });
- }
-
- @override
- Widget build(BuildContext context) {
- var size = MediaQuery.of(context).size;
-
- 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 Scaffold(
- body: SingleChildScrollView(
- child: Stack(
- children: <Widget>[
- Container(
- height: size.height * 0.3,
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topRight,
- end: Alignment.bottomRight,
- colors: [
- Color(0xFF4858A7),
- Color(0xFF6474C6),
- ])),
- ),
- SafeArea(
- child: Padding(
- padding: EdgeInsets.all(20),
- child: Column(
- children: <Widget>[
- Stack(
- alignment: Alignment.topCenter,
- children: [
- Container(
- margin: EdgeInsets.only(top: (((size.width - 20) * 0.33) * 0.5)),
- child: Card(
- elevation: 15,
- child: Container(
- height: (size.height * 0.28) * .7,
- width: size.width - 20,
- padding: EdgeInsets.all(15),
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius:
- BorderRadius.all(Radius.circular(10))),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.end,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- Text(name,
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- textAlign: TextAlign.center,
- style: GoogleFonts.inter(
- fontSize: 18,
- color: Colors.black,
- fontWeight: FontWeight.bold),
- ),
- Text(position,
- textAlign: TextAlign.center,
- style: GoogleFonts.inter(
- fontSize: 17, color: Colors.black),
- ),
- ],
- )),
- ),
- ),
- Container(
- height: (size.width - 20) * 0.33,
- width: (size.width - 20) * 0.33,
- decoration: BoxDecoration(
- color: Colors.black,
- image: DecorationImage(
- image: _imageToShow,
- fit: BoxFit.fill,
- ),
- shape: BoxShape.circle,
- ),
- ),
- InkWell(
- child: Container(
- height: ((size.width - 20) * 0.33) * 0.25,
- width: ((size.width - 20) * 0.33) * 0.25,
- margin: EdgeInsets.only(
- top: (((size.width - 20) * 0.33) - 20),
- left: ((size.width - 20) * 0.33) - 10),
- decoration: BoxDecoration(
- color: Colors.yellow,
- image: DecorationImage(
- image: AssetImage('assets/images/ic_camera.png'),
- scale: 3,
- fit: BoxFit.scaleDown,
- ),
- shape: BoxShape.circle,
- ),
- ),
- onTap: () async {
- final ImagePicker _picker = ImagePicker();
- final XFile? imagePicked = await _picker.pickImage(
- source: ImageSource.gallery);
- if (imagePicked != null) {
- _imagePath = File(imagePicked.path);
- List<int> imageBytes = _imagePath!.readAsBytesSync();
- String base64Image = base64Encode(imageBytes);
- //logDev.log(base64Image, name: "String base64");
- await loading.show();
- ChangeProfileImage_Post.connectToAPI(base64Image).then((valueResult) async {
- Map<String, dynamic> 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") {
- _imageToShow = FileImage(File(imagePicked.path));
- /* Fluttertoast.showToast(
- msg: message,
- toastLength: Toast.LENGTH_LONG,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);*/
- await loading.hide();
- showAlertDialogChangeProfile(context, "Success, " + message, "Ok");
- } else if (status == "failed") {
- /* Fluttertoast.showToast(
- msg: message,
- toastLength: Toast.LENGTH_LONG,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);*/
- await loading.hide();
- showAlertDialogChangeProfile(context, "Failed, " + message, "Back");
- }
- } 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();
- }
- setState(() {});
- });
- } else if (imagePicked == null) {
- //_imagePath = await getImageFileFromAssets('assets/images/ic_administrator.png') as File?;
- }
- },
- )
- ],
- ),
- InkWell(
- child: roundedRectButton(
- "Personal Information", Gradients1, 20, 5),
- onTap: () async {
- setState(() {
- visiblePersonalInformation =
- !visiblePersonalInformation;
- });
- },
- ),
- Visibility(
- visible: visiblePersonalInformation,
- child: Container(
- margin: EdgeInsets.only(top: 10),
- width: size.width - 50,
- padding: EdgeInsets.all(15),
- decoration: BoxDecoration(
- color: Color(0xFFD9D9D9),
- borderRadius: BorderRadius.all(Radius.circular(5))),
- child: Column(
- children: [
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(bottom: 5),
- child: Text(
- "Name",
- style: TextStyle(
- fontSize: 16, color: Colors.black87),
- ),
- ),
- Stack(
- alignment: Alignment.bottomRight,
- children: <Widget>[
- roundDetail(name, 0, 5, 3),
- ],
- ),
- ],
- ),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(bottom: 5),
- child: Text(
- "Status",
- style: TextStyle(
- fontSize: 16, color: Colors.black87),
- ),
- ),
- Stack(
- alignment: Alignment.bottomRight,
- children: <Widget>[
- roundDetail(statusDetail, 0, 5, 3),
- ],
- ),
- ],
- ),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(bottom: 5),
- child: Text(
- "Date of Birth",
- style: TextStyle(
- fontSize: 16, color: Colors.black87),
- ),
- ),
- Stack(
- alignment: Alignment.bottomRight,
- children: <Widget>[
- roundDetail(dateOfBirth, 0, 5, 3),
- ],
- ),
- ],
- ),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(bottom: 5),
- child: Text(
- "Phone Number",
- style: TextStyle(
- fontSize: 16, color: Colors.black87),
- ),
- ),
- Stack(
- alignment: Alignment.bottomRight,
- children: <Widget>[
- roundDetail(phone, 0, 5, 3),
- ],
- ),
- ],
- ),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(bottom: 5),
- child: Text(
- "Email Address",
- style: TextStyle(
- fontSize: 16, color: Colors.black87),
- ),
- ),
- Stack(
- alignment: Alignment.bottomRight,
- children: <Widget>[
- roundDetail(email, 0, 5, 3),
- ],
- ),
- ],
- ),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(bottom: 5),
- child: Text(
- "Address",
- style: TextStyle(
- fontSize: 16, color: Colors.black87),
- ),
- ),
- Stack(
- alignment: Alignment.bottomRight,
- children: <Widget>[
- roundDetail(address, 0, 5, 3),
- ],
- ),
- ],
- ),
- /*InkWell(
- child: roundedRectButton(
- "Save Password", Gradients2, 10, 10),
- onTap: () {
- if (!validateFormSavePassword(context)) {
- return;
- } else if (validateFormSavePassword(context)) {
- if (newPasswordController.text.toString() ==
- retypeNewPasswordController.text
- .toString()) {
- if (passwordController.text.toString() ==
- newPasswordController.text
- .toString() ||
- passwordController.text.toString() ==
- retypeNewPasswordController.text
- .toString()) {
- Fluttertoast.showToast(
- msg:
- "Your new password is the same with your old password, please change with new password!",
- toastLength: Toast.LENGTH_LONG,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- } else {
- showAlertDialogSavePassword(context);
- }
- } else if (newPasswordController.text
- .toString() !=
- retypeNewPasswordController.text
- .toString()) {
- Fluttertoast.showToast(
- msg:
- "Your retype password was entered incorrectly.\nPlease enter it again!",
- toastLength: Toast.LENGTH_LONG,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- }
- }
- }),*/
- ],
- ),
- ),
- ),
- InkWell(
- child:
- roundedRectButton("Edit Password", Gradients1, 10, 5),
- onTap: () {
- setState(() {
- visible = !visible;
- });
- },
- ),
- Visibility(
- visible: visible,
- child: Container(
- margin: EdgeInsets.only(top: 10),
- width: size.width - 50,
- padding: EdgeInsets.all(15),
- decoration: BoxDecoration(
- color: Color(0xFFD9D9D9),
- borderRadius: BorderRadius.all(Radius.circular(5))),
- child: Column(
- children: [
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(bottom: 5),
- child: Text(
- "Type your current Password",
- style: TextStyle(
- fontSize: 16, color: Colors.black87),
- ),
- ),
- Stack(
- alignment: Alignment.bottomRight,
- children: <Widget>[
- InputWidgetCurrentPassword(
- "Current Password"),
- ],
- ),
- ],
- ),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(bottom: 5),
- child: Text(
- "Type your New Password",
- style: TextStyle(
- fontSize: 16, color: Colors.black87),
- ),
- ),
- Stack(
- alignment: Alignment.bottomRight,
- children: <Widget>[
- InputWidgetNewPassword("New Password"),
- ],
- ),
- ],
- ),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(bottom: 5),
- child: Text(
- "Re-type your New Password",
- style: TextStyle(
- fontSize: 16, color: Colors.black87),
- ),
- ),
- Stack(
- alignment: Alignment.bottomRight,
- children: <Widget>[
- InputWidgetRetypeNewPassword(
- "Re-type New Password"),
- ],
- ),
- ],
- ),
- InkWell(
- child: roundedRectButton(
- "Save Password", Gradients2, 10, 10),
- onTap: () {
- if (!validateFormSavePassword(context)) {
- return;
- } else if (validateFormSavePassword(context)) {
- if (newPasswordController.text.toString() ==
- retypeNewPasswordController.text
- .toString()) {
- if (passwordController.text.toString() ==
- newPasswordController.text
- .toString() ||
- passwordController.text.toString() ==
- retypeNewPasswordController.text
- .toString()) {
- Fluttertoast.showToast(
- msg:
- "Your new password is the same with your old password, please change with new password!",
- toastLength: Toast.LENGTH_LONG,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- } else {
- showAlertDialogSavePassword(context);
- }
- } else if (newPasswordController.text
- .toString() !=
- retypeNewPasswordController.text
- .toString()) {
- Fluttertoast.showToast(
- msg:
- "Your retype password was entered incorrectly.\nPlease enter it again!",
- toastLength: Toast.LENGTH_LONG,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- }
- }
- }),
- ],
- ),
- ),
- ),
- InkWell(
- child: roundedRectButton("Logout", Gradients1, 10, 5),
- onTap: () {
- showAlertDialogLogout(context);
- }),
- ],
- ),
- ),
- ),
- ],
- ),
- ));
- }
- }
-
- Widget roundedRectButton(String title, List<Color> gradient, double marginTop,
- double radiusCircular) {
- return Builder(builder: (BuildContext mContext) {
- return Align(
- alignment: Alignment.center,
- child: Stack(
- children: <Widget>[
- Container(
- margin: EdgeInsets.only(top: marginTop),
- alignment: Alignment.center,
- height: 55,
- width: MediaQuery.of(mContext).size.width - 50,
- decoration: ShapeDecoration(
- shape: RoundedRectangleBorder(
- borderRadius:
- BorderRadius.all(Radius.circular(radiusCircular))),
- gradient: LinearGradient(
- colors: gradient,
- begin: Alignment.topLeft,
- end: Alignment.bottomRight),
- ),
- child: Padding(
- padding: EdgeInsets.fromLTRB(10, 3, 10, 3),
- child: Text(title,
- style: TextStyle(
- color: Colors.white,
- fontSize: 19,
- fontWeight: FontWeight.w500)),
- ),
- padding: EdgeInsets.all(10),
- )
- ],
- ),
- );
- });
- }
-
- Widget roundDetail(String detail, double marginTop, double marginBottom,
- double radiusCircular) {
- return Builder(builder: (BuildContext mContext) {
- return Align(
- alignment: Alignment.center,
- child: Stack(
- children: <Widget>[
- Container(
- margin: EdgeInsets.only(top: marginTop, bottom: marginBottom),
- alignment: Alignment.centerLeft,
- height: 45,
- width: MediaQuery.of(mContext).size.width - 50,
- decoration: ShapeDecoration(
- shape: RoundedRectangleBorder(
- borderRadius:
- BorderRadius.all(Radius.circular(radiusCircular))),
- color: Colors.blueGrey,
- ),
- child: Padding(
- padding: EdgeInsets.fromLTRB(3, 3, 3, 3),
- child: Text(detail,
- style: TextStyle(
- color: Colors.white,
- fontSize: 15,
- fontWeight: FontWeight.w500)),
- ),
- padding: EdgeInsets.all(10),
- )
- ],
- ),
- );
- });
- }
-
- const List<Color> Gradients1 = [
- //Color(0xFF0EDED2),
- Color(0xFF03A0FE),
- Color(0xFF4858A7),
- //Color(0xFF6474C6),
- ];
-
- const List<Color> Gradients2 = [
- Color(0xFFFF9945),
- Color(0xFFFc6076),
- ];
-
- //Save New Password
- showAlertDialogSavePassword(BuildContext context) {
- // set up the button
- Widget okButton = TextButton(
- child: Text("Yes"),
- onPressed: () async {
- 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));
- await loading.show();
-
- ChangePassword_Post.connectToAPI(passwordController.text.toString(), newPasswordController.text.toString()).then((valueResult) async {
- Map<String, dynamic> 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") {
- Fluttertoast.showToast(
- msg: message + ", Please login again!",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
-
- passwordController.clear();
- newPasswordController.clear();
- retypeNewPasswordController.clear();
-
- final SharedPreferences prefs = await SharedPreferences.getInstance();
- await prefs.remove('session');
- await loading.hide();
- Navigator.of(context, rootNavigator: true).pop();
- Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => LoginView()));
- } else if (status == "failed") {
- Fluttertoast.showToast(
- msg: message,
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- Navigator.of(context, rootNavigator: true).pop();
- 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();
- }
- });
- },
- );
-
- Widget noButton = TextButton(
- child: Text("No"),
- onPressed: () {
- Navigator.of(context, rootNavigator: true).pop();
- },
- );
-
- // set up the AlertDialog
- AlertDialog alert = AlertDialog(
- title: Text("Employee Self Service"),
- content: Text("Save New Password?"),
- actions: [noButton, okButton],
- );
-
- // show the dialog
- showDialog(
- context: context,
- barrierDismissible: false,
- builder: (BuildContext context) {
- return alert;
- },
- );
- }
-
- //Validate Form Change Password
- bool validateFormSavePassword(BuildContext context) {
- bool result = true;
-
- if (passwordController.text.toString().isEmpty) {
- Fluttertoast.showToast(
- msg: "Old Password Required!",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- result = false;
- }
-
- if (newPasswordController.text.toString().isEmpty) {
- Fluttertoast.showToast(
- msg: "New Password Required",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- result = false;
- }
-
- if (retypeNewPasswordController.text.toString().isEmpty) {
- Fluttertoast.showToast(
- msg: "Retype New Password Required",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- result = false;
- }
-
- return result;
- }
-
- //LOGOUT
- showAlertDialogLogout(BuildContext context) {
- // set up the button
- Widget okButton = TextButton(
- child: Text("Yes"),
- onPressed: () async {
- 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));
- await loading.show();
-
- Logout_Post.connectToAPI().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") {
- final SharedPreferences prefs = await SharedPreferences.getInstance();
- await prefs.remove('session');
- Navigator.of(context, rootNavigator: true).pop();
- await loading.hide();
- Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context) => LoginView()), (route) => false);
- } 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();
- Navigator.of(context, rootNavigator: true).pop();
- }
- } 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();
- Navigator.of(context, rootNavigator: true).pop();
- }
- });
- },
- );
-
- Widget noButton = TextButton(
- child: Text("No"),
- onPressed: () {
- Navigator.of(context, rootNavigator: true).pop();
- },
- );
-
- // set up the AlertDialog
- AlertDialog alert = AlertDialog(
- title: Text("Employee Self Service"),
- content: Text("Are you sure you want to logout from this Application?"),
- //content: Text("Apakah Anda yakin ingin keluar dari aplikasi ini?"),
- actions: [noButton, okButton],
- );
-
- // show the dialog
- showDialog(
- context: context,
- barrierDismissible: false,
- builder: (BuildContext context) {
- return alert;
- },
- );
- }
-
- //Alert Change Profile
- showAlertDialogChangeProfile(BuildContext context, String message, String buttonMessage) {
- // set up the button
- Widget okButton = TextButton(
- child: Text(buttonMessage),
- onPressed: () {
- Navigator.of(context, rootNavigator: true).pop();
- },
- );
-
- // set up the AlertDialog
- AlertDialog alert = AlertDialog(
- title: Text("Employee Self Service"),
- content: Text(message),
- actions: [okButton],
- );
-
- // show the dialog
- showDialog(
- context: context,
- barrierDismissible: false,
- builder: (BuildContext context) {
- return alert;
- },
- );
- }
|