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

Dry refactored code in desc module #146

Merged
merged 1 commit into from
Oct 30, 2023
Merged
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
7 changes: 4 additions & 3 deletions lib/app/widgets/desc/desc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class DescWeather extends StatefulWidget {

class _DescWeatherState extends State<DescWeather> {
bool hide = true;

@override
Widget build(BuildContext context) {
final textTheme = context.textTheme;
return GestureDetector(
onTap: () => setState(() => hide = !hide),
child: Tooltip(
Expand All @@ -40,12 +41,12 @@ class _DescWeatherState extends State<DescWeather> {
const SizedBox(height: 5),
Text(
widget.value,
style: context.textTheme.labelLarge,
style: textTheme.labelLarge,
),
Expanded(
child: Text(
widget.desc,
style: context.textTheme.bodySmall,
style: textTheme.bodySmall,
overflow: hide ? TextOverflow.ellipsis : TextOverflow.visible,
textAlign: TextAlign.center,
),
Expand Down
83 changes: 49 additions & 34 deletions lib/app/widgets/desc/desc_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ class _DescContainerState extends State<DescContainer> {

@override
Widget build(BuildContext context) {
final dewpoint2M = widget.dewpoint2M?.round();
final feels = widget.feels;
final visibility = widget.visibility;
final direction = widget.direction;
final wind = widget.wind;
final windgusts = widget.windgusts;
final evaporation = widget.evaporation;
final precipitation = widget.precipitation;
final rain = widget.rain;
final precipitationProbability = widget.precipitationProbability;
final humidity = widget.humidity;
final cloudcover = widget.cloudcover;
final pressure = widget.pressure;
final uvIndex = widget.uvIndex;
final shortwaveRadiation = widget.shortwaveRadiation;

return Card(
margin: const EdgeInsets.only(bottom: 15),
child: Padding(
Expand All @@ -57,113 +73,112 @@ class _DescContainerState extends State<DescContainer> {
alignment: WrapAlignment.spaceEvenly,
spacing: 5,
children: [
widget.dewpoint2M == null
dewpoint2M == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/dew.png',
value: statusData.getDegree(widget.dewpoint2M?.round()),
value: statusData.getDegree(dewpoint2M.round()),
desc: 'dewpoint'.tr,
),
widget.feels == null
feels == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/temperature.png',
value: statusData.getDegree(widget.feels?.round()),
value: statusData.getDegree(feels.round()),
desc: 'feels'.tr,
),
widget.visibility == null
visibility == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/fog.png',
value: statusData.getVisibility(widget.visibility),
value: statusData.getVisibility(visibility),
desc: 'visibility'.tr,
),
widget.direction == null
direction == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/windsock.png',
value: '${widget.direction}°',
value: '$direction°',
desc: 'direction'.tr,
message: message.getDirection(widget.direction),
message: message.getDirection(direction),
),
widget.wind == null
wind == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/wind.png',
value: statusData.getSpeed(widget.wind?.round()),
value: statusData.getSpeed(wind.round()),
desc: 'wind'.tr,
),
widget.windgusts == null
windgusts == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/windgusts.png',
value: statusData.getSpeed(widget.windgusts?.round()),
value: statusData.getSpeed(windgusts.round()),
desc: 'windgusts'.tr,
),
widget.evaporation == null
evaporation == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/evaporation.png',
value:
statusData.getPrecipitation(widget.evaporation?.abs()),
value: statusData.getPrecipitation(evaporation.abs()),
desc: 'evaporation'.tr,
),
widget.precipitation == null
precipitation == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/rainfall.png',
value: statusData.getPrecipitation(widget.precipitation),
value: statusData.getPrecipitation(precipitation),
desc: 'precipitation'.tr,
),
widget.rain == null
rain == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/water.png',
value: statusData.getPrecipitation(widget.rain),
value: statusData.getPrecipitation(rain),
desc: 'rain'.tr,
),
widget.precipitationProbability == null
precipitationProbability == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/precipitation_probability.png',
value: '${widget.precipitationProbability}%',
value: '$precipitationProbability%',
desc: 'precipitationProbability'.tr,
),
widget.humidity == null
humidity == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/humidity.png',
value: '${widget.humidity}%',
value: '$humidity%',
desc: 'humidity'.tr,
),
widget.cloudcover == null
cloudcover == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/cloudy.png',
value: '${widget.cloudcover}%',
value: '$cloudcover%',
desc: 'cloudcover'.tr,
),
widget.pressure == null
pressure == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/atmospheric.png',
value: '${widget.pressure?.round()} ${'hPa'.tr}',
value: '${pressure.round()} ${'hPa'.tr}',
desc: 'pressure'.tr,
message: message.getPressure(widget.pressure?.round()),
message: message.getPressure(pressure.round()),
),
widget.uvIndex == null
uvIndex == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/uv.png',
value: '${widget.uvIndex?.round()}',
value: '${uvIndex.round()}',
desc: 'uvIndex'.tr,
message: message.getUvIndex(widget.uvIndex?.round()),
message: message.getUvIndex(uvIndex.round()),
),
widget.shortwaveRadiation == null
shortwaveRadiation == null
? const Offstage()
: DescWeather(
imageName: 'assets/images/shortwave_radiation.png',
value: '${widget.shortwaveRadiation?.round()} ${'W/m2'.tr}',
value: '${shortwaveRadiation.round()} ${'W/m2'.tr}',
desc: 'shortwaveRadiation'.tr,
),
],
Expand Down