Last active
October 14, 2020 13:17
-
-
Save triyono777/ce73160c6b6ac71fa46f0e6523c62858 to your computer and use it in GitHub Desktop.
Modul Flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class AddPegawaiPage extends StatefulWidget { | |
static const String routeName = '/AddPegawaiPage'; | |
@override | |
_AddPegawaiPageState createState() => _AddPegawaiPageState(); | |
} | |
class _AddPegawaiPageState extends State<AddPegawaiPage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Add Pegawai'), | |
), | |
body: Column( | |
children: [ | |
TemplateTextFormField(), | |
], | |
), | |
); | |
} | |
} | |
class TemplateTextFormField extends StatelessWidget { | |
const TemplateTextFormField({ | |
Key key, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return TextFormField( | |
decoration: InputDecoration( | |
labelText: 'Nama', | |
prefixIcon: Icon(Icons.person), | |
border: OutlineInputBorder( | |
borderRadius: BorderRadius.circular(15), | |
), | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:aplikasi_gaji_pegawai/ui/page/add_pegawai.dart'; | |
import 'package:flutter/material.dart'; | |
class ListPegawaiPage extends StatefulWidget { | |
@override | |
_ListPegawaiPageState createState() => _ListPegawaiPageState(); | |
} | |
class _ListPegawaiPageState extends State<ListPegawaiPage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('List Pegawai'), | |
), | |
body: ListView.builder( | |
itemCount: 10, | |
itemBuilder: (ctx, index) => ListTile( | |
title: Text('Nama'), | |
subtitle: Text('Umur'), | |
trailing: Text('Gaji'), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: Icon(Icons.add), | |
onPressed: () { | |
Navigator.of(context).pushNamed(AddPegawaiPage.routeName); | |
}, | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:aplikasi_gaji_pegawai/ui/page/add_pegawai.dart'; | |
import 'package:aplikasi_gaji_pegawai/ui/page/list_pegawai_page.dart'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Aplikasi Pegawai', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: ListPegawaiPage(), | |
routes: { | |
AddPegawaiPage.routeName:(ctx)=>AddPegawaiPage(), | |
}, | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'dart:convert'; | |
import 'package:aplikasi_gaji_pegawai/models/pegawai_model.dart'; | |
import 'package:aplikasi_gaji_pegawai/utils/utils.dart'; | |
import 'package:http/http.dart' as http; | |
class PegawaiController { | |
PegawaiModel pegawaiModel; | |
http.Response response; | |
Future<PegawaiModel> getListPegawai() async { | |
String url = Utils.listPegawai; | |
response = await http.get(url); | |
pegawaiModel = PegawaiModel.fromJson(jsonDecode(response.body)); | |
return pegawaiModel; | |
} | |
Future<bool> addPegawai({ | |
@required String nama, | |
@required String gaji, | |
@required String umur, | |
}) async { | |
String url = Utils.addPegawai; | |
response = await http.post(url, body: { | |
'employee_name': nama, | |
'employee_salary': gaji, | |
'employee_age': umur | |
}); | |
final hasil = jsonDecode(response.body); | |
print(hasil); | |
if (hasil['status'] == 'success') { | |
return true; | |
} | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:aplikasi_gaji_pegawai/controllers/pegawai_controllers.dart'; | |
import 'package:aplikasi_gaji_pegawai/ui/widgets/template_form_field.dart'; | |
import 'package:flutter/material.dart'; | |
class AddPegawaiPage extends StatefulWidget { | |
static const String routeName = '/AddPegawaiPage'; | |
@override | |
_AddPegawaiPageState createState() => _AddPegawaiPageState(); | |
} | |
class _AddPegawaiPageState extends State<AddPegawaiPage> { | |
TextEditingController namaController = TextEditingController(); | |
TextEditingController gajiController = TextEditingController(); | |
TextEditingController umurController = TextEditingController(); | |
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey(); | |
final _formKey = GlobalKey<FormState>(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
key: _scaffoldKey, | |
appBar: AppBar( | |
title: Text('Add Pegawai'), | |
), | |
body: Form( | |
key: _formKey, | |
child: Column( | |
children: [ | |
TemplateTextFormField( | |
keyboardType: TextInputType.text, | |
textEditingController: namaController, | |
icon: Icons.person, | |
label: 'Nama', | |
), | |
TemplateTextFormField( | |
keyboardType: TextInputType.number, | |
textEditingController: umurController, | |
icon: Icons.cake, | |
label: 'Umur', | |
), | |
TemplateTextFormField( | |
keyboardType: TextInputType.number, | |
textEditingController: gajiController, | |
icon: Icons.monetization_on, | |
label: 'Gaji', | |
), | |
RaisedButton( | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(15), | |
), | |
color: Theme.of(context).primaryColor, | |
textColor: Colors.white, | |
onPressed: () { | |
if (_formKey.currentState.validate()) { | |
PegawaiController() | |
.addPegawai( | |
nama: namaController.text, | |
gaji: gajiController.text, | |
umur: umurController.text, | |
) | |
.then((value) { | |
value == true | |
? Navigator.of(context).pop(true) | |
: _scaffoldKey.currentState.showSnackBar( | |
SnackBar(content: Text('Gagal Add Pegawai'))); | |
}); | |
} | |
}, | |
child: Text('Add Pegawai'), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:aplikasi_gaji_pegawai/controllers/pegawai_controllers.dart'; | |
import 'package:aplikasi_gaji_pegawai/models/pegawai_model.dart'; | |
import 'package:aplikasi_gaji_pegawai/ui/page/add_pegawai.dart'; | |
import 'package:flutter/material.dart'; | |
class ListPegawaiPage extends StatefulWidget { | |
@override | |
_ListPegawaiPageState createState() => _ListPegawaiPageState(); | |
} | |
class _ListPegawaiPageState extends State<ListPegawaiPage> { | |
PegawaiModel pegawaiModel; | |
@override | |
void initState() { | |
super.initState(); | |
getPegawai(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('List Pegawai'), | |
), | |
body: ListView.builder( | |
itemCount: 10, | |
itemBuilder: (ctx, index) => ListTile( | |
title: Text('Nama'), | |
subtitle: Text('Umur'), | |
trailing: Text('Gaji'), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: Icon(Icons.add), | |
onPressed: () { | |
Navigator.of(context).pushNamed(AddPegawaiPage.routeName); | |
}, | |
), | |
); | |
} | |
getPegawai() async { | |
PegawaiController().getListPegawai().then((value) { | |
setState(() { | |
pegawaiModel = value; | |
}); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'dart:convert'; | |
import 'package:aplikasi_gaji_pegawai/models/pegawai_model.dart'; | |
import 'package:aplikasi_gaji_pegawai/utils/utils.dart'; | |
import 'package:http/http.dart' as http; | |
class PegawaiController { | |
PegawaiModel pegawaiModel; | |
http.Response response; | |
Future<PegawaiModel> getListPegawai() async { | |
String url = Utils.listPegawai; | |
response = await http.get(url); | |
pegawaiModel = PegawaiModel.fromJson(jsonDecode(response.body)); | |
return pegawaiModel; | |
} | |
Future<bool> addPegawai({ | |
@required String nama, | |
@required String gaji, | |
@required String umur, | |
}) async { | |
String url = Utils.addPegawai; | |
response = await http.post(url, body: { | |
'employee_name': nama, | |
'employee_salary': gaji, | |
'employee_age': umur | |
}); | |
final hasil = jsonDecode(response.body); | |
print(hasil); | |
if (hasil['status'] == 'success') { | |
return true; | |
} | |
return false; | |
} | |
Future<bool> updatePegawai({ | |
@required String nama, | |
@required String gaji, | |
@required String umur, | |
@required String id, | |
}) async { | |
String url = Utils.updatePegawai; | |
response = await http.post(url, body: { | |
'id': id, | |
'employee_name': nama, | |
'employee_salary': gaji, | |
'employee_age': umur | |
}); | |
final hasil = jsonDecode(response.body); | |
print(hasil); | |
if (hasil['status'] == 'success') { | |
return true; | |
} | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:aplikasi_gaji_pegawai/controllers/pegawai_controllers.dart'; | |
import 'package:aplikasi_gaji_pegawai/models/pegawai_model.dart'; | |
import 'package:aplikasi_gaji_pegawai/ui/page/add_pegawai.dart'; | |
import 'package:flutter/material.dart'; | |
class ListPegawaiPage extends StatefulWidget { | |
@override | |
_ListPegawaiPageState createState() => _ListPegawaiPageState(); | |
} | |
class _ListPegawaiPageState extends State<ListPegawaiPage> { | |
PegawaiModel pegawaiModel; | |
@override | |
void initState() { | |
super.initState(); | |
getPegawai(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('List Pegawai'), | |
), | |
body: pegawaiModel == null | |
? Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
CircularProgressIndicator(), | |
Text('loading'), | |
], | |
)) | |
: ListView.builder( | |
itemCount: pegawaiModel.data.length, | |
itemBuilder: (ctx, index) => ListTile( | |
title: Text('Nama ${pegawaiModel.data[index].employeeName}'), | |
subtitle: Text('Umur ${pegawaiModel.data[index].employeeAge}'), | |
trailing: | |
Text('Gaji ${pegawaiModel.data[index].employeeSalary}'), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: Icon(Icons.add), | |
onPressed: () { | |
Navigator.of(context).pushNamed(AddPegawaiPage.routeName); | |
}, | |
), | |
); | |
} | |
getPegawai() async { | |
PegawaiController().getListPegawai().then((value) { | |
setState(() { | |
pegawaiModel = value; | |
}); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:aplikasi_gaji_pegawai/controllers/pegawai_controllers.dart'; | |
import 'package:aplikasi_gaji_pegawai/models/pegawai_model.dart'; | |
import 'package:aplikasi_gaji_pegawai/ui/page/add_pegawai.dart'; | |
import 'package:flutter/material.dart'; | |
class ListPegawaiPage extends StatefulWidget { | |
@override | |
_ListPegawaiPageState createState() => _ListPegawaiPageState(); | |
} | |
class _ListPegawaiPageState extends State<ListPegawaiPage> { | |
PegawaiModel pegawaiModel; | |
@override | |
void initState() { | |
super.initState(); | |
getPegawai(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('List Pegawai'), | |
), | |
body: pegawaiModel == null | |
? Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
CircularProgressIndicator(), | |
Text('loading'), | |
], | |
)) | |
: ListView.builder( | |
itemCount: pegawaiModel.data.length, | |
itemBuilder: (ctx, index) => ListTile( | |
title: Text('Nama ${pegawaiModel.data[index].employeeName}'), | |
subtitle: Text('Umur ${pegawaiModel.data[index].employeeAge}'), | |
trailing: | |
Text('Gaji ${pegawaiModel.data[index].employeeSalary}'), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: Icon(Icons.add), | |
onPressed: () async { | |
Navigator.of(context) | |
.pushNamed( | |
AddPegawaiPage.routeName, | |
) | |
.then( | |
(value) => getPegawai(), | |
); | |
}, | |
), | |
); | |
} | |
getPegawai() async { | |
PegawaiController().getListPegawai().then((value) { | |
setState(() { | |
pegawaiModel = value; | |
}); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:aplikasi_gaji_pegawai/controllers/pegawai_controllers.dart'; | |
import 'package:aplikasi_gaji_pegawai/models/pegawai_model.dart'; | |
import 'package:aplikasi_gaji_pegawai/ui/page/add_pegawai.dart'; | |
import 'package:flutter/material.dart'; | |
class ListPegawaiPage extends StatefulWidget { | |
@override | |
_ListPegawaiPageState createState() => _ListPegawaiPageState(); | |
} | |
class _ListPegawaiPageState extends State<ListPegawaiPage> { | |
PegawaiModel pegawaiModel; | |
@override | |
void initState() { | |
super.initState(); | |
getPegawai(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('List Pegawai'), | |
), | |
body: pegawaiModel == null | |
? Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
CircularProgressIndicator(), | |
Text('loading'), | |
], | |
)) | |
: RefreshIndicator( | |
onRefresh: () => getPegawai(), | |
child: ListView.builder( | |
itemCount: pegawaiModel.data.length, | |
itemBuilder: (ctx, index) => ListTile( | |
title: Text('Nama ${pegawaiModel.data[index].employeeName}'), | |
subtitle: | |
Text('Umur ${pegawaiModel.data[index].employeeAge}'), | |
trailing: | |
Text('Gaji ${pegawaiModel.data[index].employeeSalary}'), | |
), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: Icon(Icons.add), | |
onPressed: () async { | |
Navigator.of(context) | |
.pushNamed( | |
AddPegawaiPage.routeName, | |
) | |
.then( | |
(value) => getPegawai(), | |
); | |
}, | |
), | |
); | |
} | |
getPegawai() async { | |
PegawaiController().getListPegawai().then((value) { | |
setState(() { | |
pegawaiModel = value; | |
}); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'dart:convert'; | |
import 'package:aplikasi_gaji_pegawai/models/pegawai_model.dart'; | |
import 'package:aplikasi_gaji_pegawai/utils/utils.dart'; | |
import 'package:http/http.dart' as http; | |
class PegawaiController { | |
PegawaiModel pegawaiModel; | |
http.Response response; | |
Future<PegawaiModel> getListPegawai() async { | |
String url = Utils.listPegawai; | |
response = await http.get(url); | |
pegawaiModel = PegawaiModel.fromJson(jsonDecode(response.body)); | |
return pegawaiModel; | |
} | |
Future<bool> addPegawai({ | |
@required String nama, | |
@required String gaji, | |
@required String umur, | |
}) async { | |
String url = Utils.addPegawai; | |
response = await http.post(url, body: { | |
'employee_name': nama, | |
'employee_salary': gaji, | |
'employee_age': umur | |
}); | |
final hasil = jsonDecode(response.body); | |
print(hasil); | |
if (hasil['status'] == 'success') { | |
return true; | |
} | |
return false; | |
} | |
Future<bool> updatePegawai({ | |
@required String nama, | |
@required String gaji, | |
@required String umur, | |
@required String id, | |
}) async { | |
String url = Utils.updatePegawai; | |
response = await http.post(url, body: { | |
'id': id, | |
'employee_name': nama, | |
'employee_salary': gaji, | |
'employee_age': umur | |
}); | |
final hasil = jsonDecode(response.body); | |
print(hasil); | |
if (hasil['status'] == 'success') { | |
return true; | |
} | |
return false; | |
} | |
Future<bool> deletePegawai({@required String id}) async { | |
String url = Utils.deletePegawai; | |
response = await http.get(url + '?id=$id'); | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:aplikasi_gaji_pegawai/controllers/pegawai_controllers.dart'; | |
import 'package:aplikasi_gaji_pegawai/models/pegawai_model.dart'; | |
import 'package:aplikasi_gaji_pegawai/ui/page/add_pegawai.dart'; | |
import 'package:aplikasi_gaji_pegawai/ui/page/update_pegawai_page.dart'; | |
import 'package:flutter/material.dart'; | |
class ListPegawaiPage extends StatefulWidget { | |
@override | |
_ListPegawaiPageState createState() => _ListPegawaiPageState(); | |
} | |
class _ListPegawaiPageState extends State<ListPegawaiPage> { | |
PegawaiModel pegawaiModel; | |
@override | |
void initState() { | |
super.initState(); | |
getPegawai(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('List Pegawai'), | |
), | |
body: pegawaiModel == null | |
? Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
CircularProgressIndicator(), | |
Text('loading'), | |
], | |
)) | |
: RefreshIndicator( | |
onRefresh: () => getPegawai(), | |
child: ListView.builder( | |
itemCount: pegawaiModel.data.length, | |
itemBuilder: (ctx, index) => GestureDetector( | |
onTap: () async { | |
await Navigator.of(context) | |
.push(MaterialPageRoute( | |
builder: (ctx) => UpdatePegawaiPage( | |
id: '${pegawaiModel.data[index].id}', | |
gaji: '${pegawaiModel.data[index].employeeSalary}', | |
umur: '${pegawaiModel.data[index].employeeAge}', | |
nama: '${pegawaiModel.data[index].employeeName}', | |
), | |
)) | |
.then((value) => getPegawai()); | |
}, | |
child: ListTile( | |
title: | |
Text('Nama ${pegawaiModel.data[index].employeeName}'), | |
subtitle: | |
Text('Umur ${pegawaiModel.data[index].employeeAge}'), | |
trailing: | |
Text('Gaji ${pegawaiModel.data[index].employeeSalary}'), | |
), | |
), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: Icon(Icons.add), | |
onPressed: () async { | |
Navigator.of(context) | |
.pushNamed( | |
AddPegawaiPage.routeName, | |
) | |
.then( | |
(value) => getPegawai(), | |
); | |
}, | |
), | |
); | |
} | |
getPegawai() async { | |
PegawaiController().getListPegawai().then((value) { | |
setState(() { | |
pegawaiModel = value; | |
}); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:aplikasi_gaji_pegawai/controllers/pegawai_controllers.dart'; | |
import 'package:aplikasi_gaji_pegawai/models/pegawai_model.dart'; | |
import 'package:aplikasi_gaji_pegawai/ui/page/add_pegawai.dart'; | |
import 'package:aplikasi_gaji_pegawai/ui/page/update_pegawai_page.dart'; | |
import 'package:flutter/material.dart'; | |
class ListPegawaiPage extends StatefulWidget { | |
@override | |
_ListPegawaiPageState createState() => _ListPegawaiPageState(); | |
} | |
class _ListPegawaiPageState extends State<ListPegawaiPage> { | |
PegawaiModel pegawaiModel; | |
@override | |
void initState() { | |
super.initState(); | |
getPegawai(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('List Pegawai'), | |
), | |
body: pegawaiModel == null | |
? Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
CircularProgressIndicator(), | |
Text('loading'), | |
], | |
)) | |
: RefreshIndicator( | |
onRefresh: () => getPegawai(), | |
child: ListView.builder( | |
itemCount: pegawaiModel.data.length, | |
itemBuilder: (ctx, index) => GestureDetector( | |
onTap: () async { | |
await Navigator.of(context) | |
.push(MaterialPageRoute( | |
builder: (ctx) => UpdatePegawaiPage( | |
id: '${pegawaiModel.data[index].id}', | |
gaji: '${pegawaiModel.data[index].employeeSalary}', | |
umur: '${pegawaiModel.data[index].employeeAge}', | |
nama: '${pegawaiModel.data[index].employeeName}', | |
), | |
)) | |
.then((value) => getPegawai()); | |
}, | |
child: Dismissible( | |
key: UniqueKey(), | |
direction: DismissDirection.endToStart, | |
confirmDismiss: (DismissDirection direction) async { | |
final bool res = await showDialog( | |
context: context, | |
builder: (BuildContext context) { | |
return AlertDialog( | |
title: Text('Konfirmasi'), | |
content: Text('Kamu Yakin?'), | |
actions: <Widget>[ | |
FlatButton( | |
onPressed: () => | |
Navigator.of(context).pop(true), | |
child: Text('HAPUS'), | |
), | |
FlatButton( | |
onPressed: () => | |
Navigator.of(context).pop(false), | |
child: Text('BATALKAN'), | |
) | |
], | |
); | |
}); | |
return res; | |
}, | |
child: Padding( | |
padding: const EdgeInsets.symmetric( | |
horizontal: 8, vertical: 4), | |
child: Card( | |
child: ListTile( | |
title: Text( | |
'Nama ${pegawaiModel.data[index].employeeName}'), | |
subtitle: Text( | |
'Umur ${pegawaiModel.data[index].employeeAge}'), | |
trailing: Text( | |
'Gaji ${pegawaiModel.data[index].employeeSalary}'), | |
), | |
), | |
), | |
), | |
), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: Icon(Icons.add), | |
onPressed: () async { | |
Navigator.of(context) | |
.pushNamed( | |
AddPegawaiPage.routeName, | |
) | |
.then( | |
(value) => getPegawai(), | |
); | |
}, | |
), | |
); | |
} | |
getPegawai() async { | |
PegawaiController().getListPegawai().then((value) { | |
setState(() { | |
pegawaiModel = value; | |
}); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:aplikasi_gaji_pegawai/controllers/pegawai_controllers.dart'; | |
import 'package:aplikasi_gaji_pegawai/models/pegawai_model.dart'; | |
import 'package:aplikasi_gaji_pegawai/ui/page/add_pegawai.dart'; | |
import 'package:aplikasi_gaji_pegawai/ui/page/update_pegawai_page.dart'; | |
import 'package:flutter/material.dart'; | |
class ListPegawaiPage extends StatefulWidget { | |
@override | |
_ListPegawaiPageState createState() => _ListPegawaiPageState(); | |
} | |
class _ListPegawaiPageState extends State<ListPegawaiPage> { | |
PegawaiModel pegawaiModel; | |
@override | |
void initState() { | |
super.initState(); | |
getPegawai(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('List Pegawai'), | |
), | |
body: pegawaiModel == null | |
? Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
CircularProgressIndicator(), | |
Text('loading'), | |
], | |
)) | |
: RefreshIndicator( | |
onRefresh: () => getPegawai(), | |
child: ListView.builder( | |
itemCount: pegawaiModel.data.length, | |
itemBuilder: (ctx, index) => GestureDetector( | |
onTap: () async { | |
await Navigator.of(context) | |
.push(MaterialPageRoute( | |
builder: (ctx) => UpdatePegawaiPage( | |
id: '${pegawaiModel.data[index].id}', | |
gaji: '${pegawaiModel.data[index].employeeSalary}', | |
umur: '${pegawaiModel.data[index].employeeAge}', | |
nama: '${pegawaiModel.data[index].employeeName}', | |
), | |
)) | |
.then((value) => getPegawai()); | |
}, | |
child: Dismissible( | |
key: UniqueKey(), | |
direction: DismissDirection.endToStart, | |
confirmDismiss: (DismissDirection direction) async { | |
final bool res = await showDialog( | |
context: context, | |
builder: (BuildContext context) { | |
return AlertDialog( | |
title: Text('Konfirmasi'), | |
content: Text('Kamu Yakin?'), | |
actions: <Widget>[ | |
FlatButton( | |
onPressed: () => | |
Navigator.of(context).pop(true), | |
child: Text('HAPUS'), | |
), | |
FlatButton( | |
onPressed: () => | |
Navigator.of(context).pop(false), | |
child: Text('BATALKAN'), | |
) | |
], | |
); | |
}); | |
return res; | |
}, | |
onDismissed: (value) { | |
PegawaiController() | |
.deletePegawai(id: pegawaiModel.data[index].id) | |
.then((value) => getPegawai()); | |
}, | |
background: Container( | |
color: Colors.red, | |
child: Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.end, | |
children: [ | |
Icon( | |
Icons.delete, | |
color: Colors.white, | |
) | |
], | |
), | |
), | |
), | |
child: Padding( | |
padding: const EdgeInsets.symmetric( | |
horizontal: 8, vertical: 4), | |
child: Card( | |
child: ListTile( | |
title: Text( | |
'Nama ${pegawaiModel.data[index].employeeName}'), | |
subtitle: Text( | |
'Umur ${pegawaiModel.data[index].employeeAge}'), | |
trailing: Text( | |
'Gaji ${pegawaiModel.data[index].employeeSalary}'), | |
), | |
), | |
), | |
), | |
), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: Icon(Icons.add), | |
onPressed: () async { | |
Navigator.of(context) | |
.pushNamed( | |
AddPegawaiPage.routeName, | |
) | |
.then( | |
(value) => getPegawai(), | |
); | |
}, | |
), | |
); | |
} | |
getPegawai() async { | |
PegawaiController().getListPegawai().then((value) { | |
setState(() { | |
pegawaiModel = value; | |
}); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'dart:convert'; | |
import 'package:aplikasi_gaji_pegawai/models/pegawai_model.dart'; | |
import 'package:aplikasi_gaji_pegawai/utils/utils.dart'; | |
import 'package:http/http.dart' as http; | |
class PegawaiController { | |
PegawaiModel pegawaiModel; | |
http.Response response; | |
Future<PegawaiModel> getListPegawai() async { | |
String url = Utils.listPegawai; | |
response = await http.get(url); | |
pegawaiModel = PegawaiModel.fromJson(jsonDecode(response.body)); | |
return pegawaiModel; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class AddPegawaiPage extends StatefulWidget { | |
static const String routeName = '/AddPegawaiPage'; | |
@override | |
_AddPegawaiPageState createState() => _AddPegawaiPageState(); | |
} | |
class _AddPegawaiPageState extends State<AddPegawaiPage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Add Pegawai'), | |
), | |
body: Column( | |
children: [ | |
TextFormField( | |
decoration: InputDecoration( | |
labelText: 'Nama', | |
prefixIcon: Icon(Icons.person), | |
border: OutlineInputBorder( | |
borderRadius: BorderRadius.circular(15), | |
), | |
), | |
), | |
], | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def localProperties = new Properties() | |
def localPropertiesFile = rootProject.file('local.properties') | |
if (localPropertiesFile.exists()) { | |
localPropertiesFile.withReader('UTF-8') { reader -> | |
localProperties.load(reader) | |
} | |
} | |
def flutterRoot = localProperties.getProperty('flutter.sdk') | |
if (flutterRoot == null) { | |
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") | |
} | |
def flutterVersionCode = localProperties.getProperty('flutter.versionCode') | |
if (flutterVersionCode == null) { | |
flutterVersionCode = '1' | |
} | |
def flutterVersionName = localProperties.getProperty('flutter.versionName') | |
if (flutterVersionName == null) { | |
flutterVersionName = '1.0' | |
} | |
apply plugin: 'com.android.application' | |
apply plugin: 'kotlin-android' | |
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" | |
def keystoreProperties = new Properties() | |
def keystorePropertiesFile = rootProject.file('key.properties') | |
if (keystorePropertiesFile.exists()) { | |
keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) | |
} | |
android { | |
compileSdkVersion 28 | |
sourceSets { | |
main.java.srcDirs += 'src/main/kotlin' | |
} | |
lintOptions { | |
disable 'InvalidPackage' | |
} | |
defaultConfig { | |
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). | |
applicationId "id.phicosdev.flutter_webview" | |
minSdkVersion 16 | |
targetSdkVersion 28 | |
versionCode flutterVersionCode.toInteger() | |
versionName flutterVersionName | |
} | |
signingConfigs { | |
release { | |
keyAlias keystoreProperties['keyAlias'] | |
keyPassword keystoreProperties['keyPassword'] | |
storeFile file(keystoreProperties['storeFile']) | |
storePassword keystoreProperties['storePassword'] | |
} | |
} | |
buildTypes { | |
release { | |
// TODO: Add your own signing config for the release build. | |
// Signing with the debug keys for now, so `flutter run --release` works. | |
signingConfig signingConfigs.release | |
} | |
} | |
} | |
flutter { | |
source '../..' | |
} | |
dependencies { | |
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
storePassword=passwod_saat_buat_key | |
keyPassword=passwod_saat_buat_key | |
keyAlias=nama_alias_key | |
storeFile=/Users/phicosmac/keystorecoba.jks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class ListPegawaiPage extends StatefulWidget { | |
@override | |
_ListPegawaiPageState createState() => _ListPegawaiPageState(); | |
} | |
class _ListPegawaiPageState extends State<ListPegawaiPage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('List Pegawai'), | |
), | |
body: ListView.builder( | |
itemCount: 10, | |
itemBuilder: (ctx, index) => ListTile( | |
title: Text('Nama'), | |
subtitle: Text('Umur'), | |
trailing: Text('Gaji'), | |
), | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:aplikasi_gaji_pegawai/ui/page/list_pegawai_page.dart'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Aplikasi Pegawai', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: ListPegawaiPage(), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PegawaiModel { | |
String status; | |
List<DataPegawaiModel> data; | |
PegawaiModel({this.status, this.data}); | |
PegawaiModel.fromJson(Map<String, dynamic> json) { | |
status = json['status']; | |
if (json['data'] != null) { | |
data = new List<DataPegawaiModel>(); | |
json['data'].forEach((v) { | |
data.add(new DataPegawaiModel.fromJson(v)); | |
}); | |
} | |
} | |
Map<String, dynamic> toJson() { | |
final Map<String, dynamic> data = new Map<String, dynamic>(); | |
data['status'] = this.status; | |
if (this.data != null) { | |
data['data'] = this.data.map((v) => v.toJson()).toList(); | |
} | |
return data; | |
} | |
} | |
class DataPegawaiModel { | |
String id; | |
String employeeName; | |
String employeeSalary; | |
String employeeAge; | |
String profileImage; | |
DataPegawaiModel( | |
{this.id, | |
this.employeeName, | |
this.employeeSalary, | |
this.employeeAge, | |
this.profileImage}); | |
DataPegawaiModel.fromJson(Map<String, dynamic> json) { | |
id = json['id']; | |
employeeName = json['employee_name']; | |
employeeSalary = json['employee_salary']; | |
employeeAge = json['employee_age']; | |
profileImage = json['profile_image']; | |
} | |
Map<String, dynamic> toJson() { | |
final Map<String, dynamic> data = new Map<String, dynamic>(); | |
data['id'] = this.id; | |
data['employee_name'] = this.employeeName; | |
data['employee_salary'] = this.employeeSalary; | |
data['employee_age'] = this.employeeAge; | |
data['profile_image'] = this.profileImage; | |
return data; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class TemplateTextFormField extends StatelessWidget { | |
final String label; | |
final IconData icon; | |
final TextEditingController textEditingController; | |
final TextInputType keyboardType; | |
const TemplateTextFormField({ | |
Key key, | |
this.label = 'label', | |
this.icon = Icons.label, | |
this.textEditingController, | |
this.keyboardType = TextInputType.text, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Padding( | |
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), | |
child: TextFormField( | |
validator: (text) { | |
if (text == null || text.isEmpty) { | |
return 'Inputan tidak boleh kosong'; | |
} | |
return null; | |
}, | |
controller: textEditingController, | |
keyboardType: keyboardType, | |
decoration: InputDecoration( | |
labelText: label, | |
hintText: 'Masukkan $label disini', | |
prefixIcon: Icon(icon), | |
border: OutlineInputBorder( | |
borderRadius: BorderRadius.circular(15), | |
)), | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:aplikasi_gaji_pegawai/controllers/pegawai_controllers.dart'; | |
import 'package:aplikasi_gaji_pegawai/ui/widgets/template_form_field.dart'; | |
import 'package:flutter/material.dart'; | |
class UpdatePegawaiPage extends StatefulWidget { | |
static const String routeName = '/UpdatePegawaiPage'; | |
final String id; | |
final String nama; | |
final String gaji; | |
final String umur; | |
const UpdatePegawaiPage({Key key, this.id, this.nama, this.gaji, this.umur}) | |
: super(key: key); | |
@override | |
_UpdatePegawaiPageState createState() => _UpdatePegawaiPageState(); | |
} | |
class _UpdatePegawaiPageState extends State<UpdatePegawaiPage> { | |
TextEditingController namaController = TextEditingController(); | |
TextEditingController gajiController = TextEditingController(); | |
TextEditingController umurController = TextEditingController(); | |
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey(); | |
final _formKey = GlobalKey<FormState>(); | |
getdata() { | |
setState(() { | |
namaController.text = widget.nama; | |
gajiController.text = widget.gaji; | |
umurController.text = widget.umur; | |
}); | |
} | |
@override | |
void initState() { | |
super.initState(); | |
getdata(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
key: _scaffoldKey, | |
appBar: AppBar( | |
title: Text('Update Pegawai'), | |
), | |
body: Form( | |
key: _formKey, | |
child: Column( | |
children: [ | |
TemplateTextFormField( | |
keyboardType: TextInputType.text, | |
textEditingController: namaController, | |
icon: Icons.person, | |
label: 'Nama', | |
), | |
TemplateTextFormField( | |
keyboardType: TextInputType.number, | |
textEditingController: umurController, | |
icon: Icons.cake, | |
label: 'Umur', | |
), | |
TemplateTextFormField( | |
keyboardType: TextInputType.number, | |
textEditingController: gajiController, | |
icon: Icons.monetization_on, | |
label: 'Gaji', | |
), | |
RaisedButton( | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(15), | |
), | |
color: Theme.of(context).primaryColor, | |
textColor: Colors.white, | |
onPressed: () { | |
if (_formKey.currentState.validate()) { | |
PegawaiController() | |
.updatePegawai( | |
id: widget.id, | |
nama: namaController.text, | |
gaji: gajiController.text, | |
umur: umurController.text, | |
) | |
.then((value) { | |
value == true | |
? Navigator.of(context).pop(true) | |
: _scaffoldKey.currentState.showSnackBar( | |
SnackBar(content: Text('Gagal Update Pegawai'))); | |
}); | |
} | |
}, | |
child: Text('Update Pegawai'), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Utils { | |
static const String baseUrl = 'http://employee-crud-flutter.daengweb.id'; | |
static const String listPegawai = '$baseUrl/index.php'; | |
static const String addPegawai = '$baseUrl/add.php'; | |
static const String updatePegawai = '$baseUrl/update.php'; | |
static const String deletePegawai = '$baseUrl/delete.php'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment