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.
 
 
 
 
 

865 lines
37 KiB

import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:double_back_to_close/double_back_to_close.dart';
import 'package:employee_selfservice_mobile/Screens/Menu/EventCalendar/eventCalendar_screen.dart';
import 'package:employee_selfservice_mobile/Screens/Menu/IDP/idp_screen.dart';
import 'package:employee_selfservice_mobile/Screens/NotificationCenter/NotificationCenter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:focus_detector/focus_detector.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:employee_selfservice_mobile/Screens/Menu/About/about_screen.dart';
import 'package:employee_selfservice_mobile/Screens/Menu/Absensi/absensi_screen.dart';
import 'package:employee_selfservice_mobile/Screens/Menu/AjukanCuti/ajukancuti_screen.dart';
import 'package:employee_selfservice_mobile/Screens/Menu/Reimburse/reimburse_screen.dart';
import 'package:employee_selfservice_mobile/Screens/Menu/SlipGaji/slipgaji_screen.dart';
import 'package:employee_selfservice_mobile/Screens/Menu/SuratTugas/surattugas_screen.dart';
import 'package:employee_selfservice_mobile/Screens/Settings/settings_screen.dart';
import 'package:lottie/lottie.dart';
import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:developer' as logDev;
import '../Menu/IPP/ipp_screen.dart';
import '../Settings/RequestHttp/getDetail_post.dart';
import '../Settings/RequestHttp/getProfileImage_post.dart';
import 'package:internet_connection_checker/internet_connection_checker.dart';
late String nameShared;
String name = "",
statusDetail = "",
dateOfBirth = "",
phone = "",
email = "",
address = "",
position = "";
var _imageToShow;
class HomeView extends StatefulWidget {
@override
_HomeView createState() => _HomeView();
}
class _HomeView extends State<HomeView> {
late StreamSubscription subscription;
bool isDeviceConnected = false;
bool isAlertSet = false;
//var _imageToShow;
@override
initState() {
getConnectivity();
getDetail();
_imageToShow = AssetImage('assets/images/ic_administrator.png');
WidgetsBinding.instance.addPostFrameCallback((_) {
getProfileImage();
});
super.initState();
}
getConnectivity() =>
subscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) async {
isDeviceConnected = await InternetConnectionChecker().hasConnection;
if (!isDeviceConnected && isAlertSet == false) {
showConnectivityDialogBox();
setState(() => isAlertSet = true);
}
} as void Function(List<ConnectivityResult> event)?,
);
@override
void dispose() {
subscription.cancel();
super.dispose();
}
//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));
await loading.show();
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/icons/ic_pp_2.png');
});
} else if (photo != "false") {
Uint8List decodedBytes = Base64Decoder().convert(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);
}
} 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();
});
return _imageToShow;
}
//GetDetail
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 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();
var prefs = await SharedPreferences.getInstance();
if (position == "false") {
position = "-";
await prefs.setString('position', position);
} else {
await prefs.setString('position', position);
}
}
} else {
Fluttertoast.showToast(
msg: "Server Response Error",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
textColor: Colors.white,
fontSize: 16.0);
}
});
}
int _selectedIndex = 0;
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
if (index == 0) {
}
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: DoubleBack(
/*onFirstBackPress: (context) {
final snackBar = SnackBar(content: Text("Double Back Press to Exit"));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},*/
message: "Double Back Press to Exit",
background: Colors.black38,
backgroundRadius: 10,
textStyle: TextStyle(
fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white),
child: Scaffold(
resizeToAvoidBottomInset: false,
//backgroundColor: Colors.white,
body: Stack(
children: <Widget>[
//Background(),
//HomeScreen(),
BottomNavBar()
],
)),
),
);
}
showConnectivityDialogBox() =>
showCupertinoDialog<String>(
context: context,
builder: (BuildContext context) =>
CupertinoAlertDialog(
title: const Text('No Connection'),
content: const Text('Please check your internet connectivity'),
actions: <Widget>[
Column(
children: [
SizedBox(
width: 250,
height: 250,
child: LottieBuilder.asset(
//'assets/animation/animation_no_internet.json',
'assets/animation/animation_no_internet_3.json',
repeat: true),
),
],
),
TextButton(
onPressed: () async {
Navigator.pop(context, 'Cancel');
setState(() => isAlertSet = false);
isDeviceConnected =
await InternetConnectionChecker().hasConnection;
if (!isDeviceConnected && isAlertSet == false) {
showConnectivityDialogBox();
setState(() => isAlertSet = true);
}
},
child: const Text('Retry'),
),
],
),
);
}
class BottomNavBar extends StatefulWidget {
const BottomNavBar({Key? key}) : super(key: key);
@override
State<BottomNavBar> createState() => _BottomNavBarState();
}
class _BottomNavBarState extends State<BottomNavBar> {
List<Widget> _widgetOptions = <Widget>[
HomeScreen(),
NotificationCenter_Screen(),
SettingsScreen(),
];
int _selectedIndex = 0;
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: _widgetOptions.elementAt(_selectedIndex),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.notifications),
label: 'Notification',
), BottomNavigationBarItem(
icon: Icon(Icons.person),
label: 'Profile',
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.white,
backgroundColor: Color(0xFF5666b7),
onTap: _onItemTapped),
);
}
}
class HomeScreen extends StatefulWidget {
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
//Get Profile image
getProfileImage() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
final session = prefs.getString('session');
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/icons/ic_pp_2.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);
}
} else {
Fluttertoast.showToast(
msg: "Server Response Error",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
textColor: Colors.white,
fontSize: 16.0);
}
});
return _imageToShow;
}
@override
Widget build(BuildContext context) {
var size = MediaQuery
.of(context)
.size;
return FocusDetector(
/*onVisibilityGained: (){
getProfileImage();
},
onVisibilityLost: (){
getProfileImage();
},
onFocusLost: (){
getProfileImage();
},*/
onFocusGained: () {
getProfileImage();
},
/* onForegroundLost: (){
getProfileImage();
},
onForegroundGained: (){
getProfileImage();
},*/
child: 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),
//Color(0xFF8C99DD),
])),
),
SafeArea(
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
/* Align(
alignment: Alignment.topRight,
child: InkWell(
child: Container(
alignment: Alignment.center,
height: 40,
width: 40,
child: Image.asset('assets/images/ic_settings.png')),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SettingsScreen()));
},
),
),*/
Container(
child: Stack(
alignment: Alignment.topLeft,
children: [
Container(
margin: EdgeInsets.only(
top: (((size.width - 20) * 0.33) * 0.5) +
40),
child: Card(
elevation: 15,
child: Container(
height: size.width * 0.35,
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: size.width * 0.045,
color: Colors.black,
fontWeight: FontWeight.bold),
),
Text(position,
textAlign: TextAlign.center,
style: GoogleFonts.inter(
fontSize: size.width * 0.035,
color: Colors.black),
),
],
)),
),
),
Align(
alignment: Alignment.topCenter,
child: Container(
margin: EdgeInsets.only(left: 15, top: 40),
alignment: Alignment.topLeft,
height: (size.width - 20) * 0.33,
width: (size.width - 20) * 0.33,
decoration: BoxDecoration(
color: Colors.black,
image: DecorationImage(
image: _imageToShow,
fit: BoxFit.cover,
),
shape: BoxShape.circle,
),
),
),
],
),
),
GridView.count(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
padding: EdgeInsets.only(top: 25, left: 5, right: 5),
crossAxisSpacing: 15,
mainAxisSpacing: 15,
crossAxisCount: 2,
childAspectRatio: 1.0,
children: <Widget>[
InkWell(
child: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
color: Color(0xFFD0D0D0),
borderRadius: BorderRadius.circular(5)),
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: size.width * 0.18,
child: Image.asset(
"assets/icons/menu/ic_absensi_3.png",
fit: BoxFit.contain)
),
Container(
margin: EdgeInsets.only(top: 5),
child: Text(
'Attendance',
textAlign: TextAlign.center,
style: GoogleFonts.acme(
fontSize: size.width * 0.045,
color: Colors.black),
),
)
],
),
)
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
AbsensiScreen()));
}),
InkWell(
child: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
color: Color(0xFFD0D0D0),
borderRadius: BorderRadius.circular(5)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: size.width * 0.18,
child: Image.asset(
"assets/icons/menu/ic_slipgaji_4.png",
fit: BoxFit.contain),
),
Container(
margin: EdgeInsets.only(top: 5),
child: Text(
'Pay Slip',
textAlign: TextAlign.center,
style: GoogleFonts.acme(
fontSize: size.width * 0.045,
color: Colors.black),
),
)
],
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
SlipGajiScreen()));
},
),
InkWell(
child: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
color: Color(0xFFD0D0D0),
borderRadius: BorderRadius.circular(5)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: size.width * 0.18,
child: Image.asset(
"assets/icons/menu/ic_cuti_4.png",
fit: BoxFit.contain),
),
Container(
margin: EdgeInsets.only(top: 5),
child: Text(
'Leaves',
textAlign: TextAlign.center,
style: GoogleFonts.acme(
fontSize: size.width * 0.045,
color: Colors.black),
),
)
],
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
AjukanCutiScreen()));
},
),
InkWell(
child: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
color: Color(0xFFD0D0D0),
borderRadius: BorderRadius.circular(5)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: size.width * 0.18,
child: Image.asset(
"assets/icons/menu/ic_surattugas_3.png",
fit: BoxFit.contain,
),
),
Container(
margin: EdgeInsets.only(top: 5),
child: Text(
'Assignment Letter',
textAlign: TextAlign.center,
style: GoogleFonts.acme(
fontSize: size.width * 0.045,
color: Colors.black),
),
)
],
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
SuratTugas_Screen()));
},
),
InkWell(
child: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
color: Color(0xFFD0D0D0),
borderRadius: BorderRadius.circular(5)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: size.width * 0.18,
child: Image.asset(
"assets/icons/menu/ic_reimburse_4.png",
fit: BoxFit.contain,
),
),
Container(
margin: EdgeInsets.only(top: 5),
child: Text(
'Reimbursement',
textAlign: TextAlign.center,
style: GoogleFonts.acme(
fontSize: size.width * 0.045,
color: Colors.black),
),
)
],
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
ReimburseScreen()));
},
),
InkWell(
child: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
color: Color(0xFFD0D0D0),
borderRadius: BorderRadius.circular(5)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: size.width * 0.18,
child: Image.asset(
"assets/icons/menu/ic_idp_4.png",
fit: BoxFit.contain,
),
),
Container(
margin: EdgeInsets.only(top: 5),
child: Text(
'Individual\nDevelopment Plan',
textAlign: TextAlign.center,
style: GoogleFonts.acme(
fontSize: size.width * 0.045,
color: Colors.black),
),
)
],
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => IDPScreen()));
},
),
InkWell(
child: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
color: Color(0xFFD0D0D0),
borderRadius: BorderRadius.circular(5)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: size.width * 0.18,
child: Image.asset(
"assets/icons/menu/ic_ipp_2.png",
fit: BoxFit.contain,
),
),
Container(
margin: EdgeInsets.only(top: 5),
child: Text(
'Individual\nPerformance Plan',
textAlign: TextAlign.center,
style: GoogleFonts.acme(
fontSize: size.width * 0.045,
color: Colors.black),
),
)
],
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => IPPScreen()));
},
),
InkWell(
child: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
color: Color(0xFFD0D0D0),
borderRadius: BorderRadius.circular(5)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: size.width * 0.18,
child: Image.asset(
"assets/icons/menu/ic_eventcalendar.png",
fit: BoxFit.contain,
),
),
Container(
margin: EdgeInsets.only(top: 5),
child: Text(
'Event Calendar',
textAlign: TextAlign.center,
style: GoogleFonts.acme(
fontSize: size.width * 0.045,
color: Colors.black),
),
)
],
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EventCalendarScreen()));
},
),
InkWell(
child: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
color: Color(0xFFD0D0D0),
borderRadius: BorderRadius.circular(5)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: size.width * 0.18,
child: Image.asset(
"assets/icons/menu/ic_about_9.png",
fit: BoxFit.contain,
),
),
Container(
margin: EdgeInsets.only(top: 5),
child: Text(
'About',
textAlign: TextAlign.center,
style: GoogleFonts.acme(
fontSize: size.width * 0.045,
color: Colors.black),
),
)
],
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AboutScreen()));
},
),
],
)
],
),
),
),
/*Center(
child: _widgetOptions.elementAt(_selectedIndex),
)*/
],
),
)
),
);
}
}