Advertisement
wildanfuady

Untitled

Oct 15th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'package:http/http.dart' as http;
  4. import 'package:flutter/material.dart';
  5.  
  6. class ListSiswa extends StatefulWidget{
  7. @override
  8. _ListSiswa createState() => _ListSiswa();
  9. }
  10.  
  11. class _ListSiswa extends State<ListSiswa>{
  12.  
  13. // mengambil data dari database
  14. Future<List> getData() async {
  15. final response = await http.get("http://192.168.1.10/sekolahku/siswa/getsiswa.php");
  16. return json.decode(response.body);
  17. }
  18.  
  19. @override
  20. Widget build(BuildContext context){
  21. return new Scaffold(
  22. appBar: new AppBar(
  23. title: Text("List Siswa"),
  24. leading: Icon(Icons.person),
  25. ),
  26. body: new FutureBuilder<List>(
  27. future: getData(),
  28. builder: (context, snapshot){
  29. if(snapshot.hasError) print(snapshot.error);
  30. return snapshot.hasData
  31. ? new ItemList(
  32. list: snapshot.data,
  33. )
  34. : new Center(
  35. child: new CircularProgressIndicator(),
  36. );
  37. },
  38. ),
  39. );
  40. }
  41. }
  42.  
  43. class ItemList extends StatelessWidget{
  44. final List list;
  45. ItemList({this.list});
  46. @override
  47. Widget build(BuildContext context){
  48. return new ListView.builder(
  49. itemCount: list == null ? 0 : list.length,
  50. itemBuilder: (context, i){
  51. return new Container (
  52. padding: const EdgeInsets.all(5.0),
  53. child: Card(
  54. child: new ListTile(
  55. title: Text(list[i]['nama']),
  56. leading: Icon(Icons.person),
  57. subtitle: Text("Usia : ${list[i]['usia']} tahun"),
  58. )
  59. ),
  60. );
  61. },
  62. );
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement