How to display my List into Listview?Flutter listview with Map instead of ListFlutter - Error updating a list in ListViewFlutter ListView displays wrong itemsFlutter : Can I add a Header Row to a ListViewhow to display images and text on it in listview flutter?Flutter : Bad state: Stream has already been listened toWhy does updating a List<StatefulWidget> that is used in a ListView fail to update the display?Displaying Firebase Firestore Listview Data as a list FlutterHow I can put Widget above Widget using List<Widget> widget in Flutter?Flutter/Dart Basic Understanding

How can "mimic phobia" be cured or prevented?

Has any country ever had 2 former presidents in jail simultaneously?

What is the evidence for the "tyranny of the majority problem" in a direct democracy context?

What are the purposes of autoencoders?

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

A social experiment. What is the worst that can happen?

Why did the EU agree to delay the Brexit deadline?

Is it possible to put a rectangle as background in the author section?

Is the U.S. Code copyrighted by the Government?

Did arcade monitors have same pixel aspect ratio as TV sets?

Is it better practice to read straight from sheet music rather than memorize it?

WiFi Thermostat, No C Terminal on Furnace

Is it possible to have a strip of cold climate in the middle of a planet?

Removing files under particular conditions (number of files, file age)

Fear of getting stuck on one programming language / technology that is not used in my country

Melting point of aspirin, contradicting sources

The IT department bottlenecks progress. How should I handle this?

Travelling outside the UK without a passport

Should I outline or discovery write my stories?

Is this toilet slogan correct usage of the English language?

Does a 'pending' US visa application constitute a denial?

Pre-mixing cryogenic fuels and using only one fuel tank

Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?

Can someone explain how this makes sense electrically?



How to display my List into Listview?


Flutter listview with Map instead of ListFlutter - Error updating a list in ListViewFlutter ListView displays wrong itemsFlutter : Can I add a Header Row to a ListViewhow to display images and text on it in listview flutter?Flutter : Bad state: Stream has already been listened toWhy does updating a List<StatefulWidget> that is used in a ListView fail to update the display?Displaying Firebase Firestore Listview Data as a list FlutterHow I can put Widget above Widget using List<Widget> widget in Flutter?Flutter/Dart Basic Understanding













2















i have an Json File as assets. parsing works perfect, but when i use the list from my json, an error is thrown. "the getter was called on null"



Here my JsonCode:



class Biersorten
final List<Bier> biersorten;

Biersorten(
this.biersorten
);

factory Biersorten.fromJson(List<dynamic> parsedJson)
List<Bier> listBiersorten = new List<Bier>();
listBiersorten = parsedJson.map((i)=>Bier.fromJson(i)).toList();

return new Biersorten(
biersorten: listBiersorten,
);



class Bier
int id;
String name;
String firmenname;
String alkoholgehalt;

Bier(this.id, this.name, this.firmenname, this.alkoholgehalt);

factory Bier.fromJson(Map<String, dynamic> parsedJson)
return Bier(
id: parsedJson["id"],
name : parsedJson["name"],
firmenname : parsedJson ["firmenname"],
alkoholgehalt: parsedJson["alkoholgehalt"]
);




Here my HomePageCode:



class MyHomePage extends StatelessWidget 
final String title;
Biersorten biersorten;

MyHomePage(this.title)
loadBier();


Future<String> _loadBierAsset() async
return await rootBundle.loadString("assets/JSON/Beer.json");


Future loadBier() async
String jsonString = await _loadBierAsset();
final jsonResponse = json.decode(jsonString);
biersorten = new Biersorten.fromJson(jsonResponse);
print(biersorten.biersorten[0].alkoholgehalt);


Widget getCard(String title)
return Card(
child: Container(
height: 50,
child: Center(
child: Text(title),
),
)
);


@override
Widget build(BuildContext context)
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Column(
children: <Widget>[
ListView.builder(
itemCount: biersorten.biersorten.length,
itemBuilder: (context, i)
return getCard(biersorten.biersorten[i].name);
,
)
],
),
);




In the Function _loadBierAsset() i can use the List, but in the ListView.builder it throw an error.
How can i solve this problem?



Thanks for help:)










share|improve this question






















  • can you post the Beer.json file?

    – flutter
    2 days ago











  • at least this line in constructor is redundant List<Bier> listBiersorten = new List<Bier>();

    – Eugene
    2 days ago















