ListView.builder doesn't show anything - Flutter












1














When I'm, not using the ListView.builder constructor in Flutter, the individual item is shown as expected from the JSON API:



when I use ListView.builder, nothing shows up. no Error!



I also tried a listview with Texts only that doesn't seem to work either.
Here's the code:



@override
Widget build(BuildContext context) {

return Container(

child: new Scaffold(
appBar: AppBar(
title: Text("the title"),//TODO edit this
backgroundColor: Colors.blueAccent),

body:
Column(
children: <Widget>[
FutureBuilder<List<dynamic>>(
future: getPosts2(),
builder: (context, snapshot) {
if (snapshot.hasError) print(snapshot.error);

return snapshot.hasData
? ListViewPosts(postsFrom: snapshot.data)
: Center(child: CircularProgressIndicator());
},
),


],
),

),
);
}
}


And here is the ListViewPosts Stateless Widget:



     class ListViewPosts extends 
StatelessWidget {
final List<dynamic> postsFrom;

ListViewPosts({Key key,
this.postsFrom}) : super(key: key);

@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
FadeInImage.assetNetwork(
placeholder: 'assets/images/placeholder.png',
image: postsFrom[1]["featured_media"] == 0
? 'assets/images/placeholder.png'
: postsFrom[1]["_embedded"]["wp:featuredmedia"]
[0]["source_url"],


),

FadeInImage.assetNetwork(
placeholder: 'assets/images/placeholder.png',
image: postsFrom[2]["featured_media"] == 0
? 'assets/images/placeholder.png'
: postsFrom[2]["_embedded"]["wp:featuredmedia"]
[0]["source_url"],


),
new Row(
children: <Widget>[
Expanded(
child: Text(
"نووسه‌ر: " +
postsFrom[1]["_embedded"]["author"][0]
["name"],
textAlign: TextAlign.right,
),
),
Expanded(
child: Text(
dateConvertor(
postsFrom[2]["date"].toString()),
textAlign: TextAlign.left,
),
),
],
),

ListView.builder(
itemCount: postsFrom.length, //== null ? 0 : postsFrom.length,
itemBuilder: (context, int index) {
Card(
child: Column(
children: <Widget>[
Text(postsFrom.toString()),
Container(
child: hawalImage(postsFrom, index),
),
new Padding(
padding: EdgeInsets.all(5.0),
child: new ListTile(

title: new Text("whatEver"),
subtitle: new Row(
children: <Widget>[
Expanded(
child: new Text(postsFrom[index]["title"]["rendered"]),
),
Expanded(
child: hawalDate(postsFrom, index),
),
],
),
),
),
new ButtonTheme.bar(
child: hawalBtnBar(),
),
],
),
);
},
),









share|improve this question


















  • 1




    you dont return anything from your itemBuilder
    – pskink
    Nov 23 at 6:13










  • I'm returning snapshot data to my postsFrom variable .
    – Hooshyar
    Nov 23 at 11:43










  • no, you are not, but it seems you already know what to do...
    – pskink
    Nov 24 at 6:11
















1














When I'm, not using the ListView.builder constructor in Flutter, the individual item is shown as expected from the JSON API:



when I use ListView.builder, nothing shows up. no Error!



I also tried a listview with Texts only that doesn't seem to work either.
Here's the code:



@override
Widget build(BuildContext context) {

return Container(

child: new Scaffold(
appBar: AppBar(
title: Text("the title"),//TODO edit this
backgroundColor: Colors.blueAccent),

body:
Column(
children: <Widget>[
FutureBuilder<List<dynamic>>(
future: getPosts2(),
builder: (context, snapshot) {
if (snapshot.hasError) print(snapshot.error);

return snapshot.hasData
? ListViewPosts(postsFrom: snapshot.data)
: Center(child: CircularProgressIndicator());
},
),


],
),

),
);
}
}


And here is the ListViewPosts Stateless Widget:



     class ListViewPosts extends 
