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(),
);
}
}
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(),
);
}
}