Skip to content

Commit 9e8c9ec

Browse files
author
Ananthu P Kanive
authored
Merge pull request #14 from LonelyCpp/dev
Dev
2 parents 5fb7354 + 4acba82 commit 9e8c9ec

18 files changed

+219
-50
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This is my first project on my journey to learning and understanding flutter and
55

66
![android](./screenshots/android.png?raw=true 'android')
77
![ios](./screenshots/ios.gif?raw=true 'ios')
8+
![ios](./screenshots/ios_chart.gif?raw=true 'ios')
89

910
## Features
1011
- :white_check_mark: Beautiful minimal UI
@@ -14,6 +15,7 @@ This is my first project on my journey to learning and understanding flutter and
1415
- :white_check_mark: 5 day forecast
1516
- :white_check_mark: Beautifully animated transitions
1617
- :white_check_mark: BLoC pattern for API calls
18+
- :white_check_mark: Line graph to show temperature variance
1719

1820
## Getting Started
1921

lib/src/api/http_exception.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// represents an error state from an network API request
2+
/// [code] represents the HTTP response code
3+
/// string [message] reason if any
14
class HTTPException implements Exception {
25
final int code;
36
final String message;
@@ -8,5 +11,4 @@ class HTTPException implements Exception {
811
String toString() {
912
return 'HTTPException{code: $code, message: $message}';
1013
}
11-
1214
}

lib/src/api/weather_api_client.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'package:flutter_weather/src/model/weather.dart';
44
import 'package:meta/meta.dart';
55
import 'package:http/http.dart' as http;
66

7+
/// Wrapper around the open weather map api
8+
/// https://openweathermap.org/current
79
class WeatherApiClient {
810
static const baseUrl = 'http://api.openweathermap.org';
911
final apiKey;

lib/src/bloc/weather_bloc.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ class WeatherBloc extends Bloc<WeatherEvent, WeatherState> {
2323
if (event is FetchWeather) {
2424
yield WeatherLoading();
2525
try {
26-
final Weather weather =
27-
await weatherRepository.getWeather(event.cityName, latitude: event.latitude, longitude: event.longitude);
26+
final Weather weather = await weatherRepository.getWeather(
27+
event.cityName,
28+
latitude: event.latitude,
29+
longitude: event.longitude);
2830
yield WeatherLoaded(weather: weather);
2931
} catch (exception) {
3032
print(exception);

lib/src/repository/weather_repository.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ class WeatherRepository {
77
WeatherRepository({@required this.weatherApiClient})
88
: assert(weatherApiClient != null);
99

10-
Future<Weather> getWeather(String cityName, {double latitude, double longitude}) async {
11-
if(cityName == null){
12-
cityName = await weatherApiClient.getCityNameFromLocation(latitude: latitude, longitude: longitude);
10+
Future<Weather> getWeather(String cityName,
11+
{double latitude, double longitude}) async {
12+
if (cityName == null) {
13+
cityName = await weatherApiClient.getCityNameFromLocation(
14+
latitude: latitude, longitude: longitude);
1315
}
1416
var weather = await weatherApiClient.getWeatherData(cityName);
1517
var weathers = await weatherApiClient.getForecast(cityName);

lib/src/screens/settings_screen.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class SettingsScreen extends StatelessWidget {
1414
body: Container(
1515
padding: EdgeInsets.only(left: 10, right: 10, top: 15),
1616
color: AppStateContainer.of(context).theme.primaryColor,
17-
child: Column(
18-
crossAxisAlignment: CrossAxisAlignment.start,
17+
child: ListView(
1918
children: <Widget>[
2019
Padding(
2120
padding: const EdgeInsets.all(8.0),

lib/src/screens/weather_screen.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ class _WeatherScreenState extends State<WeatherScreen>
232232

233233
Position position = await Geolocator()
234234
.getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
235-
print(position);
236235
_weatherBloc.dispatch(FetchWeather(
237236
longitude: position.longitude, latitude: position.latitude));
238237
}
@@ -253,7 +252,7 @@ class _WeatherScreenState extends State<WeatherScreen>
253252
style: TextStyle(color: Colors.green, fontSize: 16),
254253
),
255254
onPressed: () {
256-
permissionHandler.openAppSettings().then((val) => print(val));
255+
permissionHandler.openAppSettings();
257256
Navigator.of(context).pop();
258257
},
259258
),

lib/src/utils/WeatherIconMapper.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ class _IconData extends IconData {
77
fontFamily: 'WeatherIcons',
88
);
99
}
10-
10+
/// Exposes specific weather icons
11+
/// Has all weather conditions specified by open weather maps API
12+
/// https://openweathermap.org/weather-conditions
13+
// hex values and ttf file from https://erikflowers.github.io/weather-icons/
1114
class WeatherIcons {
1215
static const IconData clear_day = const _IconData(0xf00d);
1316
static const IconData clear_night = const _IconData(0xf02e);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_weather/main.dart';
3+
import 'package:flutter_weather/src/model/weather.dart';
4+
import 'package:flutter_weather/src/widgets/value_tile.dart';
5+
6+
/// Renders Weather Icon, current, min and max temperatures
7+
class CurrentConditions extends StatelessWidget {
8+
final Weather weather;
9+
const CurrentConditions({Key key, this.weather}) : super(key: key);
10+
11+
@override
12+
Widget build(BuildContext context) {
13+
return Column(
14+
mainAxisAlignment: MainAxisAlignment.center,
15+
children: <Widget>[
16+
Icon(
17+
weather.getIconData(),
18+
color: AppStateContainer.of(context).theme.accentColor,
19+
size: 70,
20+
),
21+
SizedBox(
22+
height: 20,
23+
),
24+
Text(
25+
'${this.weather.temperature.as(AppStateContainer.of(context).temperatureUnit).round()}°',
26+
style: TextStyle(
27+
fontSize: 100,
28+
fontWeight: FontWeight.w100,
29+
color: AppStateContainer.of(context).theme.accentColor),
30+
),
31+
Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
32+
ValueTile("max",
33+
'${this.weather.maxTemperature.as(AppStateContainer.of(context).temperatureUnit).round()}°'),
34+
Padding(
35+
padding: const EdgeInsets.only(left: 15, right: 15),
36+
child: Center(
37+
child: Container(
38+
width: 1,
39+
height: 30,
40+
color:
41+
AppStateContainer.of(context).theme.accentColor.withAlpha(50),
42+
)),
43+
),
44+
ValueTile("min",
45+
'${this.weather.minTemperature.as(AppStateContainer.of(context).temperatureUnit).round()}°'),
46+
]),
47+
],
48+
);
49+
}
50+
}

lib/src/widgets/forecast_horizontal_widget.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import 'package:flutter_weather/src/model/weather.dart';
44
import 'package:flutter_weather/src/widgets/value_tile.dart';
55
import 'package:intl/intl.dart';
66

7+
/// Renders a horizontal scrolling list of weather conditions
8+
/// Used to show forecast
9+
/// Shows DateTime, Weather Condition icon and Temperature
710
class ForecastHorizontal extends StatelessWidget {
811
const ForecastHorizontal({
912
Key key,

0 commit comments

Comments
 (0)