StatelessWidget {
final List<dynamic> postsFrom;

ListViewPosts({Key key,
this.postsFrom}) : super(key: key);

@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
FadeInImage.assetNetwork(
placeholder: 'assets/images/placeholder.png',
image: postsFrom[1]["featured_media"] == 0
? 'assets/images/placeholder.png'
: postsFrom[1]["_embedded"]["wp:featuredmedia"]
[0]["source_url"],


),

FadeInImage.assetNetwork(
placeholder: 'assets/images/placeholder.png',
image: postsFrom[2]["featured_media"] == 0
? 'assets/images/placeholder.png'
: postsFrom[2]["_embedded"]["wp:featuredmedia"]
[0]["source_url"],


),
new Row(
children: <Widget>[
Expanded(
child: Text(
"نووسه‌ر: " +
postsFrom[1]["_embedded"]["author"][0]
["name"],
textAlign: TextAlign.right,
),
),
Expanded(
child: Text(
dateConvertor(
postsFrom[2]["date"].toString()),
textAlign: TextAlign.left,
),
),
],
),

ListView.builder(
itemCount: postsFrom.length, //== null ? 0 : postsFrom.length,
itemBuilder: (context, int index) {
Card(
child: Column(
children: <Widget>[
Text(postsFrom.toString()),
Container(
child: hawalImage(postsFrom, index),
),
new Padding(
padding: EdgeInsets.all(5.0),
child: new ListTile(

title: new Text("whatEver"),
subtitle: new Row(
children: <Widget>[
Expanded(
child: new Text(postsFrom[index]["title"]["rendered"]),
),
Expanded(
child: hawalDate(postsFrom, index),
),
],
),
),
),
new ButtonTheme.bar(
child: hawalBtnBar(),
),
],
),
);
},
),









share|improve this question


















  • 1




    you dont return anything from your itemBuilder
    – pskink
    Nov 23 at 6:13










  • I'm returning snapshot data to my postsFrom variable .
    – Hooshyar
    Nov 23 at 11:43










  • no, you are not, but it seems you already know what to do...
    – pskink
    Nov 24 at 6:11














1












1








1







When I'm, not using the ListView.builder constructor in Flutter, the individual item is shown as expected from the JSON API:



when I use ListView.builder, nothing shows up. no Error!



I also tried a listview with Texts only that doesn't seem to work either.
Here's the code:



@override
Widget build(BuildContext context) {

return Container(

child: new Scaffold(
appBar: AppBar(
title: Text("the title"),//TODO edit this
backgroundColor: Colors.blueAccent),

body:
Column(
children: <Widget>[
FutureBuilder<List<dynamic>>(
future: getPosts2(),
builder: (context, snapshot) {
if (snapshot.hasError) print(snapshot.error);

return snapshot.hasData
? ListViewPosts(postsFrom: snapshot.data)
: Center(child: CircularProgressIndicator());
},
),


],
),

),
);
}
}


And here is the ListViewPosts Stateless Widget:



     class ListViewPosts extends 
StatelessWidget {
final List<dynamic> postsFrom;

ListViewPosts({Key key,
this.postsFrom}) : super(key: key);

@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
FadeInImage.assetNetwork(
placeholder: 'assets/images/placeholder.png',
image: postsFrom[1]["featured_media"] == 0
? 'assets/images/placeholder.png'
: postsFrom[1]["_embedded"]["wp:featuredmedia"]
[0]["source_url"],


),

FadeInImage.assetNetwork(
placeholder: 'assets/images/placeholder.png',
image: postsFrom[2]["featured_media"] == 0
? 'assets/images/placeholder.png'
: postsFrom[2]["_embedded"]["wp:featuredmedia"]
[0]["source_url"],


),
new Row(
children: <Widget>[
Expanded(
child: Text(
"نووسه‌ر: " +
postsFrom[1]["_embedded"]["author"][0]
["name"],
textAlign: TextAlign.right,
),
),
Expanded(
child: Text(
dateConvertor(
postsFrom[2]["date"].toString()),
textAlign: TextAlign.left,
),
),
],
),

ListView.builder(
itemCount: postsFrom.length, //== null ? 0 : postsFrom.length,
itemBuilder: (context, int index) {
Card(
child: Column(
children: <Widget>[
Text(postsFrom.toString()),
Container(
child: hawalImage(postsFrom, index),
),
new Padding(
padding: EdgeInsets.all(5.0),
child: new ListTile(

title: new Text("whatEver"),
subtitle: new Row(
children: <Widget>[
Expanded(
child: new Text(postsFrom[index]["title"]["rendered"]),
),
Expanded(
child: hawalDate(postsFrom, index),
),
],
),
),
),
new ButtonTheme.bar(
child: hawalBtnBar(),
),
],
),
);
},
),









share|improve this question













When I'm, not using the ListView.builder constructor in Flutter, the individual item is shown as expected from the JSON API:



when I use ListView.builder, nothing shows up. no Error!



I also tried a listview with Texts only that doesn't seem to work either.
Here's the code:



@override
Widget build(BuildContext context) {

return Container(

child: new Scaffold(
appBar: AppBar(
title: Text("the title"),//TODO edit this
backgroundColor: Colors.blueAccent),

body:
Column(
children: <Widget>[
FutureBuilder<List<dynamic>>(
future: getPosts2(),
builder: (context, snapshot) {
if (snapshot.hasError) print(snapshot.error);

return snapshot.hasData
? ListViewPosts(postsFrom: snapshot.data)
: Center(child: CircularProgressIndicator());
},
),


],
),

),
);
}
}


