Advertisement
wildanfuady

Untitled

Oct 14th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:http/http.dart' as http;
  3. import 'package:sekolahku/project/listSiswa.dart';
  4.  
  5. class EditSiswa extends StatefulWidget {
  6. final List list;
  7. final int index;
  8. EditSiswa({this.list, this.index});
  9. @override
  10. _EditSiswaState createState() => _EditSiswaState();
  11. }
  12.  
  13. class _EditSiswaState extends State<EditSiswa> {
  14.  
  15. TextEditingController controllerNama;
  16. TextEditingController controllerUsia;
  17. TextEditingController controllerKelas;
  18. TextEditingController controllerTelp;
  19. TextEditingController controllerAlamat;
  20.  
  21. final List<String> _items = ['TK', 'SD', 'SMP'].toList();
  22.  
  23. String _selection;
  24.  
  25. void editData() {
  26. var url="https://flutterapp.ilmucoding.com/siswa/editdata.php";
  27. http.post(url, body: {
  28. "id" : widget.list[widget.index]['id'],
  29. "nama" : controllerNama.text,
  30. "usia" : controllerUsia.text,
  31. "kelas" : controllerKelas.text,
  32. "telp" : controllerTelp.text,
  33. "alamat" : controllerAlamat.text,
  34. });
  35. }
  36. @override
  37. void initState() {
  38. controllerNama = new TextEditingController(text: widget.list[widget.index]['nama']);
  39. controllerUsia = new TextEditingController(text: widget.list[widget.index]['usia']);
  40. controllerKelas = new TextEditingController(text: widget.list[widget.index]['kelas']);
  41. controllerTelp = new TextEditingController(text: widget.list[widget.index]['telp']);
  42. controllerAlamat = new TextEditingController(text: widget.list[widget.index]['alamat']);
  43. super.initState();
  44. }
  45. @override
  46. Widget build(BuildContext context) {
  47. final dropdownMenuOptions = _items
  48. .map((String item) =>
  49. new DropdownMenuItem<String>(value: item, child: new Text(item))
  50. )
  51. .toList();
  52. return Scaffold(
  53. appBar: AppBar(
  54. title: new Text("Edit Siswa ${widget.list[widget.index]['nama']}"),
  55. actions: <Widget>[
  56. IconButton(
  57. icon: Icon(
  58. Icons.update,
  59. color: Colors.white,
  60. ),
  61. tooltip: "Save",
  62. onPressed: () {
  63. editData();
  64. Navigator.pop(context);
  65. },
  66. ),
  67. ],
  68. ),
  69. body: Padding(
  70. padding: const EdgeInsets.all(10.0),
  71. child: ListView(
  72. children: <Widget>[
  73. new Column(
  74. children: <Widget>[
  75. new TextField(
  76. controller: controllerNama,
  77. decoration: new InputDecoration(
  78. hintText: "Nama", labelText: "Nama"),
  79. ),
  80. new TextField(
  81. controller: controllerUsia,
  82. decoration: new InputDecoration(
  83. hintText: "Usia", labelText: "Usia"),
  84. ),
  85. new TextField(
  86. controller: controllerKelas,
  87. decoration: new InputDecoration(
  88. hintText: "Kelas", labelText: "Kelas"),
  89. ),
  90. new TextField(
  91. controller: controllerTelp,
  92. decoration: new InputDecoration(
  93. hintText: "Telp", labelText: "Telp"),
  94. ),
  95. new TextField(
  96. controller: controllerAlamat,
  97. decoration: new InputDecoration(
  98. hintText: "Alamat", labelText: "Alamat"),
  99. ),
  100. new Padding(
  101. padding: const EdgeInsets.all(10.0),
  102. ),
  103. Align(
  104. alignment: Alignment(0.98, 0.95),
  105. child: new RaisedButton(
  106. color: Colors.lightBlue,
  107. onPressed: () {
  108. editData();
  109. Navigator.of(context).push(
  110. new MaterialPageRoute(
  111. builder: (BuildContext context)=> new ListSiswa(),
  112. ),
  113. );
  114. },
  115.  
  116. child: new Text(
  117. "Edit Data Siswa",
  118. style: TextStyle(color: Colors.white),
  119. ),
  120. ),
  121. ),
  122. ],
  123. ),
  124. ],
  125. ),
  126. ),
  127. );
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement