Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Fix Filipe's mistakes. #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
include ':app'

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}
99 changes: 53 additions & 46 deletions lib/Screens/homeScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class HomeScreen extends StatefulWidget {

class _HomeScreenState extends State<HomeScreen> {
PageController _pageController = PageController();
bool _isLoading;
bool _isLoading = true;

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

Expand Down Expand Up @@ -53,7 +54,7 @@ class _HomeScreenState extends State<HomeScreen> {

return SafeArea(
child: Scaffold(
body: true
body: _isLoading
? Center(
child: CircularProgressIndicator(
backgroundColor: myContext.primaryColor,
Expand All @@ -67,7 +68,7 @@ class _HomeScreenState extends State<HomeScreen> {
)
: weatherData.isLocationError
? LocationError()
: Stack(
: Column(
children: [
SearchBar(),
SmoothPageIndicator(
Expand All @@ -82,60 +83,66 @@ class _HomeScreenState extends State<HomeScreen> {
weatherData.isRequestError
? RequestError()
: Expanded(
child: PageView(
controller: _pageController,
children: [
Container(
padding: const EdgeInsets.all(10),
width: mediaQuery.size.width,
child: RefreshIndicator(
onRefresh: () =>
_refreshData(context),
backgroundColor: Colors.blue,
child: ListView(
children: [
FadeIn(
delay: 0,
child: MainWeather(
wData: weatherData)),
FadeIn(
delay: 0.33,
child: WeatherInfo(
wData: weatherData
.currentWeather),
),
FadeIn(
delay: 0.66,
child: HourlyForecast(
weatherData.hourlyWeather),
),
],
),
),
),
Container(
height: mediaQuery.size.height,
width: mediaQuery.size.width,
child: PageView(
controller: _pageController,
children: [
Container(
padding: const EdgeInsets.all(10),
width: mediaQuery.size.width,
child: RefreshIndicator(
onRefresh: () =>
_refreshData(context),
backgroundColor: Colors.blue,
child: ListView(
children: [
FadeIn(
delay: 0.33,
child: SevenDayForecast(
delay: 0,
child: MainWeather(
wData: weatherData,
dWeather:
weatherData.sevenDayWeather,
),
),
FadeIn(
delay: 0.66,
child: WeatherDetail(
wData: weatherData)),
delay: 0.33,
child: WeatherInfo(
wData: weatherData
.currentWeather,
),
),
FadeIn(
delay: 0.66,
child: HourlyForecast(
weatherData.hourlyWeather,
),
),
],
),
),
],
),
),
Container(
height: mediaQuery.size.height,
width: mediaQuery.size.width,
child: ListView(
children: [
FadeIn(
delay: 0.33,
child: SevenDayForecast(
wData: weatherData,
dWeather:
weatherData.sevenDayWeather,
),
),
FadeIn(
delay: 0.66,
child: WeatherDetail(
wData: weatherData,
),
),
],
),
),
],
),
),
],
),
),
Expand Down
1 change: 1 addition & 0 deletions lib/Screens/hourlyWeatherScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class HourlyScreen extends StatelessWidget {
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
hours ?? '',
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:logger/logger.dart';
var logger = Logger();

var config = {
'OpenWeatherApiKey': 'fdb61777bda2658e2b20d16554abc84a',
'OpenWeatherApiKey': '930e781343fe6cbe7301649ddbe66189',
};

void main() {
Expand Down
1 change: 0 additions & 1 deletion lib/models/weather.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class Weather with ChangeNotifier {
});

factory Weather.fromJson(Map<String, dynamic> json) {
return Weather();
return Weather(
temp: json['main']['temp'],
tempMax: json['main']['temp_max'],
Expand Down
6 changes: 3 additions & 3 deletions lib/provider/weatherProvider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ class WeatherProvider with ChangeNotifier {

var url =
'https://api.openweathermap.org/data/2.5/weather?q=$location&units=metric&appid=$apiKey';

try {
final response = await http.get(url);
final extractedData = json.decode(response.body) as Map<String, dynamic>;

weather = Weather.fromJson(extractedData);
} catch (error) {
loading = false;
Expand All @@ -108,14 +110,12 @@ class WeatherProvider with ChangeNotifier {
}
var latitude = weather.lat;
var longitude = weather.long;
print(latitude);
print(longitude);

var dailyUrl =
'https://api.openweathermap.org/data/2.5/onecall?lat=$latitude&lon=$longitude&units=metric&exclude=minutely,current&appid=$apiKey';
try {
final response = await http.get(dailyUrl);
final dailyData = json.decode(response.body) as Map<String, dynamic>;
print(dailyUrl);
currentWeather = DailyWeather.fromJson(dailyData);
var tempHourly = [];
var temp24Hour = [];
Expand Down
22 changes: 12 additions & 10 deletions lib/widgets/requestError.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RequestError extends StatelessWidget {
color: Colors.black,
size: 100,
),
SizedBox(height: 10),
// SizedBox(height: 10),
Text(
'No Search Result',
style: TextStyle(
Expand All @@ -22,15 +22,17 @@ class RequestError extends StatelessWidget {
fontWeight: FontWeight.w500,
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 75, vertical: 10),
child: Text(
"Please make sure that you entered the correct location name",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.grey[700],
fontSize: 15,
fontWeight: FontWeight.w400,
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 75, vertical: 10),
child: Text(
"Please make sure that you entered the correct location name",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.grey[700],
fontSize: 15,
fontWeight: FontWeight.w400,
),
),
),
),
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/searchBar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class _SearchBarState extends State<SearchBar> {
hintText: "Search Location",
),
onSubmitted: (value) {
print(value);
setState(() {
_textController.text.isEmpty
? _validate = true
Expand Down
15 changes: 6 additions & 9 deletions lib/widgets/sevenDayForecast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,12 @@ class SevenDayForecast extends StatelessWidget {
),
SizedBox(height: 15),
Expanded(
child: ListView(
scrollDirection: Axis.vertical,
children: [
Row(
children: dWeather
.map((item) => dailyWidget(item, context))
.toList(),
),
],
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: dWeather.length,
itemBuilder: (context, index) {
return dailyWidget(dWeather[index], context);
}
),
),
],
Expand Down
4 changes: 3 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ environment:
sdk: ">=2.7.0 <3.0.0"

dependencies:
logger: ^0.9.4

flutter:
sdk: flutter

cupertino_icons: ^1.0.0
http: ^0.12.2
intl: ^0.16.1
Expand All @@ -21,6 +22,7 @@ dependencies:
flutter_weather_icons: ^1.0.2
smooth_page_indicator: ^0.2.0
simple_animations: ^2.5.1
logger: ^0.9.4


dev_dependencies:
Expand Down