Skip to content

Commit

Permalink
Merge pull request #33 from ryanaidilp/5.0.3
Browse files Browse the repository at this point in the history
add ability to check if attendance is being canceled 5.0.3
  • Loading branch information
ryanaidilp authored May 31, 2021
2 parents 6816bfd + ca99019 commit 896c220
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 59 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ android {
applicationId "com.banuacoders.siap"
minSdkVersion 24
targetSdkVersion 30
versionCode 45
versionName '5.0.2'
versionCode 46
versionName '5.0.3'
}

signingConfigs {
Expand Down
11 changes: 0 additions & 11 deletions lib/repositories/data_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,6 @@ class DataRepository {
return result;
}

Future<Map<String, dynamic>> getEmployeePresence(DateTime date) async {
Map<String, dynamic> data;
try {
data =
await apiService.getEndpointData(endpoint: Endpoint.presence, query: {
'date': date.toString(),
});
} catch (e) {}
return data;
}

Future<Response> cancelAttendance(Map<String, dynamic> data) async {
Response response;
try {
Expand Down
139 changes: 97 additions & 42 deletions lib/screen/employee_attendance_screen.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'dart:convert';

import 'package:flare_flutter/flare_actor.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:search_page/search_page.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:spo_balaesang/models/employee.dart';
import 'package:spo_balaesang/models/user.dart';
import 'package:spo_balaesang/repositories/data_repository.dart';
import 'package:spo_balaesang/screen/report_screen.dart';
import 'package:spo_balaesang/utils/app_const.dart';

Expand All @@ -19,25 +19,30 @@ class EmployeeAttendanceScreen extends StatefulWidget {

class _EmployeeAttendanceScreenState extends State<EmployeeAttendanceScreen> {
List<Employee> _employees;
bool _isLoading = false;

@override
void setState(void Function() fn) {
if (mounted) super.setState(fn);
}

void _setLoading(bool isLoading) {
setState(() {
_isLoading = isLoading;
});
}

Future<void> loadData() async {
final sp = await SharedPreferences.getInstance();
do {
final _dataEmployees = sp.get(prefsEmployeeKey);
final List<dynamic> _jsonEmployees =
jsonDecode(_dataEmployees.toString()) as List<dynamic>;
try {
_setLoading(true);
final dataRepo = Provider.of<DataRepository>(context, listen: false);
final List<Employee> _jsonEmployees = await dataRepo.getAllEmployee();
setState(() {
_employees = _jsonEmployees
.map((employee) =>
Employee.fromJson(employee as Map<String, dynamic>))
.toList();
_employees = _jsonEmployees;
});
} while (_employees.isEmpty);
} catch (e) {} finally {
_setLoading(false);
}
}

@override
Expand Down Expand Up @@ -177,6 +182,83 @@ class _EmployeeAttendanceScreenState extends State<EmployeeAttendanceScreen> {
);
}

Widget _buildContent() {
if (_isLoading) {
return const SizedBox(
child: Center(
child: SpinKitCircle(
size: 45,
color: Colors.blueAccent,
)),
);
}

if (_employees == null || _employees.isEmpty) {
return SizedBox(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
width: Get.width * 0.5,
height: Get.height * 0.3,
child: const FlareActor(
'assets/flare/failure.flr',
animation: 'failure',
),
),
const Text('Gagal memuat data pegawai!'),
sizedBoxH20,
ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6)),
primary: Colors.blueAccent,
onPrimary: Colors.white),
onPressed: loadData,
child: const Text('Coba Lagi'),
)
]),
),
);
}

return ListView.builder(
itemBuilder: (context, index) => _buildEmployeeCard(_employees[index]),
itemCount: _employees?.length ?? 0,
);
}

Future<Employee> _onSearchButtonPressed() async {
if (_employees == null || _employees.isEmpty) {
return null;
}

return showSearch(
context: context,
delegate: SearchPage(
searchLabel: 'Cari Pegawai',
barTheme: ThemeData(
appBarTheme: const AppBarTheme(
brightness: Brightness.dark,
color: Colors.blueAccent,
),
),
showItemsOnEmpty: true,
failure: _buildEmptyWidget(),
builder: (Employee employee) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: _buildEmployeeCard(employee),
),
filter: (Employee employee) => [
employee.name,
employee.status,
employee.nip,
employee.department
],
items: _employees));
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -185,40 +267,13 @@ class _EmployeeAttendanceScreenState extends State<EmployeeAttendanceScreen> {
title: const Text('Presensi Pegawai'),
actions: <Widget>[
IconButton(
onPressed: () => showSearch(
context: context,
delegate: SearchPage(
searchLabel: 'Cari Pegawai',
barTheme: ThemeData(
appBarTheme: const AppBarTheme(
brightness: Brightness.dark,
color: Colors.blueAccent,
),
),
showItemsOnEmpty: true,
failure: _buildEmptyWidget(),
builder: (Employee employee) => Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8.0),
child: _buildEmployeeCard(employee),
),
filter: (Employee employee) => [
employee.name,
employee.status,
employee.nip,
employee.department
],
items: _employees)),
onPressed: _onSearchButtonPressed,
icon: const Icon(Icons.search_rounded))
],
),
body: Padding(
padding: const EdgeInsets.only(bottom: 8, left: 8, right: 8),
child: ListView.builder(
itemBuilder: (context, index) =>
_buildEmployeeCard(_employees[index]),
itemCount: _employees?.length ?? 0,
),
child: _buildContent(),
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/screen/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class _LoginScreenState extends State<LoginScreen> {
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[
Text(
'v5.0.2',
'v5.0.3',
style: TextStyle(
color: Colors.grey,
fontSize: 12.0,
Expand Down
2 changes: 1 addition & 1 deletion lib/screen/splash_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class _SplashScreenState extends State<SplashScreen> {
color: Colors.white,
fontWeight: FontWeight.w700)),
SizedBox(width: 2.0),
Text('v5.0.2', style: TextStyle(color: Colors.white)),
Text('v5.0.3', style: TextStyle(color: Colors.white)),
Spacer()
],
),
Expand Down
22 changes: 20 additions & 2 deletions lib/widgets/employee_presence_card_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ class EmployeePresenceCardWidget extends StatelessWidget {
);
}

String checkAddressLabel() {
if (int.parse(point.substring(0, point.length - 1)) == 0 &&
address.isNotEmpty) {
return 'Alasan Pembatalan';
}

return 'Lokasi';
}

IconData checkAddressIcon() {
if (int.parse(point.substring(0, point.length - 1)) == 0 &&
address.isNotEmpty) {
return Icons.notes_rounded;
}

return Icons.location_on_rounded;
}

@override
Widget build(BuildContext context) {
return Container(
Expand Down Expand Up @@ -156,12 +174,12 @@ class EmployeePresenceCardWidget extends StatelessWidget {
Row(
children: <Widget>[
Icon(
Icons.location_on,
checkAddressIcon(),
color: Colors.grey[600],
size: 20.0,
),
sizedBoxW4,
Text('Lokasi', style: labelTextStyle)
Text(checkAddressLabel(), style: labelTextStyle)
],
),
sizedBoxH4,
Expand Down

0 comments on commit 896c220

Please sign in to comment.