Commit 8c93b59a authored by Fikri's avatar Fikri

menambahkan get api pada halaman dashboard contact us

parent 580c14bb
...@@ -6,6 +6,11 @@ import 'package:medapp_eksad/model/contact_model.dart'; ...@@ -6,6 +6,11 @@ import 'package:medapp_eksad/model/contact_model.dart';
var cmd = 'https://dmsdev-api.eksad.com/gateway/medapp/v1/cmd'; var cmd = 'https://dmsdev-api.eksad.com/gateway/medapp/v1/cmd';
var qry = 'https://dmsdev-api.eksad.com/gateway/medapp/v1/qry'; var qry = 'https://dmsdev-api.eksad.com/gateway/medapp/v1/qry';
Future<List<dynamic>> getcontact() async {
var response = await http.get(Uri.parse('$qry/contact/get'));
return jsonDecode(response.body)['data'];
}
Future<bool> savecontact(nama, email, nohp, message) async { Future<bool> savecontact(nama, email, nohp, message) async {
final response = await http.post( final response = await http.post(
Uri.parse('$cmd/contact/save'), Uri.parse('$cmd/contact/save'),
...@@ -25,12 +30,3 @@ Future<bool> savecontact(nama, email, nohp, message) async { ...@@ -25,12 +30,3 @@ Future<bool> savecontact(nama, email, nohp, message) async {
// return response.statusCode; // return response.statusCode;
} }
Future<List<contact>> showcontact() async {
var response = await http
.get(Uri.parse('$qry/contact/get'));
var resultJson = jsonDecode(response.body)['data'];
List<contact> contactlist = await resultJson
.map<contact>((json) => contact.fromJson(json))
.toList();
return contactlist;
}
\ No newline at end of file
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:medapp_eksad/api/contact_api.dart';
class Dashboard4 extends StatefulWidget { class Dashboard4 extends StatefulWidget {
const Dashboard4({Key? key}) : super(key: key); const Dashboard4({Key? key}) : super(key: key);
...@@ -9,45 +9,14 @@ class Dashboard4 extends StatefulWidget { ...@@ -9,45 +9,14 @@ class Dashboard4 extends StatefulWidget {
State<Dashboard4> createState() => _Dashboard4State(); State<Dashboard4> createState() => _Dashboard4State();
} }
class MessageUser {
String date;
String name;
String email;
String message;
String number;
MessageUser(
this.date,
this.name,
this.email,
this.message,
this.number
);
}
class _Dashboard4State extends State<Dashboard4> { class _Dashboard4State extends State<Dashboard4> {
List<MessageUser> ListMessage = <MessageUser>[ final formKey = GlobalKey<FormState>();
MessageUser("1", "Jay", 'email', 'message', 'number'),
MessageUser('2', 'Rizky', 'email', 'message', 'nomer'),
MessageUser('1', "Arham", 'email', 'message', 'number'),
MessageUser('2', 'Faid', 'email', 'message', 'nomer'),MessageUser('1', "Bagas", 'email', 'message', 'number'),
MessageUser('2', 'Fikri', 'email', 'message', 'nomer'),MessageUser('1', "Budi", 'email', 'message', 'number'),
MessageUser('2', 'Fahrur', 'email', 'message', 'nomer'),
];
@override
void initState() {
super.initState();
}
refreshList() {
setState(() {
ListMessage=ListMessage;
});
}
int id = 0;
String name = '';
String email = '';
String massage = '';
String number = '';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -61,8 +30,7 @@ class _Dashboard4State extends State<Dashboard4> { ...@@ -61,8 +30,7 @@ class _Dashboard4State extends State<Dashboard4> {
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: const Color.fromARGB(255, 10, 116, 255) color: const Color.fromARGB(255, 10, 116, 255).withAlpha(60),
.withAlpha(60),
blurRadius: 5.0, blurRadius: 5.0,
spreadRadius: 5.0, spreadRadius: 5.0,
offset: const Offset( offset: const Offset(
...@@ -75,90 +43,161 @@ class _Dashboard4State extends State<Dashboard4> { ...@@ -75,90 +43,161 @@ class _Dashboard4State extends State<Dashboard4> {
children: [ children: [
Container( Container(
height: screenSize.height * 0.15, height: screenSize.height * 0.15,
child: Center( child: Center(
child: Text('Data Messages from User',style: GoogleFonts.poppins( child: Text(
'Data Messages from User',
style: GoogleFonts.poppins(
height: 1.5, height: 1.5,
fontSize: 31, fontSize: 31,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: Colors.blueAccent[200]),), color: Colors.blueAccent[200]),
), ),
), ),
),
// Container(
// height: screenSize.height * 0.63,
// width: screenSize.width * 0.95,
// decoration:
// BoxDecoration(borderRadius: BorderRadius.circular(40)),
// //color: Colors.white,
// child: PaginatedDataTable(
// rowsPerPage: 5,
// // header :Text("Data Message User"),
// columnSpacing: 150,
// columns: [
// DataColumn(label: Text("ID")),
// DataColumn(label: Text("Name")),
// DataColumn(label: Text("Email")),
// DataColumn(label: Text("Message")),
// DataColumn(label: Text("Number")),
// ], source: ,
// ),
// ),
Container( Container(
// height: screenSize.height*0.63, height: screenSize.height * 0.65,
width: screenSize.width*0.95, child: ListView(
decoration: BoxDecoration(borderRadius: BorderRadius.circular(40)), controller: ScrollController(),
//color: Colors.white, children: [
child: PaginatedDataTable( FutureBuilder<List<dynamic>>(
rowsPerPage:5, future: getcontact(),
// header :Text("Data Message User"), builder: (BuildContext context, AsyncSnapshot snapshot) {
columnSpacing: 150, if (snapshot.hasError ||
columns: [ snapshot.data == null ||
DataColumn(label: Text("Date"),), snapshot.connectionState == ConnectionState.waiting) {
DataColumn(label: Text("Name"),), return const CircularProgressIndicator();
DataColumn(label: Text("Email"),), }
DataColumn(label: Text("Message"),), return DataTable(
DataColumn(label: Text("Number"),), decoration: const BoxDecoration(color: Colors.white),
], columnSpacing: 105,
source: UserDataTableSource(userData: ListMessage)), columns: const [
) DataColumn(label: Text("ID")),
DataColumn(label: Text("Date")),
DataColumn(label: Text("Name")),
DataColumn(label: Text("Email")),
DataColumn(label: Text("Message")),
DataColumn(label: Text("Number")),
], ],
rows: List.generate(
snapshot.data.length,
(index) {
var pgm = snapshot.data[index];
return DataRow(
cells: [
DataCell(
Text(pgm['idContact'].toString()),
),
DataCell(
Text(pgm['namaContact']),
), ),
DataCell(
Text(pgm['dateContact']),
), ),
DataCell(
Text(pgm['emailContact']),
),
DataCell(
Text(pgm['messageContact']),
),
DataCell(
Text(pgm['noHp']),
),
// DataCell(
// Row(
// children: [
// TextButton(
// style: TextButton.styleFrom(
// padding: const EdgeInsets.all(16.0),
// primary: Colors.white,
// backgroundColor: const Color.fromARGB(
// 255, 245, 27, 27),
// textStyle:
// const TextStyle(fontSize: 15),
// ),
// onPressed: () {
// showDialog(
// context: context,
// builder: (context) {
// return AlertDialog(
// title: const Text("Warning"),
// content: Text(
// "Are you sure want to delete data page ${pgm['title']}?"),
// actions: <Widget>[
// TextButton(
// child: const Text("Yes"),
// onPressed: () {
// Navigator.pop(context);
// deletePage(pgm['idpage'])
// .then((isSuccess) {
// if (isSuccess) {
// setState(() {});
// Scaffold.of(
// this.context)
// .showSnackBar(
// const SnackBar(
// content: Text(
// "Delete data success")));
// } else {
// Scaffold.of(
// this.context)
// .showSnackBar(
// const SnackBar(
// content: Text(
// "Delete data failed")));
// }
// });
// },
// ),
// TextButton(
// child: const Text("No"),
// onPressed: () {
// Navigator.pop(context);
// },
// ),
// ],
// );
// },
// );
// },
// child: const Text("Delete"),
// ),
// ],
// ),
// ),
],
); );
},
).toList(),
);
},
),
],
),
),
}
}
class UserDataTableSource extends DataTableSource {
UserDataTableSource({
required List<MessageUser> userData,
})
: _userData = userData,
assert(userData != null);
final List<MessageUser> _userData;
@override
DataRow? getRow(int index) {
assert(index >= 0);
if (index >= _userData.length) {
return null;
}
final _user = _userData[index];
return DataRow.byIndex(
index: index,
cells: <DataCell>[
DataCell(Text('${_user.date}')),
DataCell(Text('${_user.name}')),
DataCell(Text('${_user.email}')),
DataCell(Text('${_user.message}')),
DataCell(Text('${_user.number}')),
], ],
),
),
); );
} }
@override
bool get isRowCountApproximate => false;
@override
int get rowCount => _userData.length;
@override
int get selectedRowCount => 0;
void sort<T>(Comparable<T> Function(MessageUser d) getField, bool ascending) {
_userData.sort((a, b) {
final aValue = getField(a);
final bValue = getField(b);
return ascending
? Comparable.compare(aValue, bValue)
: Comparable.compare(bValue, aValue);
});
notifyListeners();
}
} }
...@@ -259,10 +259,7 @@ class _SignInState extends State<SignIn> { ...@@ -259,10 +259,7 @@ class _SignInState extends State<SignIn> {
); );
} else if (_usernamecontroller.value.text == 'admin@admin.com' && } else if (_usernamecontroller.value.text == 'admin@admin.com' &&
_passwordcontroller.value.text == 'administrator') { _passwordcontroller.value.text == 'administrator') {
Navigator.pushNamed(context, '/admin'); Navigator.pushNamed(context, '/dashboard');
} else if (_usernamecontroller.value.text == 'client@client.com' &&
_passwordcontroller.value.text == 'clientpage') {
Navigator.pushNamed(context, '/client');
} else { } else {
showDialog<String>( showDialog<String>(
context: context, context: context,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment