Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. import 'dart:async';
  2. import 'dart:convert';
  3.  
  4. import 'package:flutter/material.dart';
  5. import 'package:http/http.dart' as http;
  6. import './Detail.dart';
  7. import './adddata.dart';
  8.  
  9. void main() {
  10. runApp(new MaterialApp(
  11. title: "My Store",
  12. home: new Home(),
  13. ));
  14. }
  15.  
  16. class Home extends StatefulWidget {
  17. @override
  18. _HomeState createState() => new _HomeState();
  19. }
  20.  
  21. class _HomeState extends State<Home> {
  22. Future<List> getData() async {
  23. // final response = await http.get("http://192.168.137.1/php_flutter/getdata.php");
  24. final response = await http.get("http://latihan.onweek.org/getdata.php");
  25. return json.decode(response.body);
  26. }
  27.  
  28. @override
  29. Widget build(BuildContext context) {
  30. return new Scaffold(
  31. appBar: new AppBar(
  32. title: new Text("MY STORE"),
  33. ),
  34. floatingActionButton: new FloatingActionButton(
  35. child: new Icon(Icons.add),
  36. onPressed: ()=>Navigator.of(context).push(
  37. new MaterialPageRoute(
  38. builder: (BuildContext context)=> new AddData(),
  39. )
  40. ),
  41. ),
  42. body: new FutureBuilder<List>(
  43. future: getData(),
  44. builder: (context, snapshot) {
  45. if (snapshot.hasError) print(snapshot.error);
  46.  
  47. return snapshot.hasData
  48. ? new ItemList(
  49. list: snapshot.data,
  50. )
  51. : new Center(
  52. child: new CircularProgressIndicator(),
  53. );
  54. },
  55. ),
  56. );
  57. }
  58. }
  59.  
  60. class ItemList extends StatelessWidget {
  61. final List list;
  62. ItemList({this.list});
  63.  
  64. @override
  65. Widget build(BuildContext context) {
  66. return new ListView.builder(
  67. itemCount: list == null ? 0 : list.length,
  68. itemBuilder: (context, i) {
  69. return new Container(
  70. padding: const EdgeInsets.all(10.0),
  71. child: new GestureDetector(
  72. onTap: ()=>Navigator.of(context).push(
  73. new MaterialPageRoute(
  74. builder: (BuildContext context)=> new Detail(list:list , index: i,)
  75. )
  76. ),
  77. child: new Card(
  78.  
  79. child: new ListTile(
  80. title: new Text(list[i]['item_name']),
  81. leading: new Icon(Icons.widgets),
  82. subtitle: new Text("Stock : ${list[i]['stock']}"),
  83. ),
  84. ),
  85. ),
  86. );
  87. },
  88. );
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement