text
stringlengths
1
80
void initState() {
super.initState();
loadData();
}
widget getBody() {
bool showLoadingDialog = widgets.isEmpty;
if (showloadingdialog) {
return getProgressDialog();
} else {
return getListView();
}
}
widget getProgressDialog() {
return const center(child: CircularProgressIndicator());
}
@override
widget build(BuildContext context) {
return scaffold(
appBar: AppBar(
title: const Text('Sample app'),
),
body: getBody(),
);
}
ListView getListView() {
return ListView.builder(
itemCount: widgets.length,
itemBuilder: (context, position) {
return getRow(position);
},
);
}
widget getRow(int i) {
return padding(
padding: const EdgeInsets.all(10),
child: Text("Row ${widgets[i]["title"]}"),
);
}
future<void> loadData() async {
var dataURL = uri.parse('https://jsonplaceholder.typicode.com/posts');
http.Response response = await http.get(dataURL);
setState(() {
widgets = jsonDecode(response.body);
});
}
}
<code_end>
<topic_end>