I am getting data api and I convert it from Json. I have this method to get data, bet when using it in a future builder it giving me getPData() method was called on null.
this is where I create getPData method:
class JsonConnection {
JsonConnection.jsonDecode();
static double pLat;
static double pLong;
PData timesList;
Future getPData() async {
final pos = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.medium);
pLat = pos.latitude;
pLong = pos.longitude;
String date = DateTime.now().toString();
int method = 4;
final url = Uri.parse(
'http://api.aladhan.com/v1/timings/$date?latitude=$pLat&longitude=$pLong&method=$method');
http.Response res = await http.get(url);
var data = json.decode(res.body);
timesList = PData.fromJson(data);
return timesList;
}
here is where I used getPData:
body: FutureBuilder(
future: jsonConnection.getPData(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
print("hello");
print(snapshot.data.meta.timezone);
if (snapshot.hasData) {
CircleAvatar();
return Center(
child: Container(
padding: const EdgeInsets.only(top: 150.0),
child: Column(
children: [
Table(
border: TableBorder.all(color: Colors.purpleAccent),
defaultColumnWidth: FixedColumnWidth(150.0),
defaultVerticalAlignment:
TableCellVerticalAlignment.middle,
children: <TableRow>[
TableRow(
children: <Widget>[
TableCell(
verticalAlignment:
TableCellVerticalAlignment.middle,
child: Center(
child: Text(snapshot.data.meta.timezone,
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.bold)),
)),
what I can do to fix it?
