Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xcrescent committed Dec 22, 2022
1 parent 3889024 commit 033423a
Show file tree
Hide file tree
Showing 20 changed files with 453 additions and 99 deletions.
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<application
android:label="Weather"
android:label="Sky Sense"
android:name="${applicationName}"
android:icon="@drawable/app_icon_1">
<activity
Expand Down
32 changes: 27 additions & 5 deletions lib/controller/http_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:weather_app/models/openweathermodel.dart';
import 'package:weather_app/screens/additional/settings.dart';

// 'X-RapidAPI-Key': '78d83b60c8mshe5f3c4b35aa6bc2p131eb3jsne0ebd6ea2f41',
// 'X-RapidAPI-Host': 'weatherbit-v1-mashape.p.rapidapi.com'
class HttpController {
Future<WelcomeCurrent> fetchWeatherCurrent(double lat, double lon) async {

// print(lat + lon);
// final response = await http.get(Uri.parse(
// 'https://weatherbit-v1-mashape.p.rapidapi.com/forecast/3hourly?lat=$latitude&lon=$longitude'),headers: {
Expand All @@ -15,8 +17,12 @@ class HttpController {
// '01c2ba1c7cmshbcf4163cbfc9e28p1f846ajsn6d7542a40d6a',
// 'X-RapidAPI-Host': 'weatherbit-v1-mashape.p.rapidapi.com'
// });
var unit = 'metric';
if (tempUnit == SingingCharacter.fahrenheit) {
unit = 'imperial';
}
final response = await http.get(Uri.parse(
'https://api.openweathermap.org/data/2.5/weather?lat=$lat&lon=$lon&appid=8476478bea8d6ea40c4a303496f86447&units=metric'));
'https://api.openweathermap.org/data/2.5/weather?lat=$lat&lon=$lon&appid=8476478bea8d6ea40c4a303496f86447&units=$unit'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
Expand All @@ -39,8 +45,12 @@ class HttpController {
// '01c2ba1c7cmshbcf4163cbfc9e28p1f846ajsn6d7542a40d6a',
// 'X-RapidAPI-Host': 'weatherbit-v1-mashape.p.rapidapi.com'
// });
var unit = 'metric';
if (tempUnit == SingingCharacter.fahrenheit) {
unit = 'imperial';
}
final response = await http.get(Uri.parse(
'https://api.openweathermap.org/data/2.5/forecast/daily?lat=$lat&lon=$lon&appid=8476478bea8d6ea40c4a303496f86447&units=metric'));
'https://api.openweathermap.org/data/2.5/forecast/daily?lat=$lat&lon=$lon&appid=8476478bea8d6ea40c4a303496f86447&units=$unit'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
Expand All @@ -63,8 +73,12 @@ class HttpController {
// '01c2ba1c7cmshbcf4163cbfc9e28p1f846ajsn6d7542a40d6a',
// 'X-RapidAPI-Host': 'weatherbit-v1-mashape.p.rapidapi.com'
// });
var unit = 'metric';
if (tempUnit == SingingCharacter.fahrenheit) {
unit = 'imperial';
}
final response = await http.get(Uri.parse(
'https://pro.openweathermap.org/data/2.5/forecast/hourly?lat=$lat&lon=$lon&appid=8476478bea8d6ea40c4a303496f86447&units=metric'));
'https://pro.openweathermap.org/data/2.5/forecast/hourly?lat=$lat&lon=$lon&appid=8476478bea8d6ea40c4a303496f86447&units=$unit'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
Expand All @@ -87,8 +101,12 @@ class HttpController {
// '01c2ba1c7cmshbcf4163cbfc9e28p1f846ajsn6d7542a40d6a',
// 'X-RapidAPI-Host': 'weatherbit-v1-mashape.p.rapidapi.com'
// });
var unit = 'metric';
if (tempUnit == SingingCharacter.fahrenheit) {
unit = 'imperial';
}
final response = await http.get(Uri.parse(
'https://pro.openweathermap.org/data/2.5/forecast/hourly?q=$cityName&appid=8476478bea8d6ea40c4a303496f86447&units=metric'));
'https://pro.openweathermap.org/data/2.5/forecast/hourly?q=$cityName&appid=8476478bea8d6ea40c4a303496f86447&units=$unit'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
Expand All @@ -111,8 +129,12 @@ class HttpController {
// '01c2ba1c7cmshbcf4163cbfc9e28p1f846ajsn6d7542a40d6a',
// 'X-RapidAPI-Host': 'weatherbit-v1-mashape.p.rapidapi.com'
// });
var unit = 'metric';
if (tempUnit == SingingCharacter.fahrenheit) {
unit = 'imperial';
}
final response = await http.get(Uri.parse(
'https://api.openweathermap.org/data/2.5/forecast/daily?q=$cityName&appid=8476478bea8d6ea40c4a303496f86447&units=metric'));
'https://api.openweathermap.org/data/2.5/forecast/daily?q=$cityName&appid=8476478bea8d6ea40c4a303496f86447&units=$unit'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
Expand Down
7 changes: 1 addition & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
// https://youtu.be/ZSVnIphlGKI

import 'package:flutter/material.dart';
import 'package:weather_app/screens/additional/settings.dart';
import 'package:weather_app/screens/city_weather.dart';
import 'package:weather_app/screens/loading_screen.dart';
import 'package:weather_app/screens/splash_screen.dart';
import 'package:weather_app/screens/today_screen.dart';
import 'package:weather_app/screens/weather_now.dart';
import 'package:weather_app/screens/week_screen.dart';
import 'package:weather_app/widgets/share_widget.dart';

void main() {
runApp(const MyApp());
Expand All @@ -31,7 +26,7 @@ class MyApp extends StatelessWidget {
"/": (context) => const SplashScreen(),
"/loading": (context) => const LoadingScreen(),
"/weather" :(context) => const WeatherHome(),
"/settings": (context) => const SettingsScreen(),
// "/settings": (context) => const SettingsScreen(),
},
);
}
Expand Down
93 changes: 80 additions & 13 deletions lib/screens/additional/settings.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import 'package:flutter/material.dart';

class SettingsScreen extends StatelessWidget {
const SettingsScreen({super.key});
enum SingingCharacter { celsius, fahrenheit }

SingingCharacter? tempUnit = SingingCharacter.celsius;

class SettingsScreen extends StatefulWidget {
SettingsScreen({super.key});
// dynamic refresh;
@override
State<SettingsScreen> createState() => _SettingsScreenState();
}

class _SettingsScreenState extends State<SettingsScreen> {
@override
Widget build(BuildContext context) {
return SafeArea(
Expand All @@ -28,18 +37,76 @@ class SettingsScreen extends StatelessWidget {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text("Temperature Unit"),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))),
backgroundColor: const Color(0xff453D99),
title: const Text(
"Temperature Unit",
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontFamily: 'Poppins',
fontWeight: FontWeight.w400,
),
),
content: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Please turn on your internet connection'),
const Text(
'Please turn on your internet connection'),
],
padding: const EdgeInsets.all(8.0),
child: Container(
height: 140,
width: 80,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 8.0, horizontal: 8),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RadioListTile<SingingCharacter>(
value: SingingCharacter.celsius,
groupValue: tempUnit,
activeColor: Colors.white,

// tileColor: Colors.white,
title: Text(
'Celsius (°C)',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontFamily: 'Poppins',
fontWeight: FontWeight.w400,
),
),
onChanged: (SingingCharacter? value) {
Navigator.of(context).pop();
// widget.refresh();
setState(() {
tempUnit = value;
});
}),
RadioListTile<SingingCharacter>(
value: SingingCharacter.fahrenheit,
activeColor: Colors.white,

// tileColor: Colors.white,
groupValue: tempUnit,
title: Text(
'Fahrenheit (°F)',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontFamily: 'Poppins',
fontWeight: FontWeight.w400,
),
),
onChanged: (SingingCharacter? value) {
Navigator.of(context).pop();
setState(() {
tempUnit = value;
});
}),
],
),
),
),
),
),
Expand Down
56 changes: 56 additions & 0 deletions lib/screens/additional/share_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';

class ShareWidget extends StatelessWidget {
ShareWidget({super.key, required this.directory, required this.imageData});
Directory directory;
Uint8List? imageData;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Share Screenshot"),
),
body: Column(
children: [
const SizedBox(
height: 20,
),
Container(
width: 600,
height: 600,
decoration: BoxDecoration(
image: imageData == null
? null
: DecorationImage(
image: MemoryImage(imageData!),
),
),
),
imageData == null
? const Text("Could not load Image")
: const Text(""),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
textStyle: const TextStyle(
color: Colors.white,
),
),
onPressed: () async {
Share.shareFiles(
['${directory.path}/weather_ss.jpg'],
text: "Today's weather",
);
},
child: const Text("Share"),
),
],
),
);
}
}
8 changes: 7 additions & 1 deletion lib/screens/fragments/home_fragment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:weather_app/controller/http_controller.dart';
import 'package:weather_app/models/openweathermodel.dart';
import 'dart:io';

import 'package:weather_app/screens/additional/settings.dart';

class HomeFragment extends StatefulWidget {
const HomeFragment({super.key});

Expand Down Expand Up @@ -71,10 +73,14 @@ class _HomeFragmentState extends State<HomeFragment> {
const SizedBox(
height: 20,
),
Text(
tempUnit==SingingCharacter.celsius? Text(
"${snapshot.data!.main.temp} °C",
style: const TextStyle(
fontSize: 63, fontWeight: FontWeight.w600),
):Text(
"${snapshot.data!.main.temp} °F",
style: const TextStyle(
fontSize: 63, fontWeight: FontWeight.w600),
),
// const SizedBox(
// height: 20,
Expand Down
11 changes: 5 additions & 6 deletions lib/screens/loading_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class _LoadingScreenState extends State<LoadingScreen> {
Get.put(GlobalController(), permanent: true);

void timerNext() {
Timer(const Duration(milliseconds: 3600), () {
Timer(const Duration(milliseconds: 1600), () {
if (globalController.checkLoading().isFalse) {
Navigator.pushReplacementNamed(context, '/weather');
} else if (globalController.checkLoading().isFalse){
} else if (globalController.checkLoading().isTrue) {
timerNext();
}
});
Expand All @@ -39,11 +39,10 @@ class _LoadingScreenState extends State<LoadingScreen> {
MaterialPageRoute(builder: (context) => const WeatherHome()),
);
}
setState(() {
timerNext();
});
timerNext();
});
}

@override
void dispose() {
super.dispose();
Expand All @@ -70,7 +69,7 @@ class _LoadingScreenState extends State<LoadingScreen> {
),
speed: const Duration(milliseconds: 400)),
],
totalRepeatCount: 1,
totalRepeatCount: 2,
),
),
),
Expand Down
14 changes: 0 additions & 14 deletions lib/screens/local_weather.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/screens/splash_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class _SplashState extends State<SplashScreen> {
@override
void initState() {
super.initState();
Timer(const Duration(milliseconds: 5400), () {
Timer(const Duration(milliseconds: 5500), () {
Navigator.pushReplacement(
context,
//page route after splash screen
Expand Down
Loading

0 comments on commit 033423a

Please sign in to comment.