2















i have an Json File as assets. parsing works perfect, but when i use the list from my json, an error is thrown. "the getter was called on null"



Here my JsonCode:



class Biersorten
final List<Bier> biersorten;

Biersorten(
this.biersorten
);

factory Biersorten.fromJson(List<dynamic> parsedJson)
List<Bier> listBiersorten = new List<Bier>();
listBiersorten = parsedJson.map((i)=>Bier.fromJson(i)).toList();

return new Biersorten(
biersorten: listBiersorten,
);



class Bier
int id;
String name;
String firmenname;
String alkoholgehalt;

Bier(this.id, this.name, this.firmenname, this.alkoholgehalt);

factory Bier.fromJson(Map<String, dynamic> parsedJson)
return Bier(
id: parsedJson["id"],
name : parsedJson["name"],
firmenname : parsedJson ["firmenname"],
alkoholgehalt: parsedJson["alkoholgehalt"]
);




Here my HomePageCode:



class MyHomePage extends StatelessWidget 
final String title;
Biersorten biersorten;

MyHomePage(this.title)
loadBier();


Future<String> _loadBierAsset() async
return await rootBundle.loadString("assets/JSON/Beer.json");


Future loadBier() async
String jsonString = await _loadBierAsset();
final jsonResponse = json.decode(jsonString);
biersorten = new Biersorten.fromJson(jsonResponse);
print(biersorten.biersorten[0].alkoholgehalt);


Widget getCard(String title)
return Card(
child: Container(
height: 50,
child: Center(
child: Text(title),
),
)
);


@override
Widget build(BuildContext context)
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Column(
children: <Widget>[
ListView.builder(
itemCount: biersorten.biersorten.length,
itemBuilder: (context, i)
return getCard(biersorten.biersorten[i].name);
,
)
],
),
);




In the Function _loadBierAsset() i can use the List, but in the ListView.builder it throw an error.
How can i solve this problem?



Thanks for help:)










share|improve this question






















  • can you post the Beer.json file?

    – flutter
    2 days ago











  • at least this line in constructor is redundant List<Bier> listBiersorten = new List<Bier>();

    – Eugene
    2 days ago













2












2








2








i have an Json File as assets. parsing works perfect, but when i use the list from my json, an error is thrown. "the getter was called on null"



Here my JsonCode:



class Biersorten
final List<Bier> biersorten;

Biersorten(
this.biersorten
);

factory Biersorten.fromJson(List<dynamic> parsedJson)
List<Bier> listBiersorten = new List<Bier>();
listBiersorten = parsedJson.map((i)=>Bier.fromJson(i)).toList();

return new Biersorten(
biersorten: listBiersorten,
);



class Bier
int id;
String name;
String firmenname;
String alkoholgehalt;

Bier(this.id, this.name, this.firmenname, this.alkoholgehalt);

factory Bier.fromJson(Map<String, dynamic> parsedJson)
return Bier(
id: parsedJson["id"],
name : parsedJson["name"],
firmenname : parsedJson ["firmenname"],
alkoholgehalt: parsedJson["alkoholgehalt"]
);




Here my HomePageCode:



class MyHomePage extends StatelessWidget 
final String title;
Biersorten biersorten;

MyHomePage(this.title)
loadBier();


Future<String> _loadBierAsset() async
return await rootBundle.loadString("assets/JSON/Beer.json");


Future loadBier() async
String jsonString = await _loadBierAsset();
final jsonResponse = json.decode(jsonString);
biersorten = new Biersorten.fromJson(jsonResponse);
print(biersorten.biersorten[0].alkoholgehalt);


Widget getCard(String title)
return Card(
child: Container(
height: 50,
child: Center(
child: Text(title),
),
)
);


@override
Widget build(BuildContext context)
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Column(
children: <Widget>[
ListView.builder(
itemCount: biersorten.biersorten.length,
itemBuilder: (context, i)
return getCard(biersorten.biersorten[i].name);
,
)
],
),
);




In the Function _loadBierAsset() i can use the List, but in the ListView.builder it throw an error.
How can i solve this problem?



Thanks for help:)










share|improve this question














i have an Json File as assets. parsing works perfect, but when i use the list from my json, an error is thrown. "the getter was called on null"



Here my JsonCode:



class Biersorten
final List<Bier> biersorten;

Biersorten(
this.biersorten
);

factory Biersorten.fromJson(List<dynamic> parsedJson)
List<Bier> listBiersorten = new List<Bier>();
listBiersorten = parsedJson.map((i)=>Bier.fromJson(i)).toList();

return new Biersorten(
biersorten: listBiersorten,
);



class Bier
int id;
String name;
String firmenname;
String alkoholgehalt;

Bier(this.id, this.name, this.firmenname, this.alkoholgehalt);

factory Bier.fromJson(Map<String, dynamic> parsedJson)
return Bier(
id: parsedJson["id"],
name : parsedJson["name"],
firmenname : parsedJson ["firmenname"],
alkoholgehalt: parsedJson["alkoholgehalt"]
);




Here my HomePageCode:



class MyHomePage extends StatelessWidget 
final String title;
Biersorten biersorten;

MyHomePage(this.title)
loadBier();


Future<String> _loadBierAsset() async
return await rootBundle.loadString("assets/JSON/Beer.json");


Future loadBier() async
String jsonString = await _loadBierAsset();
final jsonResponse = json.decode(jsonString);
biersorten = new Biersorten.fromJson(jsonResponse);
print(biersorten.biersorten[0].alkoholgehalt);


Widget getCard(String title)
return Card(
child: Container(
height: 50,
child: Center(
child: Text(title),
),
)
);


@override
Widget build(BuildContext context)
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Column(
children: <Widget>[
ListView.builder(
itemCount: biersorten.biersorten.length,
itemBuilder: (context, i)
return getCard(biersorten.biersorten[i].name);
,
)
],
),
);




In the Function _loadBierAsset() i can use the List, but in the ListView.builder it throw an error.
How can i solve this problem?



Thanks for help:)







dart flutter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









Anton SchrageAnton Schrage

11910




11910












  • can you post the Beer.json file?

    – flutter
    2 days ago











  • at least this line in constructor is redundant List<Bier> listBiersorten = new List<Bier>();

    – Eugene
    2 days ago

















  • can you post the Beer.json file?

    – flutter
    2 days ago











  • at least this line in constructor is redundant List<Bier> listBiersorten = new List<Bier>();

    – Eugene
    2 days ago
















can you post the Beer.json file?

– flutter
2 days ago





can you post the Beer.json file?

– flutter
2 days ago













at least this line in constructor is redundant List<Bier> listBiersorten = new List<Bier>();

– Eugene
2 days ago





at least this line in constructor is redundant List<Bier> listBiersorten = new List<Bier>();

– Eugene
2 days ago












1 Answer
1






active

oldest

votes


















2














It is because your function is async and it doesn't return before the list is built. Till that time the list hasn't been initialized.First change your widget from Stateless to Stateful. Then Do this:



 body: biersorten!=null ?
Column(
children: <Widget>[
ListView.builder(
itemCount: biersorten.biersorten.length,
itemBuilder: (context, i)
return getCard(biersorten.biersorten[i].name);
,
)
],
): Center(child: CircularProgressIndicator()),


And change your loadBier function to



Future loadBier() async 
String jsonString = await _loadBierAsset();
final jsonResponse = json.decode(jsonString);
setState(()
biersorten = new Biersorten.fromJson(jsonResponse);
);
print(biersorten.biersorten[0].alkoholgehalt);



And in your initState() add



loadBier();





share|improve this answer

























  • Thank you. this works perfect to me.

    – Anton Schrage
    2 days ago











  • if it worked then upvote it ... :)

    – Ryosuke
    2 days ago











  • sry my friend:D

    – Anton Schrage
    2 days ago











  • thanks for upvote :)

    – Ryosuke
    2 days ago










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%2f55281365%2fhow-to-display-my-listobject-into-listview%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














It is because your function is async and it doesn't return before the list is built. Till that time the list hasn't been initialized.First change your widget from Stateless to Stateful. Then Do this:



 body: biersorten!=null ?
Column(
children: <Widget>[
ListView.builder(
itemCount: biersorten.biersorten.length,
itemBuilder: (context, i)
return getCard(biersorten.biersorten[i].name);
,
)
],
): Center(child: CircularProgressIndicator()),


And change your loadBier function to



Future loadBier() async 
String jsonString = await _loadBierAsset();
final jsonResponse = json.decode(jsonString);
setState(()
biersorten = new Biersorten.fromJson(jsonResponse);
);
print(biersorten.biersorten[0].alkoholgehalt);



