Skip to content

Commit 9da5581

Browse files
committed
Add light theme and icons
1 parent 7916ccb commit 9da5581

File tree

12 files changed

+166
-209
lines changed

12 files changed

+166
-209
lines changed

lib/src/app/app.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import 'package:flutter_weather_bg_null_safety/bg/weather_bg.dart';
55
import 'package:watch_it/watch_it.dart';
66
import 'package:yaru/yaru.dart';
77

8-
import '../../build_context_x.dart';
8+
import '../build_context_x.dart';
99
import '../../constants.dart';
1010
import '../../weather.dart';
1111
import '../weather/view/city_search_field.dart';
12+
import '../weather/weather_data_x.dart';
1213
import '../weather/weather_model.dart';
13-
import '../weather/weather_utils.dart';
1414
import 'app_model.dart';
1515
import 'offline_page.dart';
1616

@@ -22,7 +22,7 @@ class App extends StatelessWidget {
2222
return MaterialApp(
2323
title: 'Weather',
2424
debugShowCheckedModeBanner: false,
25-
themeMode: ThemeMode.dark,
25+
theme: yaruLight,
2626
darkTheme: yaruDark.copyWith(
2727
tabBarTheme: TabBarTheme.of(context).copyWith(
2828
labelColor: Colors.white,
@@ -113,7 +113,7 @@ class _AppPageState extends State<AppPage> {
113113
Opacity(
114114
opacity: 0.6,
115115
child: WeatherBg(
116-
weatherType: getWeatherType(data),
116+
weatherType: data.weatherType,
117117
width: mq.size.width,
118118
height: mq.size.height,
119119
),

lib/src/app/offline_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:yaru/yaru.dart';
33

4-
import '../../build_context_x.dart';
4+
import '../build_context_x.dart';
55

66
class OfflinePage extends StatelessWidget {
77
const OfflinePage({super.key});

lib/src/weather/theme_x.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'package:flutter/material.dart';
2+
3+
extension ThemeX on ThemeData {
4+
bool get light => brightness == Brightness.light;
5+
6+
TextStyle? get weatherBgTextStyle => textTheme.headlineSmall?.copyWith(
7+
color: Colors.white,
8+
fontSize: 20,
9+
shadows: [
10+
Shadow(
11+
color: Colors.black.withOpacity(light ? 1 : 0.8),
12+
offset: const Offset(0, 0),
13+
blurRadius: light ? 2 : 3,
14+
),
15+
],
16+
);
17+
}

lib/src/weather/view/city_search_field.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:watch_it/watch_it.dart';
33
import 'package:yaru/yaru.dart';
44

5-
import '../../../build_context_x.dart';
5+
import '../../build_context_x.dart';
66
import '../weather_model.dart';
77

88
class CitySearchField extends StatefulWidget {

lib/src/weather/view/forecast_chart.dart

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import 'package:collection/collection.dart';
22
import 'package:fl_chart/fl_chart.dart';
3+
import 'package:flutter/cupertino.dart';
34
import 'package:flutter/material.dart';
5+
import 'package:flutter/widgets.dart';
46
import 'package:open_weather_client/models/weather_data.dart';
57
import 'package:yaru/yaru.dart';
68

7-
import '../../../build_context_x.dart';
9+
import '../../build_context_x.dart';
810
import '../../../constants.dart';
911
import '../weather_data_x.dart';
1012

@@ -29,6 +31,7 @@ class ForeCastChart extends StatelessWidget {
2931
padding: const EdgeInsets.symmetric(vertical: kYaruPagePadding),
3032
child: BarChart(
3133
BarChartData(
34+
baselineY: 0,
3235
titlesData: getTitlesData(context),
3336
borderData: borderData,
3437
barGroups: barGroups,
@@ -56,9 +59,9 @@ class ForeCastChart extends StatelessWidget {
5659
'${data[value.toInt()].temperature.tempMin.toInt()} °',
5760
style: TextStyle(
5861
fontWeight: FontWeight.bold,
59-
color: data[value.toInt()].temperature.tempMin < 5
60-
? YaruColors.purple
61-
: YaruColors.blue,
62+
color: data[value.toInt()]
63+
.minColor
64+
.scale(lightness: context.light ? -0.6 : 0.4),
6265
),
6366
),
6467
);
@@ -71,34 +74,49 @@ class ForeCastChart extends StatelessWidget {
7174
topTitles: AxisTitles(
7275
sideTitles: SideTitles(
7376
showTitles: true,
74-
reservedSize: 110,
77+
reservedSize: 150,
7578
getTitlesWidget: (value, meta) {
7679
return SideTitleWidget(
7780
axisSide: meta.axisSide,
7881
child: Column(
7982
children: [
80-
Expanded(
83+
Flexible(
8184
child: Text(
8285
data[value.toInt()].getWeekDay(context),
8386
style: const TextStyle(
8487
fontWeight: FontWeight.bold,
8588
),
8689
),
8790
),
91+
Flexible(
92+
child: Text(
93+
data[value.toInt()].getDate(context),
94+
style: const TextStyle(
95+
fontWeight: FontWeight.bold,
96+
),
97+
),
98+
),
99+
const SizedBox(
100+
height: 5,
101+
),
102+
Icon(data[value.toInt()].icon),
88103
const SizedBox(
89-
height: 50,
104+
height: 40,
90105
),
91-
Expanded(
106+
Flexible(
92107
child: Text(
93108
'${data[value.toInt()].temperature.tempMax.toInt()} °',
94109
style: TextStyle(
95110
fontWeight: FontWeight.bold,
96-
color: data[value.toInt()].temperature.tempMax > 30
97-
? YaruColors.orange
98-
: Colors.yellow,
111+
color: data[value.toInt()]
112+
.maxColor
113+
.scale(lightness: context.light ? -0.6 : 0.4),
99114
),
100115
),
101116
),
117+
const SizedBox(
118+
height: 10,
119+
),
102120
],
103121
),
104122
);
@@ -114,10 +132,11 @@ class ForeCastChart extends StatelessWidget {
114132
show: false,
115133
);
116134

117-
LinearGradient getBarGradient({required min, required max}) => LinearGradient(
135+
LinearGradient getBarGradient({required Color minColor, required maxColor}) =>
136+
LinearGradient(
118137
colors: [
119-
max > 30 ? YaruColors.orange : Colors.yellow,
120-
min < -5 ? YaruColors.purple : YaruColors.blue,
138+
maxColor,
139+
minColor,
121140
],
122141
begin: Alignment.topCenter,
123142
end: Alignment.bottomCenter,
@@ -133,8 +152,8 @@ class ForeCastChart extends StatelessWidget {
133152
toY: data[i].temperature.tempMax,
134153
fromY: data[i].temperature.tempMin + 1,
135154
gradient: getBarGradient(
136-
max: data[i].temperature.tempMax,
137-
min: data[i].temperature.tempMin,
155+
maxColor: data[i].maxColor,
156+
minColor: data[i].minColor,
138157
),
139158
),
140159
],

lib/src/weather/view/forecast_tile.dart

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import 'package:flutter_weather_bg_null_safety/flutter_weather_bg.dart';
44
import 'package:open_weather_client/models/weather_data.dart';
55
import 'package:yaru/constants.dart';
66

7-
import '../../../build_context_x.dart';
7+
import '../../build_context_x.dart';
88
import '../../../string_x.dart';
9+
import '../theme_x.dart';
910
import '../weather_data_x.dart';
10-
import '../weather_utils.dart';
1111

1212
class ForecastTile extends StatefulWidget {
13-
final WeatherData selectedData;
13+
final WeatherData data;
1414
final String? cityName;
1515
final double fontSize;
1616
final String? position;
@@ -23,7 +23,7 @@ class ForecastTile extends StatefulWidget {
2323

2424
const ForecastTile({
2525
super.key,
26-
required this.selectedData,
26+
required this.data,
2727
this.cityName,
2828
this.fontSize = 20,
2929
this.position,
@@ -44,32 +44,22 @@ class _ForecastTileState extends State<ForecastTile> {
4444
@override
4545
Widget build(BuildContext context) {
4646
final theme = context.theme;
47-
final style = theme.textTheme.headlineSmall?.copyWith(
48-
color: Colors.white,
49-
fontSize: 20,
50-
shadows: [
51-
Shadow(
52-
color: Colors.black.withOpacity(0.8),
53-
offset: const Offset(0, 1),
54-
blurRadius: 3,
55-
),
56-
],
57-
);
47+
final style = theme.weatherBgTextStyle;
5848

5949
final children = [
6050
Column(
6151
mainAxisSize: MainAxisSize.min,
6252
children: [
6353
Text(
64-
widget.selectedData.currentTemperature,
54+
widget.data.currentTemperature,
6555
style: style,
6656
),
6757
Text(
68-
'Feels like: ${widget.selectedData.feelsLike}',
58+
'Feels like: ${widget.data.feelsLike}',
6959
style: style,
7060
),
7161
Text(
72-
'Wind: ${widget.selectedData.windSpeed}',
62+
'Wind: ${widget.data.windSpeed}',
7363
style: style,
7464
),
7565
],
@@ -92,12 +82,16 @@ class _ForecastTileState extends State<ForecastTile> {
9282
Row(
9383
mainAxisSize: MainAxisSize.min,
9484
children: [
95-
getIcon(widget.selectedData, theme.colorScheme),
85+
Icon(
86+
widget.data.icon,
87+
color: style?.color,
88+
shadows: style?.shadows,
89+
),
9690
const SizedBox(
9791
width: 10,
9892
),
9993
Text(
100-
widget.selectedData.longDescription.capitalize(),
94+
widget.data.longDescription.capitalize(),
10195
textAlign: TextAlign.center,
10296
style: style,
10397
overflow: TextOverflow.ellipsis,
@@ -124,7 +118,7 @@ class _ForecastTileState extends State<ForecastTile> {
124118
child: ClipRRect(
125119
borderRadius: widget.borderRadius,
126120
child: WeatherBg(
127-
weatherType: getWeatherType(widget.selectedData),
121+
weatherType: widget.data.weatherType,
128122
width: widget.width ?? double.infinity,
129123
height: widget.height ?? double.infinity,
130124
),

lib/src/weather/view/today_tile.dart

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import 'package:flutter/material.dart';
22
import 'package:open_weather_client/models/weather_data.dart';
33
import 'package:yaru/constants.dart';
4-
import '../../../build_context_x.dart';
5-
import '../weather_utils.dart';
4+
5+
import '../../build_context_x.dart';
66
import '../../../string_x.dart';
7+
import '../theme_x.dart';
78
import '../weather_data_x.dart';
89

910
class TodayTile extends StatelessWidget {
@@ -35,17 +36,8 @@ class TodayTile extends StatelessWidget {
3536
@override
3637
Widget build(BuildContext context) {
3738
final theme = context.theme;
38-
final style = theme.textTheme.headlineSmall?.copyWith(
39-
color: Colors.white,
40-
fontSize: 20,
41-
shadows: [
42-
Shadow(
43-
color: Colors.black.withOpacity(0.5),
44-
offset: const Offset(0, 1),
45-
blurRadius: 3,
46-
),
47-
],
48-
);
39+
40+
final style = theme.weatherBgTextStyle;
4941

5042
final children = [
5143
Column(
@@ -83,7 +75,11 @@ class TodayTile extends StatelessWidget {
8375
Row(
8476
mainAxisSize: MainAxisSize.min,
8577
children: [
86-
getIcon(data, theme.colorScheme),
78+
Icon(
79+
data.icon,
80+
color: style?.color,
81+
shadows: style?.shadows,
82+
),
8783
const SizedBox(
8884
width: 10,
8985
),

0 commit comments

Comments
 (0)