Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the code seems to stop at await . #18

Open
ghost opened this issue Oct 23, 2020 · 0 comments
Open

the code seems to stop at await . #18

ghost opened this issue Oct 23, 2020 · 0 comments

Comments

@ghost
Copy link

ghost commented Oct 23, 2020

import 'dart:convert';

import 'package:clima/services/location.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

const KapiKey = '1c7a174d6a5d41f17e6f08959deecf2d';

class LoadingScreen extends StatefulWidget {
@OverRide
_LoadingScreenState createState() => _LoadingScreenState();
}

class _LoadingScreenState extends State {
double latitude;
double longtiude;
@OverRide
void initState() {
// TODO: implement initState
super.initState();
getLocation();
// if i place getData() here only then it gets called.
}

void getLocation() async {
Location location = Location();
print('hi'); //this will prin
print('hi'); // this also will print
await location.getCurrentLocation();
print('hi'); this will not print.
latitude = location.lat;
longtiude = location.long;
getData(); doesnot get called at all!
}

void getData() async {
http.Response response = await http.get(
'http://api.openweathermap.org/data/2.5/weather?lat=$latitude&lon=$longtiude&appid=$KapiKey');
if (response.statusCode == 200) {
String data = response.body;
print(data);
var DecodedData = jsonDecode(data);
double tempreture = DecodedData['main']['temp'];
int condition = DecodedData['weather'][0]['id'];
String cityName = DecodedData['name'];
print(tempreture);
print(condition);
print(cityName);
} else {
print(response.statusCode);
}
}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Center(),
);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants