Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:http/http.dart' as http;
- import 'dart:async';
- import 'dart:convert';
- class Lihat extends StatefulWidget {
- @override
- _LihatState createState() => _LihatState();
- }
- class _LihatState extends State<Lihat> {
- TextEditingController controllerCari = new TextEditingController();
- Future<List> cariData() async {
- final response = await http.get('https://rsudenisa736.000webhostapp.com/json_get.php?norm='+controllerCari.text);
- return json.decode(response.body);
- //http.Response response = await http.get('http://situs.com/json_get.php?id='+controllerCari.text);
- //debugPrint(response.body);
- //var url =Uri.encodeFull('http://situs.com/json_get.php?id='+controllerCari.text);
- //http.get(url);
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: new AppBar(
- title: new Text("Lihat Data"),
- ),
- body: new Container(
- /*future: cariData(),
- builder: (context,snapshot){
- if(snapshot.hasError) print(snapshot.error);
- return snapshot.hasData ? new ItemList() : new Center(
- child: new CircularProgressIndicator(),
- );
- }, */
- child : new Column(
- children: <Widget>[
- new TextField(
- controller: controllerCari,
- decoration: new InputDecoration(
- hintText: "Cari Data"
- ),
- ),
- new RaisedButton(
- onPressed: (){
- cariData();
- },
- child: const Text("Cari DATA"),
- textColor: Colors.blue,
- ),
- new FutureBuilder<List>(
- future: cariData(),
- 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 ListView.builder(
- itemCount: list==null ? 0 : list.length,
- itemBuilder: (context, i){
- return new Text(list[i]['norm']);
- }
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement