123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020 |
- 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();
- logDev.log(getProfileImage().toString(), name: "APA ISINYA");
- _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") {
- _imageToShow = AssetImage('assets/images/ic_administrator.png');
- logDev.log("PHOTO RESULT FALSE", name: "DECODED BYTES");
- } 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;
- });
- //_imageToShow = Image.memory(base64Decode(photo));
- //logDev.log(_imageToShow.toString(), name: "Image to Show");
- //_imageToShow = AssetImage('assets/images/collaboration.png');
- }
- } 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();
- }
- });
- //return Image.memory(decodedBytes);
- loading.hide();
- return _imageToShow;
- }
-
- //Get Detail
- getDetail() async {
- final SharedPreferences prefs = await SharedPreferences.getInstance();
- final session = prefs.getString('session');
- GetDetail_Post.connectToAPI(session!).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 login again!",
- 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(0xFFD21404),
- Color(0xFFFD7267),
- ])),
- ),
- 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 SharedPreferences prefs =
- await SharedPreferences.getInstance();
- final String? session = prefs.getString('session');
- 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(
- session!, base64Image)
- .then((valueResult) async {
- logDev.log(valueResult, name: "HASIL CHANGE");
- 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();
- } 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();
- }
- } 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) {
- logDev.log("NULL", name: "NO IMAGE SELECTED");
- //_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(
- "Nama Pegawai",
- 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(
- "Tanggal Lahir",
- 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(
- "Nomor Telepon",
- 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(
- "Alamat Email",
- 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(
- "Alamat Rumah",
- 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,
- /*gradient: LinearGradient(
- colors: gradient,
- begin: Alignment.topLeft,
- end: Alignment.bottomRight),*/
- ),
- 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),
- ];
-
- 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();
-
- final SharedPreferences prefs = await SharedPreferences.getInstance();
- final session = prefs.getString('session');
- ChangePassword_Post.connectToAPI(passwordController.text.toString(),
- newPasswordController.text.toString(), session!)
- .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 session = await prefs.remove('session');
- logDev.log(session.toString(), name: "SESSION KEHAPUS GAAAA?");
- 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,
- 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();
-
- final SharedPreferences prefs = await SharedPreferences.getInstance();
- final session = prefs.getString('session');
-
- Logout_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();
- if (status == "success") {
- final session = await prefs.remove('session');
- logDev.log(session.toString(), name: "SESSION KEHAPUS GA?");
- 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,
- builder: (BuildContext context) {
- return alert;
- },
- );
- }
|