Advertisement
wildanfuady

Untitled

Nov 13th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:http/http.dart' as http;
  3. import 'package:flutter/services.dart';
  4. import 'package:sekolahku/project/EditSiswa.dart';
  5. import 'dart:convert';
  6. import 'dart:async';
  7.  
  8. import 'package:sekolahku/project/ListSiswa.dart';
  9.  
  10. class ViewSiswa extends StatefulWidget{
  11.  
  12. // menampung data
  13. final List list;
  14. final int index;
  15. ViewSiswa({this.index, this.list});
  16. // end menerima data
  17. _ViewSiswa createState() => _ViewSiswa();
  18.  
  19. }
  20.  
  21. class _ViewSiswa extends State<ViewSiswa>{
  22.  
  23. // fungsi untuk menghapus data siswa
  24. void deleteData(){
  25. var url = "http://10.0.2.2/flutter-sekolahku-server/siswa/deletesiswa.php";
  26. http.post(url, body:{
  27. 'id' : widget.list[widget.index]['id']
  28. });
  29. }
  30. // fungsi konfirmasi hapus
  31. void confirm(){
  32. AlertDialog alertDialog = new AlertDialog(
  33. content: Text("Apakah Anda yakin ingin menghapus siswa yang bernama '${widget.list[widget.index]['nama']}'?"),
  34. actions: <Widget>[
  35. RaisedButton(
  36. child: Text("Delete", style: TextStyle(color: Colors.white),),
  37. color: Colors.red,
  38. onPressed: (){
  39. deleteData();
  40. Navigator.of(context).pushReplacement(new MaterialPageRoute(builder: (_) {
  41. return new ListSiswa();
  42. }));
  43. },
  44. ),
  45. new RaisedButton(
  46. child: Text("Close", style:TextStyle(color: Colors.white),),
  47. color: Colors.green,
  48. onPressed: () => Navigator.pop(context),
  49. ),
  50. ],
  51. );
  52. showDialog(context: context, child: alertDialog);
  53. }
  54.  
  55. Widget build(BuildContext context){
  56.  
  57. // view
  58. return Scaffold(
  59.  
  60. appBar: AppBar(
  61. title: Text("Detail Siswa"),
  62. leading: IconButton(
  63. icon: Icon(Icons.arrow_back),
  64. onPressed: () => {
  65. Navigator.of(context).pushReplacement(
  66. new MaterialPageRoute(
  67. builder: (_) {
  68. return new ListSiswa();
  69. }
  70. ),
  71. ),
  72. },
  73. ),
  74. actions: <Widget>[
  75. IconButton(
  76. icon: Icon(Icons.delete),
  77. onPressed: () => confirm(),
  78. )
  79. ],
  80. ),
  81.  
  82. body: Container(
  83. child: ListView(
  84. children: <Widget>[
  85. ListTile(
  86. leading: Icon(Icons.person),
  87. title: Text("${widget.list[widget.index]["nama"]}"),
  88. subtitle: Text("Nama"),
  89. ),
  90. Divider(
  91. color: Colors.grey,
  92. ),
  93. ListTile(
  94. leading: Icon(Icons.school),
  95. title: Text("${widget.list[widget.index]["kelas"]} ${widget.list[widget.index]["jenjang"]}"),
  96. subtitle: Text("Kelas"),
  97. ),
  98. Divider(
  99. color: Colors.grey,
  100. ),
  101. ListTile(
  102. leading: Icon(Icons.sort),
  103. title: Text("${widget.list[widget.index]["usia"]} tahun"),
  104. subtitle: Text("Usia"),
  105. ),
  106. Divider(
  107. color: Colors.grey,
  108. ),
  109. ListTile(
  110. leading: Icon(Icons.phone),
  111. title: Text("${widget.list[widget.index]["telp"]}"),
  112. subtitle: Text("Telp"),
  113. ),
  114. Divider(
  115. color: Colors.grey,
  116. ),
  117. ListTile(
  118. leading: Icon(Icons.child_care),
  119. title: Text("${widget.list[widget.index]["hobi"].replaceAll(",", ", ")}"),
  120. subtitle: Text("Hobi"),
  121. ),
  122. Divider(
  123. color: Colors.grey,
  124. ),
  125. ListTile(
  126. leading: Icon(Icons.map),
  127. title: Text("${widget.list[widget.index]["alamat"]}"),
  128. subtitle: Text("Alamat"),
  129. ),
  130. Divider(
  131. color: Colors.grey,
  132. ),
  133. ],
  134. ),
  135. ),
  136. floatingActionButton: FloatingActionButton(
  137. child: Icon(Icons.edit),
  138. onPressed: () => {
  139. Navigator.of(context).push(
  140. new MaterialPageRoute(
  141. builder: (_) {
  142. return EditSiswa(list: widget.list, index: widget.index);
  143. }
  144. ),
  145. ),
  146. },
  147. ),
  148. );
  149.  
  150. }
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement