1
+ // ignore_for_file: unused_element
2
+
1
3
import 'package:example/modules/location_view_widget.dart' ;
2
4
import 'package:example/modules/weather_summary_widget.dart' ;
3
5
import 'package:flutter/material.dart' ;
4
6
import 'package:open_weather_client/open_weather.dart' ;
5
7
8
+ /// A screen that demonstrates the use of prebuilt functions from the OpenWeather package.
6
9
class PrebuiltFunctionScreen extends StatefulWidget {
10
+ /// Creates a [PrebuiltFunctionScreen] .
7
11
const PrebuiltFunctionScreen ({super .key});
8
12
9
13
@override
@@ -33,49 +37,55 @@ class _PrebuiltFunctionScreenState extends State<PrebuiltFunctionScreen> {
33
37
// });
34
38
}
35
39
36
- // ignore: unused_element
40
+ /// Fetches the current weather data by city name.
41
+ ///
42
+ /// Returns a [WeatherData] object containing the current weather information.
37
43
Future <WeatherData > _getCurrentweatherByCity () async {
38
- return openWeather.currentWeatherByCityName (
39
- cityName: _cityName, weatherUnits: WeatherUnits .METRIC );
44
+ return openWeather.currentWeatherByCityName (cityName: _cityName, weatherUnits: WeatherUnits .METRIC );
40
45
}
41
46
42
- // ignore: unused_element
47
+ /// Fetches the current weather data by geographic location.
48
+ ///
49
+ /// Returns a [WeatherData] object containing the current weather information.
43
50
Future <WeatherData > _getCurrentweatherByLocation () async {
44
51
return openWeather.currentWeatherByLocation (
45
- latitude: _latitude,
46
- longitude: _longitude,
47
- weatherUnits: WeatherUnits .METRIC );
52
+ latitude: _latitude, longitude: _longitude, weatherUnits: WeatherUnits .METRIC );
48
53
}
49
54
55
+ /// Fetches the current weather data by zip code.
56
+ ///
57
+ /// Returns a [WeatherData] object containing the current weather information.
50
58
Future <WeatherData > _getCurrentweatherByZipCode () async {
51
59
return openWeather.currentWeatherByZipCode (
52
- zipCode: _zipCode,
53
- countryCode: _countryCode,
54
- weatherUnits: WeatherUnits .METRIC );
60
+ zipCode: _zipCode, countryCode: _countryCode, weatherUnits: WeatherUnits .METRIC );
55
61
}
56
62
57
- // ignore: unused_element
63
+ /// Fetches the five-day weather forecast by city name.
64
+ ///
65
+ /// Returns a [WeatherForecastData] object containing the weather forecast information.
58
66
Future <WeatherForecastData > _getFiveDaysForecastByCityName () async {
59
- return openWeather.fiveDaysWeatherForecastByCityName (
60
- cityName: _cityName, weatherUnits: WeatherUnits .METRIC );
67
+ return openWeather.fiveDaysWeatherForecastByCityName (cityName: _cityName, weatherUnits: WeatherUnits .METRIC );
61
68
}
62
69
63
- // ignore: unused_element
70
+ /// Fetches the five-day weather forecast by geographic location.
71
+ ///
72
+ /// Returns a [WeatherForecastData] object containing the weather forecast information.
64
73
Future <WeatherForecastData > _getFiveDaysForecastByLocation () async {
65
74
return openWeather.fiveDaysWeatherForecastByLocation (
66
- latitude: _latitude,
67
- longitude: _longitude,
68
- weatherUnits: WeatherUnits .METRIC );
75
+ latitude: _latitude, longitude: _longitude, weatherUnits: WeatherUnits .METRIC );
69
76
}
70
77
71
- // ignore: unused_element
78
+ /// Fetches the five-day weather forecast by zip code.
79
+ ///
80
+ /// Returns a [WeatherForecastData] object containing the weather forecast information.
72
81
Future <WeatherForecastData > _getFiveDaysForecastByZipCode () async {
73
82
return openWeather.fiveDaysWeatherForecastByZipCode (
74
- zipCode: _zipCode,
75
- countryCode: _countryCode,
76
- weatherUnits: WeatherUnits .METRIC );
83
+ zipCode: _zipCode, countryCode: _countryCode, weatherUnits: WeatherUnits .METRIC );
77
84
}
78
85
86
+ /// Builds a button that navigates back to the previous screen.
87
+ ///
88
+ /// Returns an [ElevatedButton] widget.
79
89
Widget _buildButton () {
80
90
return ElevatedButton (
81
91
child: const Text ('Check with prebuilt widgets' ),
@@ -93,9 +103,7 @@ class _PrebuiltFunctionScreenState extends State<PrebuiltFunctionScreen> {
93
103
backgroundColor: Colors .white,
94
104
elevation: 0 ,
95
105
title: const Text ('OpenWeather prebuilt functions' ,
96
- style: TextStyle (color: Colors .black),
97
- maxLines: 2 ,
98
- textAlign: TextAlign .center),
106
+ style: TextStyle (color: Colors .black), maxLines: 2 , textAlign: TextAlign .center),
99
107
),
100
108
body: Container (
101
109
width: double .infinity,
@@ -113,19 +121,12 @@ class _PrebuiltFunctionScreenState extends State<PrebuiltFunctionScreen> {
113
121
),
114
122
WeatherSummary (
115
123
color: Colors .black,
116
- imageUrl:
117
- 'https://openweathermap.org/img/wn/${snapshot .data !.details .first .icon }@2x.png' ,
118
- currentTemperature: snapshot
119
- .data! .temperature.currentTemperature
120
- .toString (),
121
- maxTemperature:
122
- snapshot.data! .temperature.tempMax.toString (),
123
- minTemperature:
124
- snapshot.data! .temperature.tempMin.toString (),
125
- humidity:
126
- snapshot.data! .temperature.humidity.toString (),
127
- pressure:
128
- snapshot.data! .temperature.pressure.toString (),
124
+ imageUrl: 'https://openweathermap.org/img/wn/${snapshot .data !.details .first .icon }@2x.png' ,
125
+ currentTemperature: snapshot.data! .temperature.currentTemperature.toString (),
126
+ maxTemperature: snapshot.data! .temperature.tempMax.toString (),
127
+ minTemperature: snapshot.data! .temperature.tempMin.toString (),
128
+ humidity: snapshot.data! .temperature.humidity.toString (),
129
+ pressure: snapshot.data! .temperature.pressure.toString (),
129
130
),
130
131
_buildButton ()
131
132
],
0 commit comments