Advertisement
rama_astadipati

detail

May 7th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'editdata.dart';
  3. import 'package:http/http.dart' as http;
  4. import 'main.dart';
  5.  
  6. class Detail extends StatefulWidget {
  7. List list;
  8. int index;
  9. Detail({this.index, this.list});
  10. @override
  11. _DetailState createState() => _DetailState();
  12. }
  13.  
  14.  
  15. class _DetailState extends State<Detail> {
  16.  
  17. void deleteData(){
  18. var url = "http://192.168.2.203/api_flutter/deletedata.php";
  19.  
  20. http.post(url, body: {
  21. 'id' : widget.list[widget.index]['id'],
  22. });
  23. }
  24. void confirm(){
  25. AlertDialog alertDialog = new AlertDialog(
  26. content: new Text("Yakin hapus '${widget.list[widget.index]['item_name']}'"),
  27. actions: <Widget>[
  28. new RaisedButton(
  29. child: new Text("Hapus", style: new TextStyle(color: Colors.black),),
  30. color: Colors.red,
  31. onPressed: (){
  32. deleteData();
  33. Navigator.of(context).push(
  34. new MaterialPageRoute(
  35. builder: (BuildContext context)=>new MyApp(),
  36. );
  37. },
  38. ),
  39. new RaisedButton(
  40. child: new Text("Batal", style: new TextStyle(color: Colors.black)),
  41. color: Colors.green,
  42. onPressed: ()=>Navigator.pop(context),
  43. )
  44. ],
  45. );
  46. showDialog(context: context, child: alertDialog);
  47. }
  48.  
  49. @override
  50. Widget build(BuildContext context) {
  51. return new Scaffold(
  52. appBar: new AppBar(title: new Text("${widget.list[widget.index]['item_name']}"),),
  53. body: new Container(
  54. height: 250.0,
  55. padding: const EdgeInsets.all(20.0),
  56. child: new Card(
  57. child: new Center(
  58. child: new Column(
  59. children: <Widget>[
  60. new Padding(padding: const EdgeInsets.only(top: 30.0),),
  61. new Text(widget.list[widget.index]['item_name'], style: new TextStyle(fontSize: 20.0),),
  62. new Text("Code : ${widget.list[widget.index]['item_code']}", style: new TextStyle(fontSize: 18.0),),
  63. new Text("Harga : ${widget.list[widget.index]['harga']}", style: new TextStyle(fontSize: 18.0),),
  64. new Text("Stok : ${widget.list[widget.index]['stock']}", style: new TextStyle(fontSize: 18.0),),
  65. new Padding(padding: const EdgeInsets.only(top: 30.0),),
  66.  
  67. new Row(
  68. mainAxisSize: MainAxisSize.min,
  69. children: <Widget>[
  70. new RaisedButton(
  71. child: new Text("Edit"),
  72. color: Colors.green,
  73. onPressed: ()=>Navigator.of(context).push(
  74. new MaterialPageRoute(
  75. builder:(BuildContext context)=>new Editdata(list: widget.list, index: widget.index,),
  76. )
  77. ),
  78. ),
  79. new RaisedButton(
  80. child: new Text("Hapus"),
  81. color: Colors.red,
  82. onPressed: ()=>confirm(),
  83. )
  84. ],)
  85. ],
  86. ),
  87. ),
  88. ),
  89. ),
  90. );
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement