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
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
add a comment |
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
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
add a comment |
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
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
dart flutter
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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();
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
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
add a comment |
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();
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
add a comment |
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();
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();
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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