Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'dart:async';
  3. import 'dart:convert';
  4. import 'package:http/http.dart' as http;
  5. import 'detaill_resep.dart';
  6.  
  7. class DataResepHome extends StatefulWidget
  8. {
  9. @override
  10. // _DataResepHomeState createState()= new _DataResepHomeState();
  11. _DataResepHomeState createState() => new _DataResepHomeState();
  12.  
  13. }
  14.  
  15. class _DataResepHomeState extends State<DataResepHome>
  16. {
  17. Future<List> getData() async
  18. {
  19. final responseData = await http.get("http://10.80.33.185/resep/get_resep.php");
  20. return jsonDecode(responseData.body);
  21. }
  22.  
  23. Widget build(BuildContext context)
  24. {
  25. return new Scaffold(
  26. appBar: AppBar(
  27. title: new Text("Resep Sehat Dr.Zaidul Akbar"),
  28. backgroundColor: Colors.green,
  29. ),
  30. body: new FutureBuilder<List>(
  31. future: getData(),
  32. builder: (context,snapshot){
  33. if(snapshot.hasError)print(snapshot.error);
  34. return snapshot.hasData ? new ItemList(list:snapshot.data):
  35. new Center(
  36. child: CircularProgressIndicator(),
  37. );
  38. },
  39. ),
  40. );
  41. }
  42. }
  43.  
  44. class ItemList extends StatelessWidget
  45. {
  46. final List list;
  47. ItemList({this.list});
  48.  
  49. @override
  50. Widget build(BuildContext context) {
  51. // TODO: implement build
  52. return new ListView.builder(
  53. itemCount: list == null ? 0:list.length,
  54. itemBuilder: (context,i)
  55. {
  56. return new Container(
  57. padding: const EdgeInsets.all(10.0),
  58. child: new GestureDetector(
  59. onTap: (){
  60. Navigator.of(context).push(new MaterialPageRoute(builder: (context)=> DetailPageResep(list:list,index: i,)));
  61.  
  62. },
  63. child: new Card(
  64. child: new ListTile(
  65. title: new Text(list[i]['judul_resep'],style: new TextStyle(color: Colors.green , fontWeight: FontWeight.bold),
  66. ),
  67. subtitle: new Text("Tanggal : ${list[i]['tgl_resep']}"),
  68. trailing:new Image.network("http://10.80.33.185/resep/img/" + list[i]['img_resep'],
  69. fit: BoxFit.cover,
  70. height: 60.0,
  71. width: 60.0,
  72. ),
  73. ),
  74. )
  75. ),
  76. );
  77. },
  78. );
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement