-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 957d9c6
Showing
14 changed files
with
538 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json | ||
|
||
|
||
/android | ||
/ios | ||
|
||
/analysis_options.yaml | ||
pubspec.lock | ||
.metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# clima_flutter | ||
|
||
A new Flutter project. | ||
|
||
## Getting Started | ||
|
||
This project is a starting point for a Flutter application. | ||
|
||
A few resources to get you started if this is your first Flutter project: | ||
|
||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) | ||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) | ||
|
||
For help getting started with Flutter development, view the | ||
[online documentation](https://docs.flutter.dev/), which offers tutorials, | ||
samples, guidance on mobile development, and a full API reference. |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:clima_flutter/screens/loading_screen.dart'; | ||
|
||
void main() => runApp(MyApp()); | ||
|
||
class MyApp extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
theme: ThemeData.dark(), | ||
home: LoadingScreen(), | ||
debugShowCheckedModeBanner: false, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:clima_flutter/utilities/constants.dart'; | ||
|
||
class CityScreen extends StatefulWidget { | ||
@override | ||
_CityScreenState createState() => _CityScreenState(); | ||
} | ||
|
||
class _CityScreenState extends State<CityScreen> { | ||
String cityName = ""; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Container( | ||
decoration: BoxDecoration( | ||
image: DecorationImage( | ||
image: AssetImage('images/city_background.jpg'), | ||
fit: BoxFit.cover, | ||
), | ||
), | ||
constraints: BoxConstraints.expand(), | ||
child: SafeArea( | ||
child: Column( | ||
children: <Widget>[ | ||
Align( | ||
alignment: Alignment.topLeft, | ||
child: TextButton( | ||
onPressed: () { | ||
Navigator.pop(context); | ||
}, | ||
child: Icon( | ||
Icons.arrow_back_ios, | ||
size: 50.0, | ||
), | ||
), | ||
), | ||
Container( | ||
padding: EdgeInsets.all(20.0), | ||
child: TextField( | ||
style: TextStyle( | ||
color: Colors.black, | ||
), | ||
decoration: kTextFieldInputDecoration, | ||
onChanged: (value) { | ||
cityName = value; | ||
}, | ||
), | ||
), | ||
TextButton( | ||
onPressed: () { | ||
Navigator.pop(context, cityName); | ||
}, | ||
child: Text( | ||
'Get Weather', | ||
style: kButtonTextStyle, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:clima_flutter/screens/location_screen.dart'; | ||
import 'package:clima_flutter/services/weather.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_spinkit/flutter_spinkit.dart'; | ||
|
||
class LoadingScreen extends StatefulWidget { | ||
@override | ||
_LoadingScreenState createState() => _LoadingScreenState(); | ||
} | ||
|
||
class _LoadingScreenState extends State<LoadingScreen> { | ||
@override | ||
void initState() { | ||
super.initState(); | ||
getLocationData(); | ||
} | ||
|
||
void getLocationData() async { | ||
var weatherData = await WeatherModel().getLocationWeather(); | ||
|
||
Navigator.push(context, MaterialPageRoute(builder: (context) { | ||
return LocationScreen(locationWeather: weatherData); | ||
})); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Center( | ||
child: SpinKitDoubleBounce( | ||
color: Colors.white, | ||
size: 100.0, | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import 'package:clima_flutter/screens/city_screen.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:clima_flutter/utilities/constants.dart'; | ||
import '../services/weather.dart'; | ||
|
||
class LocationScreen extends StatefulWidget { | ||
LocationScreen({this.locationWeather}); | ||
final locationWeather; | ||
@override | ||
_LocationScreenState createState() => _LocationScreenState(); | ||
} | ||
|
||
class _LocationScreenState extends State<LocationScreen> { | ||
WeatherModel weather = WeatherModel(); | ||
late int temperature; | ||
late String weatherIcon; | ||
late String weatherMessage; | ||
String? cityName; | ||
@override | ||
void initState() { | ||
super.initState(); | ||
updateUI(widget.locationWeather); | ||
} | ||
|
||
void updateUI(dynamic weatherData) { | ||
setState(() { | ||
if (weatherData == null) { | ||
temperature = 0; | ||
weatherIcon = 'Error'; | ||
weatherMessage = 'Unable to get weather data.'; | ||
cityName = ''; | ||
return; | ||
} | ||
|
||
double temp = weatherData['main']['temp']; | ||
temperature = temp.toInt(); | ||
var condition = weatherData['weather'][0]['id']; | ||
weatherIcon = weather.getWeatherIcon(condition); | ||
weatherMessage = weather.getMessage(temperature); | ||
cityName = weatherData['name']; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Container( | ||
decoration: BoxDecoration( | ||
image: DecorationImage( | ||
image: AssetImage('images/location_background.jpg'), | ||
fit: BoxFit.cover, | ||
colorFilter: ColorFilter.mode( | ||
Colors.white.withOpacity(0.8), BlendMode.dstATop), | ||
), | ||
), | ||
constraints: BoxConstraints.expand(), | ||
child: SafeArea( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: <Widget>[ | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: <Widget>[ | ||
TextButton( | ||
onPressed: () async { | ||
var weatherData = await weather.getLocationWeather(); | ||
updateUI(weatherData); | ||
}, | ||
child: Icon( | ||
Icons.near_me, | ||
size: 50.0, | ||
), | ||
), | ||
TextButton( | ||
onPressed: () async { | ||
var typedName = await Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) { | ||
return CityScreen(); | ||
}, | ||
), | ||
); | ||
if (typedName != null) { | ||
var weatherData = | ||
await weather.getCityWeather(typedName); | ||
updateUI(weatherData); | ||
} | ||
}, | ||
child: Icon( | ||
Icons.location_city, | ||
size: 50.0, | ||
), | ||
), | ||
], | ||
), | ||
Padding( | ||
padding: EdgeInsets.only(left: 15.0), | ||
child: Row( | ||
children: <Widget>[ | ||
Text( | ||
'$temperature°', | ||
style: kTempTextStyle, | ||
), | ||
Text( | ||
weatherIcon, | ||
style: kConditionTextStyle, | ||
), | ||
], | ||
), | ||
), | ||
Padding( | ||
padding: EdgeInsets.only(right: 15.0), | ||
child: Text( | ||
'$weatherMessage in $cityName!', | ||
textAlign: TextAlign.right, | ||
style: kMessageTextStyle, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:geolocator/geolocator.dart'; | ||
|
||
class Location { | ||
double? latitude; | ||
double? longitude; | ||
|
||
Future<void> getCurrentPosition() async { | ||
try { | ||
Position position = await Geolocator.getCurrentPosition( | ||
desiredAccuracy: LocationAccuracy.low); | ||
// print(position); | ||
latitude = position.latitude; | ||
longitude = position.longitude; | ||
} catch (e) { | ||
print(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:http/http.dart' as http; | ||
import 'dart:convert'; | ||
|
||
class NetworkHelper { | ||
final String url; | ||
NetworkHelper(this.url); | ||
|
||
Future getData() async { | ||
http.Response response = await http.get(Uri.parse(url)); | ||
|
||
if (response.statusCode == 200) { | ||
String data = response.body; | ||
return jsonDecode(data); | ||
} else { | ||
print(response.statusCode); | ||
} | ||
} | ||
} |
Oops, something went wrong.