diff --git a/lib/main.dart b/lib/main.dart index 4a7e682..a04967d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -19,7 +19,7 @@ class MyApp extends StatelessWidget { return MaterialApp( navigatorKey: getIt().navigatorKey, title: 'Weather Alert Flutter', - initialRoute: '/forecast', + initialRoute: '/weatherinfo', onGenerateRoute: RouteGenerator.generateRoute, debugShowCheckedModeBanner: false, theme: ThemeData( diff --git a/lib/provider/getit.dart b/lib/provider/getit.dart index 144aee6..61d4e75 100644 --- a/lib/provider/getit.dart +++ b/lib/provider/getit.dart @@ -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()); } diff --git a/lib/route_generator.dart b/lib/route_generator.dart index 88afd36..dc6a43d 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -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 { diff --git a/lib/src/screens/weather_info_screen.dart b/lib/src/screens/weather_info_screen.dart index 0266bcc..a4f9594 100644 --- a/lib/src/screens/weather_info_screen.dart +++ b/lib/src/screens/weather_info_screen.dart @@ -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( + + return BaseView( + onModelReady: (model) => model.getWeatherData(), builder: (ctx, model, child) => SafeArea( child : Scaffold( body: SingleChildScrollView( @@ -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, @@ -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, @@ -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, @@ -92,7 +151,7 @@ class WeatherInfoScreen extends StatelessWidget { Row( children: [ Text( - "19 C", + model.high, style: TextStyle( fontSize: width/22, fontWeight: FontWeight.w400, @@ -110,7 +169,7 @@ class WeatherInfoScreen extends StatelessWidget { Row( children: [ Text( - "9 C", + model.low, style: TextStyle( fontSize: width/22, fontWeight: FontWeight.w400, @@ -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), ], ), ], @@ -197,10 +256,10 @@ class WeatherInfoScreen extends StatelessWidget { child: Row( children: [ SizedBox( - width: width/22, + width: width/10, ), Column( - children: const [ + children: [ SizedBox( height: 40, ), @@ -208,14 +267,14 @@ class WeatherInfoScreen extends StatelessWidget { 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, ), @@ -223,7 +282,7 @@ class WeatherInfoScreen extends StatelessWidget { SizedBox( height: 20, ), - Text("05:03 pm"), + Text(model.set), ], ) ], @@ -267,15 +326,15 @@ 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, @@ -283,11 +342,11 @@ class WeatherInfoScreen extends StatelessWidget { ], ), SizedBox( - width: width/3, + width: width/7, ), const Icon( - Icons.wb_cloudy_rounded, - color: Colors.cyanAccent, + Icons.device_hub, + color: Colors.grey, ), Column( children: [ @@ -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, @@ -319,12 +378,12 @@ 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, @@ -332,20 +391,20 @@ class WeatherInfoScreen extends StatelessWidget { ], ), 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, diff --git a/lib/views/Forecast_Info_ViewModel.dart b/lib/views/Forecast_Info_ViewModel.dart new file mode 100644 index 0000000..ed146dd --- /dev/null +++ b/lib/views/Forecast_Info_ViewModel.dart @@ -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"; + + } +} diff --git a/lib/views/weatherinfo_viewmodel.dart b/lib/views/weatherinfo_viewmodel.dart index f0f95dc..7c7be2f 100644 --- a/lib/views/weatherinfo_viewmodel.dart +++ b/lib/views/weatherinfo_viewmodel.dart @@ -3,58 +3,92 @@ import 'package:flutter/material.dart'; import 'package:weather_alert_app/provider/base_model.dart'; import 'package:weather/weather.dart'; - class WeatherInfoViewModel 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 = ""; - WeatherFactory wf = new WeatherFactory('b3a39ca14fda797db47b1a9e5f2a84d2'); - //Day-0 - String dateP0 = ""; - String maxTemp0 = ""; - String minTemp0 = ""; - // Day-0 - String dateP1 = ""; - String maxTemp1 = ""; - String minTemp1 = ""; + //Day-0 + String dateP0 = ""; + String maxTemp0 = ""; + String minTemp0 = ""; + + // Day-0 + String dateP1 = ""; + String maxTemp1 = ""; + String minTemp1 = ""; + + //Day-0 + String dateP2 = ""; + String maxTemp2 = ""; + String minTemp2 = ""; + + //Day-0 + String dateP3 = ""; + String maxTemp3 = ""; + String minTemp3 = ""; + String desc = ""; + + 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(); + List forecast = await wf.fiveDayForecastByCityName("Patna"); //Day-0 - String dateP2 = ""; - String maxTemp2 = ""; - String minTemp2 = ""; + maxTemp0 = forecast[0].tempMax.toString().substring(0,6); + minTemp0 = forecast[0].tempMin.toString().substring(0,6); + dateP0 = forecast[0].date.toString().substring(5,10); //Day-0 - String dateP3 = ""; - String maxTemp3 = ""; - String minTemp3 = ""; - - - - String temp = ""; - String desc = ""; - String date = ""; - - void getWeatherData() async { - List forecast = await wf.fiveDayForecastByCityName("Patna"); - //Day-0 - maxTemp0 = forecast[0].tempMax.toString().substring(0,6); - minTemp0 = forecast[0].tempMin.toString().substring(0,6); - dateP0 = forecast[0].date.toString().substring(5,10); - //Day-0 - maxTemp1 = forecast[1].tempMax.toString().substring(0,6); - minTemp1 = forecast[1].tempMin.toString().substring(0,6); - dateP1 = forecast[1].date.toString().substring(5,10); - // //Day-0 - maxTemp2 = forecast[2].tempMax.toString().substring(0,6); - minTemp2 = forecast[2].tempMin.toString().substring(0,6); - dateP2 = forecast[2].date.toString().substring(5,10); - // //Day-0 - maxTemp3 = forecast[3].tempMax.toString().substring(0,6); - minTemp3 = forecast[3].tempMin.toString().substring(0,6); - dateP3 = forecast[3].date.toString().substring(5,10); - - temp = forecast[0].temperature.toString().substring(0,6); - desc = forecast[0].weatherDescription.toString(); - - print("====================================" + maxTemp0); - print("====================================" + dateP0); - print("====================================" + minTemp0); - print("====================================" + desc); - } -} + maxTemp1 = forecast[1].tempMax.toString().substring(0,6); + minTemp1 = forecast[1].tempMin.toString().substring(0,6); + dateP1 = forecast[1].date.toString().substring(5,10); + // //Day-0 + maxTemp2 = forecast[2].tempMax.toString().substring(0,6); + minTemp2 = forecast[2].tempMin.toString().substring(0,6); + dateP2 = forecast[2].date.toString().substring(5,10); + // //Day-0 + maxTemp3 = forecast[3].tempMax.toString().substring(0,6); + minTemp3 = forecast[3].tempMin.toString().substring(0,6); + dateP3 = forecast[3].date.toString().substring(5,10); + + temp = forecast[0].temperature.toString().substring(0,6); + desc = forecast[0].weatherDescription.toString(); + + //time = w. + // print("====================================" + w.humidity.toString()); + // info = "weather"; + + + } + +} \ No newline at end of file