Keep getting “Instance of 'Future'” as output from jsonFlutter: Fetch certain elements of a HTML pageIs there a way to get the Future from setMethodCallHandler?Loading a file using rootBundlefuture functions keep repeatingFlutter pushReplacementNamed().then() does not triggerHow to get primitive value from Future object (Future<int>) in flutter?How to use searchDelegate with future list from jsonCould not launch Instance of 'Future<String>'type 'Future<dynamic>' is not a subtype of type 'String'
Xdebug not working over Drush
Letting unbanned users comment
Should I leave building the database for the end?
How much can I judge a company based on a phone screening?
What kind of liquid can be seen 'leaking' from the upper surface of the wing of a Boeing 737-800?
Do beef farmed pastures net remove carbon emissions?
Why aren't rainbows blurred-out into nothing after they are produced?
Creating some gif with tikz: Any idea to get better result?
Why not demand President's/candidate's financial records instead of tax returns?
"Mouth-breathing" as slang for stupidity
A trip to the library
Is there a way to proportionalize fixed costs in a MILP?
What is the farthest a camera can see?
Does an Irish VISA WARNING count as "refused entry at the border of any country other than the UK?"
Luggage Storage at Szechenyi Baths
Running code generated in realtime in JavaScript with eval()
Global BGP Routing only by only importing supernet prefixes
Why does cat'ing a file via ssh result in control characters?
Are those flyers about apartment purchase a scam?
Are employers legally allowed to pay employees in goods and services equal to or greater than the minimum wage?
How to not forget things?
How can I communicate my issues with a potential date's pushy behavior?
In the movie Krull, what happened in the Spider Den?
Are there examples in Tanach of 3 or more parties having an ongoing conversation?
Keep getting “Instance of 'Future'” as output from json
Flutter: Fetch certain elements of a HTML pageIs there a way to get the Future from setMethodCallHandler?Loading a file using rootBundlefuture functions keep repeatingFlutter pushReplacementNamed().then() does not triggerHow to get primitive value from Future object (Future<int>) in flutter?How to use searchDelegate with future list from jsonCould not launch Instance of 'Future<String>'type 'Future<dynamic>' is not a subtype of type 'String'
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to call a json api from https://jsonplaceholder.typicode.com/posts, but my output is "Instance of Future".
I obviously want the correct output to be 1. Check the link as to why it should be 1
getJson() is in a different .dart file(but same project) as the output.
I believe it is working correctly(since there is an output)
import 'package:http/http.dart' as http;
import 'dart:convert';
Future<List> getJson() async
String apiURL = "https://jsonplaceholder.typicode.com/posts";
http.Response response = await http.get(apiURL);
return json.decode(response.body);
Future getData(int i, String place) async
List _data = await getJson();
return _data[i][place];
Then the output is
Text("This is the output $getData(0, "id")"
which results in "Instance of 'Future<dynamic>'"
flutter
add a comment |
I want to call a json api from https://jsonplaceholder.typicode.com/posts, but my output is "Instance of Future".
I obviously want the correct output to be 1. Check the link as to why it should be 1
getJson() is in a different .dart file(but same project) as the output.
I believe it is working correctly(since there is an output)
import 'package:http/http.dart' as http;
import 'dart:convert';
Future<List> getJson() async
String apiURL = "https://jsonplaceholder.typicode.com/posts";
http.Response response = await http.get(apiURL);
return json.decode(response.body);
Future getData(int i, String place) async
List _data = await getJson();
return _data[i][place];
Then the output is
Text("This is the output $getData(0, "id")"
which results in "Instance of 'Future<dynamic>'"
flutter
add a comment |
I want to call a json api from https://jsonplaceholder.typicode.com/posts, but my output is "Instance of Future".
I obviously want the correct output to be 1. Check the link as to why it should be 1
getJson() is in a different .dart file(but same project) as the output.
I believe it is working correctly(since there is an output)
import 'package:http/http.dart' as http;
import 'dart:convert';
Future<List> getJson() async
String apiURL = "https://jsonplaceholder.typicode.com/posts";
http.Response response = await http.get(apiURL);
return json.decode(response.body);
Future getData(int i, String place) async
List _data = await getJson();
return _data[i][place];
Then the output is
Text("This is the output $getData(0, "id")"
which results in "Instance of 'Future<dynamic>'"
flutter
I want to call a json api from https://jsonplaceholder.typicode.com/posts, but my output is "Instance of Future".
I obviously want the correct output to be 1. Check the link as to why it should be 1
getJson() is in a different .dart file(but same project) as the output.
I believe it is working correctly(since there is an output)
import 'package:http/http.dart' as http;
import 'dart:convert';
Future<List> getJson() async
String apiURL = "https://jsonplaceholder.typicode.com/posts";
http.Response response = await http.get(apiURL);
return json.decode(response.body);
Future getData(int i, String place) async
List _data = await getJson();
return _data[i][place];
Then the output is
Text("This is the output $getData(0, "id")"
which results in "Instance of 'Future<dynamic>'"
flutter
flutter
asked Mar 27 at 10:52
RandyRandy
82 bronze badges
82 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can wrap your Text
inside FutureBuilder
- something like that:
FutureBuilder(builder: (BuildContext context, AsyncSnapshot<String> snapshot)
if (snapshot.hasData) return Text("This is the output $snapshot.data");
else return Text("There is no output yet");
, future: getData(0, 'id'),);
The output text is in aColumn(children: <Widgets>[Text(""), Text("")]
Can you explain how to do it there?
– Randy
Mar 27 at 11:13
You can wrap the wholeColumn
inFutureBuilder
if you need this data for bothText
s. Ifsnapshot.hasData
you return filled texts. In other case you can return what you want - some placeholder or just emptyContainer
– Andrey Turkovsky
Mar 27 at 11:29
add a comment |
You need to await for the response
So instead of:
Text("This is the output $getData(0, "id")"
You need to do:
String _data = await getData(0, 'id');
Text('This is the output $_data');
My output is in a stateful widget like thisclass MyApp extends StatefulWidget @override _MyAppState createState() => _MyAppState(); class _MyAppState extends State<MyApp>
Do I need to add something else? Because I'm writingString _data = await getData(0, 'id');
before the override in the _MyAppState class, but getting an error for await
– Randy
Mar 27 at 11:07
Yeah that is fine, you could call this in initState(). But function that awaits has to be async so for example you could do this like:String _data; void showData() async getData(0, 'id').then((String s) if(mounted) setState(() => _data = s); );
Or you could just use FutureBuilder like different answer suggested
– knezzz
Mar 27 at 11:09
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%2f55375432%2fkeep-getting-instance-of-futuredynamic-as-output-from-json%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
You can wrap your Text
inside FutureBuilder
- something like that:
FutureBuilder(builder: (BuildContext context, AsyncSnapshot<String> snapshot)
if (snapshot.hasData) return Text("This is the output $snapshot.data");
else return Text("There is no output yet");
, future: getData(0, 'id'),);
The output text is in aColumn(children: <Widgets>[Text(""), Text("")]
Can you explain how to do it there?
– Randy
Mar 27 at 11:13
You can wrap the wholeColumn
inFutureBuilder
if you need this data for bothText
s. Ifsnapshot.hasData
you return filled texts. In other case you can return what you want - some placeholder or just emptyContainer
– Andrey Turkovsky
Mar 27 at 11:29
add a comment |
You can wrap your Text
inside FutureBuilder
- something like that:
FutureBuilder(builder: (BuildContext context, AsyncSnapshot<String> snapshot)
if (snapshot.hasData) return Text("This is the output $snapshot.data");
else return Text("There is no output yet");
, future: getData(0, 'id'),);
The output text is in aColumn(children: <Widgets>[Text(""), Text("")]
Can you explain how to do it there?
– Randy
Mar 27 at 11:13
You can wrap the wholeColumn
inFutureBuilder
if you need this data for bothText
s. Ifsnapshot.hasData
you return filled texts. In other case you can return what you want - some placeholder or just emptyContainer
– Andrey Turkovsky
Mar 27 at 11:29
add a comment |
You can wrap your Text
inside FutureBuilder
- something like that:
FutureBuilder(builder: (BuildContext context, AsyncSnapshot<String> snapshot)
if (snapshot.hasData) return Text("This is the output $snapshot.data");
else return Text("There is no output yet");
, future: getData(0, 'id'),);
You can wrap your Text
inside FutureBuilder
- something like that:
FutureBuilder(builder: (BuildContext context, AsyncSnapshot<String> snapshot)
if (snapshot.hasData) return Text("This is the output $snapshot.data");
else return Text("There is no output yet");
, future: getData(0, 'id'),);
answered Mar 27 at 11:00
Andrey TurkovskyAndrey Turkovsky
6,5294 gold badges22 silver badges47 bronze badges
6,5294 gold badges22 silver badges47 bronze badges
The output text is in aColumn(children: <Widgets>[Text(""), Text("")]
Can you explain how to do it there?
– Randy
Mar 27 at 11:13
You can wrap the wholeColumn
inFutureBuilder
if you need this data for bothText
s. Ifsnapshot.hasData
you return filled texts. In other case you can return what you want - some placeholder or just emptyContainer
– Andrey Turkovsky
Mar 27 at 11:29
add a comment |
The output text is in aColumn(children: <Widgets>[Text(""), Text("")]
Can you explain how to do it there?
– Randy
Mar 27 at 11:13
You can wrap the wholeColumn
inFutureBuilder
if you need this data for bothText
s. Ifsnapshot.hasData
you return filled texts. In other case you can return what you want - some placeholder or just emptyContainer
– Andrey Turkovsky
Mar 27 at 11:29
The output text is in a
Column(children: <Widgets>[Text(""), Text("")]
Can you explain how to do it there?– Randy
Mar 27 at 11:13
The output text is in a
Column(children: <Widgets>[Text(""), Text("")]
Can you explain how to do it there?– Randy
Mar 27 at 11:13
You can wrap the whole
Column
in FutureBuilder
if you need this data for both Text
s. If snapshot.hasData
you return filled texts. In other case you can return what you want - some placeholder or just empty Container
– Andrey Turkovsky
Mar 27 at 11:29
You can wrap the whole
Column
in FutureBuilder
if you need this data for both Text
s. If snapshot.hasData
you return filled texts. In other case you can return what you want - some placeholder or just empty Container
– Andrey Turkovsky
Mar 27 at 11:29
add a comment |
You need to await for the response
So instead of:
Text("This is the output $getData(0, "id")"
You need to do:
String _data = await getData(0, 'id');
Text('This is the output $_data');
My output is in a stateful widget like thisclass MyApp extends StatefulWidget @override _MyAppState createState() => _MyAppState(); class _MyAppState extends State<MyApp>
Do I need to add something else? Because I'm writingString _data = await getData(0, 'id');
before the override in the _MyAppState class, but getting an error for await
– Randy
Mar 27 at 11:07
Yeah that is fine, you could call this in initState(). But function that awaits has to be async so for example you could do this like:String _data; void showData() async getData(0, 'id').then((String s) if(mounted) setState(() => _data = s); );
Or you could just use FutureBuilder like different answer suggested
– knezzz
Mar 27 at 11:09
add a comment |
You need to await for the response
So instead of:
Text("This is the output $getData(0, "id")"
You need to do:
String _data = await getData(0, 'id');
Text('This is the output $_data');
My output is in a stateful widget like thisclass MyApp extends StatefulWidget @override _MyAppState createState() => _MyAppState(); class _MyAppState extends State<MyApp>
Do I need to add something else? Because I'm writingString _data = await getData(0, 'id');
before the override in the _MyAppState class, but getting an error for await
– Randy
Mar 27 at 11:07
Yeah that is fine, you could call this in initState(). But function that awaits has to be async so for example you could do this like:String _data; void showData() async getData(0, 'id').then((String s) if(mounted) setState(() => _data = s); );
Or you could just use FutureBuilder like different answer suggested
– knezzz
Mar 27 at 11:09
add a comment |
You need to await for the response
So instead of:
Text("This is the output $getData(0, "id")"
You need to do:
String _data = await getData(0, 'id');
Text('This is the output $_data');
You need to await for the response
So instead of:
Text("This is the output $getData(0, "id")"
You need to do:
String _data = await getData(0, 'id');
Text('This is the output $_data');
answered Mar 27 at 10:55
knezzzknezzz
3962 silver badges7 bronze badges
3962 silver badges7 bronze badges
My output is in a stateful widget like thisclass MyApp extends StatefulWidget @override _MyAppState createState() => _MyAppState(); class _MyAppState extends State<MyApp>
Do I need to add something else? Because I'm writingString _data = await getData(0, 'id');
before the override in the _MyAppState class, but getting an error for await
– Randy
Mar 27 at 11:07
Yeah that is fine, you could call this in initState(). But function that awaits has to be async so for example you could do this like:String _data; void showData() async getData(0, 'id').then((String s) if(mounted) setState(() => _data = s); );
Or you could just use FutureBuilder like different answer suggested
– knezzz
Mar 27 at 11:09
add a comment |
My output is in a stateful widget like thisclass MyApp extends StatefulWidget @override _MyAppState createState() => _MyAppState(); class _MyAppState extends State<MyApp>
Do I need to add something else? Because I'm writingString _data = await getData(0, 'id');
before the override in the _MyAppState class, but getting an error for await
– Randy
Mar 27 at 11:07
Yeah that is fine, you could call this in initState(). But function that awaits has to be async so for example you could do this like:String _data; void showData() async getData(0, 'id').then((String s) if(mounted) setState(() => _data = s); );
Or you could just use FutureBuilder like different answer suggested
– knezzz
Mar 27 at 11:09
My output is in a stateful widget like this
class MyApp extends StatefulWidget @override _MyAppState createState() => _MyAppState(); class _MyAppState extends State<MyApp>
Do I need to add something else? Because I'm writing String _data = await getData(0, 'id');
before the override in the _MyAppState class, but getting an error for await– Randy
Mar 27 at 11:07
My output is in a stateful widget like this
class MyApp extends StatefulWidget @override _MyAppState createState() => _MyAppState(); class _MyAppState extends State<MyApp>
Do I need to add something else? Because I'm writing String _data = await getData(0, 'id');
before the override in the _MyAppState class, but getting an error for await– Randy
Mar 27 at 11:07
Yeah that is fine, you could call this in initState(). But function that awaits has to be async so for example you could do this like:
String _data; void showData() async getData(0, 'id').then((String s) if(mounted) setState(() => _data = s); );
Or you could just use FutureBuilder like different answer suggested– knezzz
Mar 27 at 11:09
Yeah that is fine, you could call this in initState(). But function that awaits has to be async so for example you could do this like:
String _data; void showData() async getData(0, 'id').then((String s) if(mounted) setState(() => _data = s); );
Or you could just use FutureBuilder like different answer suggested– knezzz
Mar 27 at 11:09
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%2f55375432%2fkeep-getting-instance-of-futuredynamic-as-output-from-json%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