Created
July 12, 2018 16:19
-
-
Save rahichesoft/ce8df52d2b044c6c0b14990d32b80e08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:convert'; | |
import 'package:flutter/material.dart'; | |
import 'package:http/http.dart' as http; | |
void main() { | |
runApp(new MaterialApp( | |
home: new HomePage(), | |
)); | |
} | |
class HomePage extends StatefulWidget { | |
@override | |
HomePageState createState() => new HomePageState(); | |
} | |
class HomePageState extends State<HomePage> { | |
Map<String,dynamic> data; | |
Future<String> getData() async { | |
var response = await http.get( | |
Uri.encodeFull("http://myip:8080/names"), | |
headers: { | |
"Accept": "application/json" | |
} | |
); | |
this.setState(() { | |
data = JSON.decode(response.body); | |
}); | |
print(data["data"][1]["name"]; // where i inserted my own value "name" | |
return "Success!"; | |
} | |
@override | |
void initState() { | |
super.initState(); | |
this.getData(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return new Scaffold( | |
appBar: new AppBar( | |
title: new Text("Listviews"), | |
), | |
body: new ListView.builder( | |
itemCount: data == null ? 0 : data["data"].length, | |
itemBuilder: (BuildContext context, int index) { | |
return new Card( | |
child: new Text(data["data"][index]["name"]), // inserted my own value "name" | |
); | |
}, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment