When launching the application the string appears as null Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?How to properly wait until future is complete in dartSafely turning a JSON string into an objectHow to escape braces (curly brackets) in a format string in .NETHow do I parse a string to a float or int in Python?Identify if a string is a number.NET - JSON serialization of enum as stringConvert JS object to JSON stringHow do I turn a C# object into a JSON string in .NET?Flutter - Implementing a Navigation drawer with a TabBarView widget with dynamic Tab viewHow to offset a scaffold widget in Flutter?Flutter : Bad state: Stream has already been listened to
Are my PIs rude or am I just being too sensitive?
How discoverable are IPv6 addresses and AAAA names by potential attackers?
What is the musical term for a note that continously plays through a melody?
Do you forfeit tax refunds/credits if you aren't required to and don't file by April 15?
How can I make names more distinctive without making them longer?
Why was the term "discrete" used in discrete logarithm?
Is there a service that would inform me whenever a new direct route is scheduled from a given airport?
Is the address of a local variable a constexpr?
I am not a queen, who am I?
Is there a "higher Segal conjecture"?
What LEGO pieces have "real-world" functionality?
Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?
Disable hyphenation for an entire paragraph
When -s is used with third person singular. What's its use in this context?
Is there a concise way to say "all of the X, one of each"?
Output the ŋarâþ crîþ alphabet song without using (m)any letters
Proof involving the spectral radius and Jordan Canonical form
If Jon Snow became King of the Seven Kingdoms what would his regnal number be?
Should I call the interviewer directly, if HR aren't responding?
Right-skewed distribution with mean equals to mode?
What causes the vertical darker bands in my photo?
How can players work together to take actions that are otherwise impossible?
How to bypass password on Windows XP account?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
When launching the application the string appears as null
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?How to properly wait until future is complete in dartSafely turning a JSON string into an objectHow to escape braces (curly brackets) in a format string in .NETHow do I parse a string to a float or int in Python?Identify if a string is a number.NET - JSON serialization of enum as stringConvert JS object to JSON stringHow do I turn a C# object into a JSON string in .NET?Flutter - Implementing a Navigation drawer with a TabBarView widget with dynamic Tab viewHow to offset a scaffold widget in Flutter?Flutter : Bad state: Stream has already been listened to
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
As the title has said, whenever I run the flutter application in my phone (debug mode atm, I don't know if it will work correctly in release mode). The dndguide.toString() appears as null. However, upon a hot reload the string appears normally. Is there a way to avoid this and make it work correctly upon launching? I suspect I put the loadjson() call in the wrong location, but I've tried shaping the code so that the function is called in different areas and no success.
Here is the code for the application:
import 'package:flutter/material.dart';
import 'dart:async' show Future;
import 'package:flutter/services.dart' show rootBundle;
import 'dart:convert';
void main() => runApp(MyApp());
var dndguide;
class MyApp extends StatelessWidget
// This widget is the root of your application.
@override
Widget build(BuildContext context)
return MaterialApp(
home: MyHomePage(),
);
class MyHomePage extends StatefulWidget
@override
_MyHomePageState createState() => _MyHomePageState();
class _MyHomePageState extends State<MyHomePage>
Future<String> _loadAsset() async
return await rootBundle.loadString('assets/data/HDARG.json');
Future loadjson() async
String jsonString = await _loadAsset();
final jsonResponse = json.decode(jsonString);
dndguide = jsonResponse;
@override
Widget build(BuildContext context)
loadjson();
var scrollcontroller;
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: MediaQuery.of(context).size.height - 24,
margin: EdgeInsets.only(top: 24.0),
width: MediaQuery.of(context).size.width * .90,
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
controller: scrollcontroller,
scrollDirection: Axis.vertical,
child: Text(dndguide.toString()),
),
),
],
),
),
);
json parsing dart flutter
add a comment |
As the title has said, whenever I run the flutter application in my phone (debug mode atm, I don't know if it will work correctly in release mode). The dndguide.toString() appears as null. However, upon a hot reload the string appears normally. Is there a way to avoid this and make it work correctly upon launching? I suspect I put the loadjson() call in the wrong location, but I've tried shaping the code so that the function is called in different areas and no success.
Here is the code for the application:
import 'package:flutter/material.dart';
import 'dart:async' show Future;
import 'package:flutter/services.dart' show rootBundle;
import 'dart:convert';
void main() => runApp(MyApp());
var dndguide;
class MyApp extends StatelessWidget
// This widget is the root of your application.
@override
Widget build(BuildContext context)
return MaterialApp(
home: MyHomePage(),
);
class MyHomePage extends StatefulWidget
@override
_MyHomePageState createState() => _MyHomePageState();
class _MyHomePageState extends State<MyHomePage>
Future<String> _loadAsset() async
return await rootBundle.loadString('assets/data/HDARG.json');
Future loadjson() async
String jsonString = await _loadAsset();
final jsonResponse = json.decode(jsonString);
dndguide = jsonResponse;
@override
Widget build(BuildContext context)
loadjson();
var scrollcontroller;
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: MediaQuery.of(context).size.height - 24,
margin: EdgeInsets.only(top: 24.0),
width: MediaQuery.of(context).size.width * .90,
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
controller: scrollcontroller,
scrollDirection: Axis.vertical,
child: Text(dndguide.toString()),
),
),
],
),
),
);
json parsing dart flutter
add a comment |
As the title has said, whenever I run the flutter application in my phone (debug mode atm, I don't know if it will work correctly in release mode). The dndguide.toString() appears as null. However, upon a hot reload the string appears normally. Is there a way to avoid this and make it work correctly upon launching? I suspect I put the loadjson() call in the wrong location, but I've tried shaping the code so that the function is called in different areas and no success.
Here is the code for the application:
import 'package:flutter/material.dart';
import 'dart:async' show Future;
import 'package:flutter/services.dart' show rootBundle;
import 'dart:convert';
void main() => runApp(MyApp());
var dndguide;
class MyApp extends StatelessWidget
// This widget is the root of your application.
@override
Widget build(BuildContext context)
return MaterialApp(
home: MyHomePage(),
);
class MyHomePage extends StatefulWidget
@override
_MyHomePageState createState() => _MyHomePageState();
class _MyHomePageState extends State<MyHomePage>
Future<String> _loadAsset() async
return await rootBundle.loadString('assets/data/HDARG.json');
Future loadjson() async
String jsonString = await _loadAsset();
final jsonResponse = json.decode(jsonString);
dndguide = jsonResponse;
@override
Widget build(BuildContext context)
loadjson();
var scrollcontroller;
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: MediaQuery.of(context).size.height - 24,
margin: EdgeInsets.only(top: 24.0),
width: MediaQuery.of(context).size.width * .90,
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
controller: scrollcontroller,
scrollDirection: Axis.vertical,
child: Text(dndguide.toString()),
),
),
],
),
),
);
json parsing dart flutter
As the title has said, whenever I run the flutter application in my phone (debug mode atm, I don't know if it will work correctly in release mode). The dndguide.toString() appears as null. However, upon a hot reload the string appears normally. Is there a way to avoid this and make it work correctly upon launching? I suspect I put the loadjson() call in the wrong location, but I've tried shaping the code so that the function is called in different areas and no success.
Here is the code for the application:
import 'package:flutter/material.dart';
import 'dart:async' show Future;
import 'package:flutter/services.dart' show rootBundle;
import 'dart:convert';
void main() => runApp(MyApp());
var dndguide;
class MyApp extends StatelessWidget
// This widget is the root of your application.
@override
Widget build(BuildContext context)
return MaterialApp(
home: MyHomePage(),
);
class MyHomePage extends StatefulWidget
@override
_MyHomePageState createState() => _MyHomePageState();
class _MyHomePageState extends State<MyHomePage>
Future<String> _loadAsset() async
return await rootBundle.loadString('assets/data/HDARG.json');
Future loadjson() async
String jsonString = await _loadAsset();
final jsonResponse = json.decode(jsonString);
dndguide = jsonResponse;
@override
Widget build(BuildContext context)
loadjson();
var scrollcontroller;
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: MediaQuery.of(context).size.height - 24,
margin: EdgeInsets.only(top: 24.0),
width: MediaQuery.of(context).size.width * .90,
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
controller: scrollcontroller,
scrollDirection: Axis.vertical,
child: Text(dndguide.toString()),
),
),
],
),
),
);
json parsing dart flutter
json parsing dart flutter
asked Mar 8 at 16:14
F. CasianoF. Casiano
32
32
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The json
response is called asynchronously, which why the first time it gives null
and after hot reloading it appears successfully. You should put some placeholder value into your dndguide
variable or call the json
in the initState()
function of your _MyHomePageState
instead of calling it during build
process:
@override
void initState()
super.initState();
loadjson();
I've added the @override to the _MyHomePageState class as you've suggested but the problem still persists. It only shows after a hot refresh. Could it be an issue with the async itself?
– F. Casiano
Mar 8 at 19:59
AFutureBuilder
will be suitable for your case.which will begin building your widget only after the data is recieved.
– Mazin Ibrahim
Mar 8 at 20:01
stackoverflow.com/questions/54634418/…
– Mazin Ibrahim
Mar 8 at 20:06
Thank you! That was exactly what I needed. With FutureBuilder I removed almost everything that was causing me problems.
– F. Casiano
Mar 9 at 2:51
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%2f55067011%2fwhen-launching-the-application-the-string-appears-as-null%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
The json
response is called asynchronously, which why the first time it gives null
and after hot reloading it appears successfully. You should put some placeholder value into your dndguide
variable or call the json
in the initState()
function of your _MyHomePageState
instead of calling it during build
process:
@override
void initState()
super.initState();
loadjson();
I've added the @override to the _MyHomePageState class as you've suggested but the problem still persists. It only shows after a hot refresh. Could it be an issue with the async itself?
– F. Casiano
Mar 8 at 19:59
AFutureBuilder
will be suitable for your case.which will begin building your widget only after the data is recieved.
– Mazin Ibrahim
Mar 8 at 20:01
stackoverflow.com/questions/54634418/…
– Mazin Ibrahim
Mar 8 at 20:06
Thank you! That was exactly what I needed. With FutureBuilder I removed almost everything that was causing me problems.
– F. Casiano
Mar 9 at 2:51
add a comment |
The json
response is called asynchronously, which why the first time it gives null
and after hot reloading it appears successfully. You should put some placeholder value into your dndguide
variable or call the json
in the initState()
function of your _MyHomePageState
instead of calling it during build
process:
@override
void initState()
super.initState();
loadjson();
I've added the @override to the _MyHomePageState class as you've suggested but the problem still persists. It only shows after a hot refresh. Could it be an issue with the async itself?
– F. Casiano
Mar 8 at 19:59
AFutureBuilder
will be suitable for your case.which will begin building your widget only after the data is recieved.
– Mazin Ibrahim
Mar 8 at 20:01
stackoverflow.com/questions/54634418/…
– Mazin Ibrahim
Mar 8 at 20:06
Thank you! That was exactly what I needed. With FutureBuilder I removed almost everything that was causing me problems.
– F. Casiano
Mar 9 at 2:51
add a comment |
The json
response is called asynchronously, which why the first time it gives null
and after hot reloading it appears successfully. You should put some placeholder value into your dndguide
variable or call the json
in the initState()
function of your _MyHomePageState
instead of calling it during build
process:
@override
void initState()
super.initState();
loadjson();
The json
response is called asynchronously, which why the first time it gives null
and after hot reloading it appears successfully. You should put some placeholder value into your dndguide
variable or call the json
in the initState()
function of your _MyHomePageState
instead of calling it during build
process:
@override
void initState()
super.initState();
loadjson();
answered Mar 8 at 16:28
Mazin IbrahimMazin Ibrahim
1,4501817
1,4501817
I've added the @override to the _MyHomePageState class as you've suggested but the problem still persists. It only shows after a hot refresh. Could it be an issue with the async itself?
– F. Casiano
Mar 8 at 19:59
AFutureBuilder
will be suitable for your case.which will begin building your widget only after the data is recieved.
– Mazin Ibrahim
Mar 8 at 20:01
stackoverflow.com/questions/54634418/…
– Mazin Ibrahim
Mar 8 at 20:06
Thank you! That was exactly what I needed. With FutureBuilder I removed almost everything that was causing me problems.
– F. Casiano
Mar 9 at 2:51
add a comment |
I've added the @override to the _MyHomePageState class as you've suggested but the problem still persists. It only shows after a hot refresh. Could it be an issue with the async itself?
– F. Casiano
Mar 8 at 19:59
AFutureBuilder
will be suitable for your case.which will begin building your widget only after the data is recieved.
– Mazin Ibrahim
Mar 8 at 20:01
stackoverflow.com/questions/54634418/…
– Mazin Ibrahim
Mar 8 at 20:06
Thank you! That was exactly what I needed. With FutureBuilder I removed almost everything that was causing me problems.
– F. Casiano
Mar 9 at 2:51
I've added the @override to the _MyHomePageState class as you've suggested but the problem still persists. It only shows after a hot refresh. Could it be an issue with the async itself?
– F. Casiano
Mar 8 at 19:59
I've added the @override to the _MyHomePageState class as you've suggested but the problem still persists. It only shows after a hot refresh. Could it be an issue with the async itself?
– F. Casiano
Mar 8 at 19:59
A
FutureBuilder
will be suitable for your case.which will begin building your widget only after the data is recieved.– Mazin Ibrahim
Mar 8 at 20:01
A
FutureBuilder
will be suitable for your case.which will begin building your widget only after the data is recieved.– Mazin Ibrahim
Mar 8 at 20:01
stackoverflow.com/questions/54634418/…
– Mazin Ibrahim
Mar 8 at 20:06
stackoverflow.com/questions/54634418/…
– Mazin Ibrahim
Mar 8 at 20:06
Thank you! That was exactly what I needed. With FutureBuilder I removed almost everything that was causing me problems.
– F. Casiano
Mar 9 at 2:51
Thank you! That was exactly what I needed. With FutureBuilder I removed almost everything that was causing me problems.
– F. Casiano
Mar 9 at 2:51
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%2f55067011%2fwhen-launching-the-application-the-string-appears-as-null%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