And here is the ListViewPosts Stateless Widget:



     class ListViewPosts extends 
StatelessWidget {
final List<dynamic> postsFrom;

ListViewPosts({Key key,
this.postsFrom}) : super(key: key);

@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
FadeInImage.assetNetwork(
placeholder: 'assets/images/placeholder.png',
image: postsFrom[1]["featured_media"] == 0
? 'assets/images/placeholder.png'
: postsFrom[1]["_embedded"]["wp:featuredmedia"]
[0]["source_url"],


),

FadeInImage.assetNetwork(
placeholder: 'assets/images/placeholder.png',
image: postsFrom[2]["featured_media"] == 0
? 'assets/images/placeholder.png'
: postsFrom[2]["_embedded"]["wp:featuredmedia"]
[0]["source_url"],


),
new Row(
children: <Widget>[
Expanded(
child: Text(
"نووسه‌ر: " +
postsFrom[1]["_embedded"]["author"][0]
["name"],
textAlign: TextAlign.right,
),
),
Expanded(
child: Text(
dateConvertor(
postsFrom[2]["date"].toString()),
textAlign: TextAlign.left,
),
),
],
),

ListView.builder(
itemCount: postsFrom.length, //== null ? 0 : postsFrom.length,
itemBuilder: (context, int index) {
Card(
child: Column(
children: <Widget>[
Text(postsFrom.toString()),
Container(
child: hawalImage(postsFrom, index),
),
new Padding(
padding: EdgeInsets.all(5.0),
child: new ListTile(

title: new Text("whatEver"),
subtitle: new Row(
children: <Widget>[
Expanded(
child: new Text(postsFrom[index]["title"]["rendered"]),
),
Expanded(
child: hawalDate(postsFrom, index),
),
],
),
),
),
new ButtonTheme.bar(
child: hawalBtnBar(),
),
],
),
);
},
),






dart flutter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 21:57









Hooshyar

113




113








  • 1




    you dont return anything from your itemBuilder
    – pskink
    Nov 23 at 6:13










  • I'm returning snapshot data to my postsFrom variable .
    – Hooshyar
    Nov 23 at 11:43










  • no, you are not, but it seems you already know what to do...
    – pskink
    Nov 24 at 6:11














  • 1




    you dont return anything from your itemBuilder
    – pskink
    Nov 23 at 6:13










  • I'm returning snapshot data to my postsFrom variable .
    – Hooshyar
    Nov 23 at 11:43










  • no, you are not, but it seems you already know what to do...
    – pskink
    Nov 24 at 6:11








1




1




you dont return anything from your itemBuilder
– pskink
Nov 23 at 6:13




you dont return anything from your itemBuilder
– pskink
Nov 23 at 6:13












I'm returning snapshot data to my postsFrom variable .
– Hooshyar
Nov 23 at 11:43




I'm returning snapshot data to my postsFrom variable .
– Hooshyar
Nov 23 at 11:43












no, you are not, but it seems you already know what to do...
– pskink
Nov 24 at 6:11




no, you are not, but it seems you already know what to do...
– pskink
Nov 24 at 6:11












2 Answers
2






active

oldest

votes


















0














You have to write return Card at the beginning of the curly brackets in the builder function. Also I would be cautious with using Expanded there, it might cause some errors.



Also you put a ListView inside a Column without defining it's height, so it will take up space indefinitely. Wrap it in a widget that provides height constraints(SizedBox, Expanded, ...)






share|improve this answer





















  • thanks, buddy, me being a noob and not returning the card :-*
    – Hooshyar
    Nov 23 at 14:30



















0














You have to write return Card at the beginning of the curly brackets in the builder function. Also I would be cautious with using Expanded there, it might cause some errors.






share|improve this answer





















  • I have tried with return Card , also without Expanded. I have tried one with only text elements but still, nothing shows up.
    – Hooshyar
    Nov 23 at 11:44











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438398%2flistview-builder-doesnt-show-anything-flutter%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You have to write return Card at the beginning of the curly brackets in the builder function. Also I would be cautious with using Expanded there, it might cause some errors.



Also you put a ListView inside a Column without defining it's height, so it will take up space indefinitely. Wrap it in a widget that provides height constraints(SizedBox, Expanded, ...)






share|improve this answer





















  • thanks, buddy, me being a noob and not returning the card :-*
    – Hooshyar
    Nov 23 at 14:30
















0














You have to write return Card at the beginning of the curly brackets in the builder function. Also I would be cautious with using Expanded there, it might cause some errors.



Also you put a ListView inside a Column without defining it's height, so it will take up space indefinitely. Wrap it in a widget that provides height constraints(SizedBox, Expanded, ...)






share|improve this answer





















  • thanks, buddy, me being a noob and not returning the card :-*
    – Hooshyar
    Nov 23 at 14:30














0












0








0






You have to write return Card at the beginning of the curly brackets in the builder function. Also I would be cautious with using Expanded there, it might cause some errors.



Also you put a ListView inside a Column without defining it's height, so it will take up space indefinitely. Wrap it in a widget that provides height constraints(SizedBox, Expanded, ...)






share|improve this answer












You have to write return Card at the beginning of the curly brackets in the builder function. Also I would be cautious with using Expanded there, it might cause some errors.



Also you put a ListView inside a Column without defining it's height, so it will take up space indefinitely. Wrap it in a widget that provides height constraints(SizedBox, Expanded, ...)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 at 13:34









01leo

348111




348111












  • thanks, buddy, me being a noob and not returning the card :-*
    – Hooshyar
    Nov 23 at 14:30


















  • thanks, buddy, me being a noob and not returning the card :-*
    – Hooshyar
    Nov 23 at 14:30
















thanks, buddy, me being a noob and not returning the card :-*
– Hooshyar
Nov 23 at 14:30




thanks, buddy, me being a noob and not returning the card :-*
– Hooshyar
Nov 23 at 14:30













0














You have to write return Card at the beginning of the curly brackets in the builder function. Also I would be cautious with using Expanded there, it might cause some errors.






share|improve this answer





















  • I have tried with return Card , also without Expanded. I have tried one with only text elements but still, nothing shows up.
    – Hooshyar
    Nov 23 at 11:44
















0














You have to write return Card at the beginning of the curly brackets in the builder function. Also I would be cautious with using Expanded there, it might cause some errors.






share|improve this answer





















  • I have tried with return Card , also without Expanded. I have tried one with only text elements but still, nothing shows up.
    – Hooshyar
    Nov 23 at 11:44














0












0








0






You have to write return Card at the beginning of the curly brackets in the builder function. Also I would be cautious with using Expanded there, it might cause some errors.






share|improve this answer












You have to write return Card at the beginning of the curly brackets in the builder function. Also I would be cautious with using Expanded there, it might cause some errors.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 at 7:49









01leo

348111




348111












  • I have tried with return Card , also without Expanded. I have tried one with only text elements but still, nothing shows up.
    – Hooshyar
    Nov 23 at 11:44


















  • I have tried with return Card , also without Expanded. I have tried one with only text elements but still, nothing shows up.
    – Hooshyar
    Nov 23 at 11:44
















I have tried with return Card , also without Expanded. I have tried one with only text elements but still, nothing shows up.
– Hooshyar
Nov 23 at 11:44




I have tried with return Card , also without Expanded. I have tried one with only text elements but still, nothing shows up.
– Hooshyar
Nov 23 at 11:44


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438398%2flistview-builder-doesnt-show-anything-flutter%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Lallio

Futebolista

Jornalista