Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

Commit

Permalink
Removed the get current location's weather button
Browse files Browse the repository at this point in the history
  • Loading branch information
PrestoSole committed Dec 27, 2020
1 parent 68c0558 commit bc5ab22
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity-2.0.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-6.1.13\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.12+4\\\\","dependencies":[]}],"android":[{"name":"connectivity","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity-2.0.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-6.1.13\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.12+4\\\\","dependencies":[]}],"macos":[{"name":"connectivity_macos","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_macos-0.1.0+7\\\\","dependencies":[]},{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-0.0.1+11\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-0.0.1+2\\\\","dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-0.0.2+4\\\\","dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-0.0.4+3\\\\","dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-0.0.1+3\\\\","dependencies":["path_provider_windows"]}],"web":[{"name":"connectivity_for_web","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_for_web-0.3.1+4\\\\","dependencies":[]},{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-0.1.2+7\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity","dependencies":["connectivity_macos","connectivity_for_web"]},{"name":"connectivity_for_web","dependencies":[]},{"name":"connectivity_macos","dependencies":[]},{"name":"geolocator","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2020-12-18 12:50:02.429605","version":"1.22.5"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity-2.0.2\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.12+4\\\\","dependencies":[]}],"android":[{"name":"connectivity","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity-2.0.2\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.12+4\\\\","dependencies":[]}],"macos":[{"name":"connectivity_macos","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_macos-0.1.0+7\\\\","dependencies":[]},{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-0.0.1+11\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-0.0.1+2\\\\","dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-0.0.2+4\\\\","dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-0.0.4+3\\\\","dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-0.0.1+3\\\\","dependencies":["path_provider_windows"]}],"web":[{"name":"connectivity_for_web","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_for_web-0.3.1+4\\\\","dependencies":[]},{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-0.1.2+7\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity","dependencies":["connectivity_macos","connectivity_for_web"]},{"name":"connectivity_for_web","dependencies":[]},{"name":"connectivity_macos","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2020-12-27 16:09:17.342761","version":"1.22.5"}
1 change: 0 additions & 1 deletion fastlane/metadata/android/en-US/full_description.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
A simple and fast weather app that uses the OpenWeatherMap API.

* Simple design
* Gives the current location's weather
* Works with any city in the world
60 changes: 29 additions & 31 deletions lib/screens/location_screen.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:clima/services/location.dart';
import 'package:clima/services/networking.dart';
import 'package:clima/services/weather.dart';
import 'package:clima/utilities/constants.dart';
import 'package:clima/utilities/reusable_widgets.dart';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'city_screen.dart';
Expand Down Expand Up @@ -41,22 +39,22 @@ class _LocationScreenState extends State<LocationScreen> {
_scaffoldKey.currentState.removeCurrentSnackBar();
final dynamic weatherData = await future;
updateUI(weatherData);
} on LocationServicesTurnedOff {
_scaffoldKey.currentState.showSnackBar(
await snackBar(
text: 'Location is turned off.',
action: SnackBarAction(
label: 'Turn on',
onPressed: () async {
await Geolocator.openLocationSettings();
},
),
),
);
} on LocationPermissionDenied {
_scaffoldKey.currentState.showSnackBar(
await snackBar(text: 'Permission denied.'),
);
// } on LocationServicesTurnedOff {
// _scaffoldKey.currentState.showSnackBar(
// await snackBar(
// text: 'Location is turned off.',
// action: SnackBarAction(
// label: 'Turn on',
// onPressed: () async {
// await Geolocator.openLocationSettings();
// },
// ),
// ),
// );
// } on LocationPermissionDenied {
// _scaffoldKey.currentState.showSnackBar(
// await snackBar(text: 'Permission denied.'),
// );
} on NoInternetConnection {
_scaffoldKey.currentState.showSnackBar(
await snackBar(text: 'No network connection.'),
Expand Down Expand Up @@ -155,19 +153,19 @@ class _LocationScreenState extends State<LocationScreen> {
),

/// The get current geographic location's weather button.
IconButton(
icon: const Icon(Icons.location_on_outlined),
tooltip: "Get current geographic location's weather",
onPressed: () {
setState(() {
isVisible = true;
});
errorHandler(
future: weather.getLocationWeather(),
errorMessage: "Can't connect to server.",
);
},
),
// IconButton(
// icon: const Icon(Icons.location_on_outlined),
// tooltip: "Get current geographic location's weather",
// onPressed: () {
// setState(() {
// isVisible = true;
// });
// errorHandler(
// future: weather.getLocationWeather(),
// errorMessage: "Can't connect to server.",
// );
// },
// ),
],
),
body: Container(
Expand Down
84 changes: 42 additions & 42 deletions lib/services/location.dart
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import 'package:geolocator/geolocator.dart';

class LocationServicesTurnedOff implements Exception {}

class LocationPermissionDenied implements Exception {}

class Location {
double latitude;
double longitude;

/// This function is responsible to get the latitude and longitude using the Geolocator package.
Future<void> getCurrentLocation() async {
final bool isLocationServiceEnabled =
await Geolocator.isLocationServiceEnabled();
final LocationPermission permission = await Geolocator.checkPermission();
if (isLocationServiceEnabled) {
if (permission == LocationPermission.whileInUse ||
permission == LocationPermission.always) {
final Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.low);

latitude = position.latitude;
longitude = position.longitude;
} else if (permission == LocationPermission.denied) {
await Geolocator.requestPermission();
final LocationPermission permissionAgain =
await Geolocator.checkPermission();
if (permissionAgain == LocationPermission.denied ||
permissionAgain == LocationPermission.deniedForever) {
throw LocationPermissionDenied();
} else {
await getCurrentLocation();
}
} else {
await Geolocator.openAppSettings();
throw LocationPermissionDenied();
}
} else {
throw LocationServicesTurnedOff();
}
}
}
// import 'package:geolocator/geolocator.dart';
//
// class LocationServicesTurnedOff implements Exception {}
//
// class LocationPermissionDenied implements Exception {}
//
// class Location {
// double latitude;
// double longitude;
//
// /// This function is responsible to get the latitude and longitude using the Geolocator package.
// Future<void> getCurrentLocation() async {
// final bool isLocationServiceEnabled =
// await Geolocator.isLocationServiceEnabled();
// final LocationPermission permission = await Geolocator.checkPermission();
// if (isLocationServiceEnabled) {
// if (permission == LocationPermission.whileInUse ||
// permission == LocationPermission.always) {
// final Position position = await Geolocator.getCurrentPosition(
// desiredAccuracy: LocationAccuracy.low);
//
// latitude = position.latitude;
// longitude = position.longitude;
// } else if (permission == LocationPermission.denied) {
// await Geolocator.requestPermission();
// final LocationPermission permissionAgain =
// await Geolocator.checkPermission();
// if (permissionAgain == LocationPermission.denied ||
// permissionAgain == LocationPermission.deniedForever) {
// throw LocationPermissionDenied();
// } else {
// await getCurrentLocation();
// }
// } else {
// await Geolocator.openAppSettings();
// throw LocationPermissionDenied();
// }
// } else {
// throw LocationServicesTurnedOff();
// }
// }
// }
23 changes: 11 additions & 12 deletions lib/services/weather.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:clima/services/location.dart';
import 'package:clima/services/networking.dart';

const String apiKey = '4bef3adf2fcb90307c2bf5feac75a2ba';
Expand All @@ -16,17 +15,17 @@ class WeatherModel {
}

/// This function gets the weatherData using geographic coordinates.
Future<dynamic> getLocationWeather() async {
final Location location = Location();
await location.getCurrentLocation();

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

final dynamic weatherData = await networkHelper.getData();
return weatherData;
}
// Future<dynamic> getLocationWeather() async {
// final Location location = Location();
// await location.getCurrentLocation();
//
// final NetworkHelper networkHelper = NetworkHelper(
// '$openWeatherMapURL?lat=${location.latitude}&lon=${location.longitude}&appid=$apiKey&units=metric',
// );
//
// final dynamic weatherData = await networkHelper.getData();
// return weatherData;
// }

/// This function returns the right weather icon for the right condition.
String getWeatherIcon(int condition) {
Expand Down
14 changes: 0 additions & 14 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
geolocator:
dependency: "direct main"
description:
name: geolocator
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.13"
geolocator_platform_interface:
dependency: transitive
description:
name: geolocator_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.8"
http:
dependency: "direct main"
description:
Expand Down
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: clima
description: A new Flutter application.

version: 0.1+2
version: 1.0+1

environment:
sdk: ">=2.1.0 <3.0.0"
Expand All @@ -14,7 +14,6 @@ dependencies:
shared_preferences: ^0.5.12+4
connectivity: ^2.0.1
auto_size_text: ^2.1.0
geolocator: ^6.1.13
http: ^0.12.0+2
flutter_spinkit: ^4.1.2+1
lint: ^1.4.0-dev.d210.1
Expand Down

0 comments on commit bc5ab22

Please sign in to comment.