Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'editdata.dart';
- import 'package:http/http.dart' as http;
- import 'main.dart';
- class Detail extends StatefulWidget {
- List list;
- int index;
- Detail({this.index, this.list});
- @override
- _DetailState createState() => _DetailState();
- }
- class _DetailState extends State<Detail> {
- void deleteData(){
- var url = "http://192.168.2.203/api_flutter/deletedata.php";
- http.post(url, body: {
- 'id' : widget.list[widget.index]['id'],
- });
- }
- void confirm(){
- AlertDialog alertDialog = new AlertDialog(
- content: new Text("Yakin hapus '${widget.list[widget.index]['item_name']}'"),
- actions: <Widget>[
- new RaisedButton(
- child: new Text("Hapus", style: new TextStyle(color: Colors.black),),
- color: Colors.red,
- onPressed: (){
- deleteData();
- Navigator.of(context).push(
- new MaterialPageRoute(
- builder: (BuildContext context)=>new MyApp(),
- );
- },
- ),
- new RaisedButton(
- child: new Text("Batal", style: new TextStyle(color: Colors.black)),
- color: Colors.green,
- onPressed: ()=>Navigator.pop(context),
- )
- ],
- );
- showDialog(context: context, child: alertDialog);
- }
- @override
- Widget build(BuildContext context) {
- return new Scaffold(
- appBar: new AppBar(title: new Text("${widget.list[widget.index]['item_name']}"),),
- body: new Container(
- height: 250.0,
- padding: const EdgeInsets.all(20.0),
- child: new Card(
- child: new Center(
- child: new Column(
- children: <Widget>[
- new Padding(padding: const EdgeInsets.only(top: 30.0),),
- new Text(widget.list[widget.index]['item_name'], style: new TextStyle(fontSize: 20.0),),
- new Text("Code : ${widget.list[widget.index]['item_code']}", style: new TextStyle(fontSize: 18.0),),
- new Text("Harga : ${widget.list[widget.index]['harga']}", style: new TextStyle(fontSize: 18.0),),
- new Text("Stok : ${widget.list[widget.index]['stock']}", style: new TextStyle(fontSize: 18.0),),
- new Padding(padding: const EdgeInsets.only(top: 30.0),),
- new Row(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- new RaisedButton(
- child: new Text("Edit"),
- color: Colors.green,
- onPressed: ()=>Navigator.of(context).push(
- new MaterialPageRoute(
- builder:(BuildContext context)=>new Editdata(list: widget.list, index: widget.index,),
- )
- ),
- ),
- new RaisedButton(
- child: new Text("Hapus"),
- color: Colors.red,
- onPressed: ()=>confirm(),
- )
- ],)
- ],
- ),
- ),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement