Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api #8

Open
wants to merge 3 commits 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
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MyApp extends StatelessWidget {
return MaterialApp(
navigatorKey: getIt<NavigationService>().navigatorKey,
title: 'Weather Alert Flutter',
initialRoute: '/forecast',
initialRoute: '/weatherinfo',
onGenerateRoute: RouteGenerator.generateRoute,
debugShowCheckedModeBanner: false,
theme: ThemeData(
Expand Down
2 changes: 2 additions & 0 deletions lib/provider/getit.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:get_it/get_it.dart';
import 'package:weather_alert_app/services/navigation_service.dart';
import 'package:weather_alert_app/views/weatherinfo_viewmodel.dart';
import 'package:weather_alert_app/views/Forecast_Info_ViewModel.dart';

GetIt getIt = GetIt.instance;
void setupLocator() {
getIt.registerLazySingleton(() => NavigationService());
getIt.registerFactory(() => WeatherInfoViewModel());
getIt.registerFactory(() => ForecastInfoViewModel());
}
3 changes: 0 additions & 3 deletions lib/route_generator.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import 'package:flutter/material.dart';
import 'package:weather_alert_app/src/screens/homescreen.dart';

import 'package:weather_alert_app/src/screens/forecast_screen.dart';

import 'package:weather_alert_app/src/screens/weather_info_screen.dart';

import 'package:weather_alert_app/src/screens/alert_rescue.dart';

class RouteGenerator {
Expand Down
129 changes: 94 additions & 35 deletions lib/src/screens/weather_info_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ import 'package:flutter/material.dart';
import 'package:weather_alert_app/provider/getit.dart';
import 'package:weather_alert_app/config/app_config.dart' as config;
import 'package:weather_alert_app/provider/base_view.dart';
import 'package:weather_alert_app/views/weatherinfo_viewmodel.dart';
import 'package:weather/weather.dart';
import 'package:weather_alert_app/views/Forecast_Info_ViewModel.dart';

class WeatherInfoScreen extends StatelessWidget {
const WeatherInfoScreen({Key? key}) : super(key: key);

@override
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;
return BaseView<WeatherInfoViewModel>(

return BaseView<ForecastInfoViewModel>(
onModelReady: (model) => model.getWeatherData(),
builder: (ctx, model, child) => SafeArea(
child : Scaffold(
body: SingleChildScrollView(
Expand All @@ -23,7 +28,61 @@ class WeatherInfoScreen extends StatelessWidget {
child: Column(
crossAxisAlignment :CrossAxisAlignment.start,
children: [
SizedBox(height: 90),
Padding(
padding: const EdgeInsets.fromLTRB(15, 20, 15, 10),
child: Container(
height: height / 15,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(15.0)),
color: const Color.fromRGBO(58, 74, 88, 1),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(
Icons.article,
size: height / 25,
color: Color.fromRGBO(181, 205, 242, 1),
),
Text(
'Patna, India',
style: TextStyle(
color: Colors.white,
fontSize: height / 34,
fontWeight: FontWeight.w400),
),
IconButton(
onPressed: () {
// setState(() {
// TextField(
// decoration: InputDecoration(
// hintText: 'Patna, India',
// hintStyle: TextStyle(
// color: Colors.white,
// fontSize: 18,
// fontStyle: FontStyle.italic,
// ),
// border: InputBorder.none,
// ),
// style: TextStyle(
// color: Colors.white,
// ),
// );
// });
},
icon: Icon(
Icons.search,
size: height / 25,
),
color: Colors.white,
)
],
),
),
),
),
Container(
height: 223,
width: width/1,
Expand All @@ -34,20 +93,20 @@ class WeatherInfoScreen extends StatelessWidget {
Row(
children: [
SizedBox(
width: width/8,
width: width/5,
),
Text(
"29-Dec-2021",
model.date,
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: width/20,
color: Color.fromRGBO(101, 98, 98, 1)),
),
SizedBox(
width: width/4,
width: width/3,
),
Text(
"9:02 PM",
model.time,
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: width/20,
Expand All @@ -71,15 +130,15 @@ class WeatherInfoScreen extends StatelessWidget {
height: 10,
),
Text(
"12 C",
model.temp,
style: TextStyle(
fontSize: width/11.8,
fontSize: width/15,
fontWeight: FontWeight.w400,
color: Color.fromRGBO(0, 0, 0, 1),
),
),
Text(
"Thunderstorm",
model.descri,
style: TextStyle(
fontSize: width/22,
fontWeight: FontWeight.w400,
Expand All @@ -92,7 +151,7 @@ class WeatherInfoScreen extends StatelessWidget {
Row(
children: [
Text(
"19 C",
model.high,
style: TextStyle(
fontSize: width/22,
fontWeight: FontWeight.w400,
Expand All @@ -110,7 +169,7 @@ class WeatherInfoScreen extends StatelessWidget {
Row(
children: [
Text(
"9 C",
model.low,
style: TextStyle(
fontSize: width/22,
fontWeight: FontWeight.w400,
Expand Down Expand Up @@ -152,13 +211,13 @@ class WeatherInfoScreen extends StatelessWidget {
width:width/22,
),
Column(
children: const [
children: [
Text("N W"),
Text("7 kmph"),
Text(model.speed),
SizedBox(
height: 40,
),
Text("81 %"),
Text(model.info),
],
),
],
Expand Down Expand Up @@ -197,33 +256,33 @@ class WeatherInfoScreen extends StatelessWidget {
child: Row(
children: [
SizedBox(
width: width/22,
width: width/10,
),
Column(
children: const [
children: [
SizedBox(
height: 40,
),
Icon(Icons.wb_sunny),
SizedBox(
height: 20,
),
Text("06:31 am"),
Text(model.rise),
],
),
SizedBox(
width: width/2.2,
width: width/1.8,
),
Column(
children: const [
children: [
SizedBox(
height: 40,
),
Icon(Icons.wb_sunny_outlined),
SizedBox(
height: 20,
),
Text("05:03 pm"),
Text(model.set),
],
)
],
Expand Down Expand Up @@ -267,27 +326,27 @@ class WeatherInfoScreen extends StatelessWidget {
SizedBox(
height: 15,
),
Text("AQI",
Text("Cloudliness",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: width/22,
fontSize: width/23,
)),
SizedBox(
height: 15,
),
Text("70 | LOW",
Text(model.cloud,
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: width/29.3,
)),
],
),
SizedBox(
width: width/3,
width: width/7,
),
const Icon(
Icons.wb_cloudy_rounded,
color: Colors.cyanAccent,
Icons.device_hub,
color: Colors.grey,
),
Column(
children: [
Expand All @@ -296,7 +355,7 @@ class WeatherInfoScreen extends StatelessWidget {
fontWeight: FontWeight.w500,
fontSize: width/22,
)),
Text("1015 mbar",
Text(model.pressure,
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: width/22,
Expand All @@ -319,33 +378,33 @@ class WeatherInfoScreen extends StatelessWidget {
SizedBox(
width: width/29.3,
),
Text("Chance of Rain",
Text("Wind Gust",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: width/22,
)),
Text("1 %",
Text(model.wind,
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: width/22,
)),
],
),
SizedBox(
width: width/5,
width: width/5.5,
),
Icon(
Icons.wb_sunny_rounded,
color: Colors.yellow,
Icons.water,
color: Colors.blue,
),
Column(
children: [
Text("UV Index",
Text("Rain Percentage",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: width/22,
)),
Text("1",
Text(model.last,
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize:width/22,
Expand Down
51 changes: 51 additions & 0 deletions lib/views/Forecast_Info_ViewModel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:dotenv/dotenv.dart';
import 'package:flutter/material.dart';
import 'package:weather_alert_app/provider/base_model.dart';
import 'package:weather/weather.dart';


class ForecastInfoViewModel extends BaseModel {
String day = "sunny";
WeatherFactory wf = new WeatherFactory('0fc8d53cab4163347cd518754dc4701d');
String info = "";
String temp = "";
String feel = "";
String maxTemp = "";
String minTemp = "";
String descri = "";
String date = "";
String time = "";
String high ="";
String low ="";
String rise="";
String set="";
String speed="";
String chance="";
String pressure="";
String cloud = "";
String wind = "";
String last = "";
void getWeatherData() async {
Weather w = await wf.currentWeatherByCityName("Kolkata");
speed = w.windSpeed.toString();
rise = w.sunrise.toString().substring(11,16);
set= w.sunset.toString().substring(11,16);
info = w.humidity.toString();
temp = w.temperature.toString();
feel = w.tempFeelsLike.toString();
low = w.tempMin.toString().substring(0,5);
high = w.tempMax.toString().substring(0,5);
descri = w.weatherDescription.toString();
date = w.date.toString().substring(5,10);
time = w.date.toString().substring(11,16);
pressure = w.pressure.toString();
cloud=w.cloudiness.toString();
wind=w.windSpeed!.roundToDouble().toString();
last = w.rainLast3Hours.toString();

//time = w.
// print("====================================" + w.humidity.toString());
// info = "weather";

}
}
Loading