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;








-1















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>'"










share|improve this question






























    -1















    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>'"










    share|improve this question


























      -1












      -1








      -1








      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>'"










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 10:52









      RandyRandy

      82 bronze badges




      82 bronze badges

























          2 Answers
          2






          active

          oldest

          votes


















          1














          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'),);





          share|improve this answer

























          • 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 Texts. 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


















          0














          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');





          share|improve this answer

























          • 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














          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%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









          1














          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'),);





          share|improve this answer

























          • 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 Texts. 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















          1














          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'),);





          share|improve this answer

























          • 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 Texts. 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













          1












          1








          1







          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'),);





          share|improve this answer













          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'),);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 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 Texts. 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

















          • 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 Texts. 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
















          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 Texts. 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 Texts. 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













          0














          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');





          share|improve this answer

























          • 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
















          0














          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');





          share|improve this answer

























          • 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














          0












          0








          0







          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');





          share|improve this answer













          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');






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 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


















          • 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

















          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


















          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%2f55375432%2fkeep-getting-instance-of-futuredynamic-as-output-from-json%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권, 지리지 충청도 공주목 은진현