Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:async';
- import 'dart:convert';
- import 'package:http/http.dart' as http;
- import 'package:flutter/material.dart';
- class ListSiswa extends StatefulWidget{
- @override
- _ListSiswa createState() => _ListSiswa();
- }
- class _ListSiswa extends State<ListSiswa>{
- // mengambil data dari database
- Future<List> getData() async {
- final response = await http.get("http://192.168.1.10/sekolahku/siswa/getsiswa.php");
- return json.decode(response.body);
- }
- @override
- Widget build(BuildContext context){
- return new Scaffold(
- appBar: new AppBar(
- title: Text("List Siswa"),
- leading: Icon(Icons.person),
- ),
- body: new FutureBuilder<List>(
- future: getData(),
- builder: (context, snapshot){
- if(snapshot.hasError) print(snapshot.error);
- return snapshot.hasData
- ? new ItemList(
- list: snapshot.data,
- )
- : new Center(
- child: new CircularProgressIndicator(),
- );
- },
- ),
- );
- }
- }
- class ItemList extends StatelessWidget{
- final List list;
- ItemList({this.list});
- @override
- Widget build(BuildContext context){
- return new ListView.builder(
- itemCount: list == null ? 0 : list.length,
- itemBuilder: (context, i){
- return new Container (
- padding: const EdgeInsets.all(5.0),
- child: Card(
- child: new ListTile(
- title: Text(list[i]['nama']),
- leading: Icon(Icons.person),
- subtitle: Text("Usia : ${list[i]['usia']} tahun"),
- )
- ),
- );
- },
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement