Skip to content

Commit

Permalink
🐛 FIX: Errors + Code Formate
Browse files Browse the repository at this point in the history
  • Loading branch information
sharjeelyunus committed Jun 4, 2020
1 parent 8e5538e commit 1d80e30
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class MyApp extends StatelessWidget {
home: LoadingScreen(),
);
}
}
}
4 changes: 3 additions & 1 deletion lib/screens/city_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:clima/utilities/constants.dart';
import '../utilities/constants.dart';

class CityScreen extends StatefulWidget {
@override
Expand All @@ -8,6 +9,7 @@ class CityScreen extends StatefulWidget {

class _CityScreenState extends State<CityScreen> {
String cityName;

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -59,4 +61,4 @@ class _CityScreenState extends State<CityScreen> {
),
);
}
}
}
19 changes: 14 additions & 5 deletions lib/screens/loading_screen.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import 'package:flutter/material.dart';
import 'package:clima/screens/location_screen.dart';
import '../services/weather.dart';
import 'location_screen.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:clima/services/weather.dart';

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

class _LoadingScreenState extends State<LoadingScreen> {
double latitude;
double longitude;

@override
void initState() {
super.initState();
Expand All @@ -34,9 +37,15 @@ class _LoadingScreenState extends State<LoadingScreen> {
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SpinKitDoubleBounce(
color: Colors.white,
size: 100.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text('Make sure your location is turned on!!'),
SpinKitFadingCube(
color: Colors.white,
size: 100,
),
],
),
),
);
Expand Down
18 changes: 8 additions & 10 deletions lib/screens/location_screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:clima/screens/city_screen.dart';
import 'package:flutter/material.dart';
import 'package:clima/utilities/constants.dart';
import 'package:clima/services/weather.dart';
import 'city_screen.dart';
import '../services/weather.dart';

class LocationScreen extends StatefulWidget {
LocationScreen({this.locationWeather});
Expand All @@ -13,16 +13,15 @@ class LocationScreen extends StatefulWidget {
}

class _LocationScreenState extends State<LocationScreen> {
WeatherModel weather = WeatherModel();
int temperature;
String weatherIcon;
String cityName;
String weatherMessage;
String cityName;
WeatherModel weather = WeatherModel();

@override
void initState() {
super.initState();

updateUI(widget.locationWeather);
}

Expand All @@ -35,11 +34,12 @@ class _LocationScreenState extends State<LocationScreen> {
cityName = '';
return;
}
double temp = weatherData['main']['temp'];
var temp = weatherData['main']['temp'];
temperature = temp.toInt();
weatherMessage = weather.getMessage(temperature);

var condition = weatherData['weather'][0]['id'];
weatherIcon = weather.getWeatherIcon(condition);
weatherMessage = weather.getMessage(temperature);
cityName = weatherData['name'];
});
}
Expand Down Expand Up @@ -80,9 +80,7 @@ class _LocationScreenState extends State<LocationScreen> {
var typedName = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return CityScreen();
},
builder: (context) => CityScreen(),
),
);
if (typedName != null) {
Expand Down
3 changes: 2 additions & 1 deletion lib/services/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ class Location {
try {
Position position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.low);

latitude = position.latitude;
longitude = position.longitude;
} catch (e) {
print(e);
}
}
}
}
3 changes: 1 addition & 2 deletions lib/services/networking.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:http/http.dart' as http;
import 'dart:convert';

class NetworkHelper {

NetworkHelper(this.url);

final String url;
Expand All @@ -14,7 +13,7 @@ class NetworkHelper {
String data = response.body;

return jsonDecode(data);
} else {
} else {
print(response.statusCode);
}
}
Expand Down
9 changes: 4 additions & 5 deletions lib/services/weather.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import 'package:clima/services/location.dart';
import 'package:clima/services/networking.dart';

const apiKey = 'f1b3b6fcd051b681a4de47af96412cc4';
const openWeatherMapUrl = 'https://api.openweathermap.org/data/2.5/weather';
const openWeatherMapURL = 'https://api.openweathermap.org/data/2.5/weather';

class WeatherModel {
Future<dynamic> getCityWeather(String cityName) async {
NetworkHelper networkHelper = NetworkHelper(
'$openWeatherMapUrl?q=$cityName&appid=$apiKey&units=metric');
'$openWeatherMapURL?q=$cityName&appid=$apiKey&units=metric');

var weatherData = await networkHelper.getData();
return weatherData;
}
Expand All @@ -18,10 +18,9 @@ class WeatherModel {
await location.getCurrentLocation();

NetworkHelper networkHelper = NetworkHelper(
'$openWeatherMapUrl?lat=${location.latitude}&lon=${location.longitude}&appid=$apiKey&units=metric');
'$openWeatherMapURL?lat=${location.latitude}&lon=${location.longitude}&appid=$apiKey&units=metric');

var weatherData = await networkHelper.getData();

return weatherData;
}

Expand Down
9 changes: 7 additions & 2 deletions lib/utilities/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ const kConditionTextStyle = TextStyle(
const kTextFieldInputDecoration = InputDecoration(
filled: true,
fillColor: Colors.white,
icon: Icon(Icons.location_city, color: Colors.white),
icon: Icon(
Icons.location_city,
color: Colors.white,
),
hintText: 'Enter City Name',
hintStyle: TextStyle(color: Colors.grey),
hintStyle: TextStyle(
color: Colors.grey,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10.0),
Expand Down

0 comments on commit 1d80e30

Please sign in to comment.