Reputation: 139
Hi I'm having two problems when trying to import API's into flutter, first it seems it seems it is unable to read the data from my snapshot so when I use the function if (snapshot.hasData) it keeps showing the CircularProgressIndicator.
Second problem is when I try to add a variables to allow me to add text from the API it is giving me the error 'The property can't be unconditionally accessed because the receiver can be 'null''`
@override
Widget build(BuildContext context) {
return Scaffold (
appBar: AppBar(
title: Text('News App'),
),
body: Container(
child: FutureBuilder<Welcome>(
future: _Welcome,
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: 52,
itemBuilder:(context, index) {
var ticker = snapshot.data.ticker; //error here
return Container(
height: 100,
child: Row(
children: [
Text(ticker)
],
),
);
});
}
else
return Center(child: CircularProgressIndicator());
},
),
)
);
}`
Upvotes: 0
Views: 2430
Reputation: 46
For your first problem try it with
if (snapshot.connectionState == ConnectionState.done)
For your second problem try adding an exclamation mark to guarantee the value is not null
var ticker = snapshot.data!.ticker;
Upvotes: 2