And in your initState() add



loadBier();





share|improve this answer

























  • Thank you. this works perfect to me.

    – Anton Schrage
    2 days ago











  • if it worked then upvote it ... :)

    – Ryosuke
    2 days ago











  • sry my friend:D

    – Anton Schrage
    2 days ago











  • thanks for upvote :)

    – Ryosuke
    2 days ago















2














It is because your function is async and it doesn't return before the list is built. Till that time the list hasn't been initialized.First change your widget from Stateless to Stateful. Then Do this:



 body: biersorten!=null ?
Column(
children: <Widget>[
ListView.builder(
itemCount: biersorten.biersorten.length,
itemBuilder: (context, i)
return getCard(biersorten.biersorten[i].name);
,
)
],
): Center(child: CircularProgressIndicator()),


And change your loadBier function to



Future loadBier() async 
String jsonString = await _loadBierAsset();
final jsonResponse = json.decode(jsonString);
setState(()
biersorten = new Biersorten.fromJson(jsonResponse);
);
print(biersorten.biersorten[0].alkoholgehalt);



And in your initState() add



loadBier();





share|improve this answer

























  • Thank you. this works perfect to me.

    – Anton Schrage
    2 days ago











  • if it worked then upvote it ... :)

    – Ryosuke
    2 days ago











  • sry my friend:D

    – Anton Schrage
    2 days ago











  • thanks for upvote :)

    – Ryosuke
    2 days ago













2












2








2







It is because your function is async and it doesn't return before the list is built. Till that time the list hasn't been initialized.First change your widget from Stateless to Stateful. Then Do this:



 body: biersorten!=null ?
Column(
children: <Widget>[
ListView.builder(
itemCount: biersorten.biersorten.length,
itemBuilder: (context, i)
return getCard(biersorten.biersorten[i].name);
,
)
],
): Center(child: CircularProgressIndicator()),


And change your loadBier function to



Future loadBier() async 
String jsonString = await _loadBierAsset();
final jsonResponse = json.decode(jsonString);
setState(()
biersorten = new Biersorten.fromJson(jsonResponse);
);
print(biersorten.biersorten[0].alkoholgehalt);



And in your initState() add



loadBier();





share|improve this answer















It is because your function is async and it doesn't return before the list is built. Till that time the list hasn't been initialized.First change your widget from Stateless to Stateful. Then Do this:



 body: biersorten!=null ?
Column(
children: <Widget>[
ListView.builder(
itemCount: biersorten.biersorten.length,
itemBuilder: (context, i)
return getCard(biersorten.biersorten[i].name);
,
)
],
): Center(child: CircularProgressIndicator()),


And change your loadBier function to



Future loadBier() async 
String jsonString = await _loadBierAsset();
final jsonResponse = json.decode(jsonString);
setState(()
biersorten = new Biersorten.fromJson(jsonResponse);
);
print(biersorten.biersorten[0].alkoholgehalt);



And in your initState() add



loadBier();






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









RyosukeRyosuke

1818




1818












  • Thank you. this works perfect to me.

    – Anton Schrage
    2 days ago











  • if it worked then upvote it ... :)

    – Ryosuke
    2 days ago











  • sry my friend:D

    – Anton Schrage
    2 days ago











  • thanks for upvote :)

    – Ryosuke
    2 days ago

















  • Thank you. this works perfect to me.

    – Anton Schrage
    2 days ago











  • if it worked then upvote it ... :)

    – Ryosuke
    2 days ago











  • sry my friend:D

    – Anton Schrage
    2 days ago











  • thanks for upvote :)

    – Ryosuke
    2 days ago
















Thank you. this works perfect to me.

– Anton Schrage
2 days ago





Thank you. this works perfect to me.

– Anton Schrage
2 days ago













if it worked then upvote it ... :)

– Ryosuke
2 days ago





if it worked then upvote it ... :)

– Ryosuke
2 days ago













sry my friend:D

– Anton Schrage
2 days ago





sry my friend:D

– Anton Schrage
2 days ago













thanks for upvote :)

– Ryosuke
2 days ago





thanks for upvote :)

– Ryosuke
2 days ago



















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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281365%2fhow-to-display-my-listobject-into-listview%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현