Skip to content

Commit

Permalink
Display day in today chart (#11)
Browse files Browse the repository at this point in the history
* Display day in today chart

* Better names
  • Loading branch information
Feichtmeier authored Apr 28, 2024
1 parent 544621c commit d45f96f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 37 deletions.
3 changes: 2 additions & 1 deletion lib/src/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"enterValidApiKey": "Bitte gib einen (gültigen) API Schlüssel ein",
"hourly": "Stündlich",
"daily": "Täglich",
"now": "Jetzt"
"now": "Jetzt",
"today": "Heute"
}
3 changes: 2 additions & 1 deletion lib/src/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"enterValidApiKey": "Please enter a (valid) API key",
"hourly": "Hourly",
"daily": "Daily",
"now": "Now"
"now": "Now",
"today": "Today"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import '../weather_data_x.dart';
import '../weather_model.dart';
import 'error_view.dart';

class ForeCastChart extends StatelessWidget with WatchItMixin {
const ForeCastChart({super.key});
class DailyBarChart extends StatelessWidget with WatchItMixin {
const DailyBarChart({super.key});

@override
Widget build(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import 'package:yaru/yaru.dart';

import '../../../constants.dart';
import '../../build_context_x.dart';
import '../../l10n/l10n.dart';
import '../weather_data_x.dart';
import '../weather_model.dart';
import 'error_view.dart';
import 'today_tile.dart';
import 'now_tile.dart';

class TodayChart extends StatefulWidget with WatchItStatefulWidgetMixin {
const TodayChart({super.key});
class HourlyLineChart extends StatefulWidget with WatchItStatefulWidgetMixin {
const HourlyLineChart({super.key});

@override
State<TodayChart> createState() => _TodayChartState();
State<HourlyLineChart> createState() => _HourlyLineChartState();
}

class _TodayChartState extends State<TodayChart> {
class _HourlyLineChartState extends State<HourlyLineChart> {
late ScrollController _scrollController;

List<Color> gradientColors = [
Expand All @@ -42,7 +43,7 @@ class _TodayChartState extends State<TodayChart> {
@override
Widget build(BuildContext context) {
final forecast =
watchPropertyValue((WeatherModel m) => m.notTodayFullForecast);
watchPropertyValue((WeatherModel m) => m.fiveDaysForCast ?? []);
final mq = context.mq;

final cityName = watchPropertyValue((WeatherModel m) => m.lastLocation);
Expand Down Expand Up @@ -76,7 +77,7 @@ class _TodayChartState extends State<TodayChart> {
width: forecast.length * 100,
height: 400,
child: LineChart(
mainData(forecast),
mainData(forecast: forecast, data: data),
),
),
),
Expand Down Expand Up @@ -114,7 +115,7 @@ class _TodayChartState extends State<TodayChart> {
),
),
if (data != null)
TodayTile(
NowTile(
data: data,
fontSize: 20,
cityName: cityName,
Expand All @@ -123,29 +124,41 @@ class _TodayChartState extends State<TodayChart> {
);
}

Widget bottomTitleWidgets(
double value,
TitleMeta meta,
List<WeatherData> data,
) {
const style = TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
);
Widget text;
text = Text(
data[value.toInt()].getTime(context),
style: style,
);

Widget bottomTitleWidgets({
required double value,
required TitleMeta meta,
required List<WeatherData> forecast,
required WeatherData data,
}) {
final weekday = forecast[value.toInt()].getWeekDay(context);
return SideTitleWidget(
fitInside: SideTitleFitInsideData.fromTitleMeta(meta),
axisSide: meta.axisSide,
child: text,
child: Column(
children: [
Text(
forecast[value.toInt()].getTime(context),
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
Text(
weekday == data.getWeekDay(context) ? context.l10n.today : weekday,
style: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 10,
),
),
],
),
);
}

LineChartData mainData(List<WeatherData> forecast) {
LineChartData mainData({
required List<WeatherData> forecast,
required WeatherData data,
}) {
final outlineColor = context.theme.colorScheme.onSurface.withOpacity(0.2);

return LineChartData(
Expand Down Expand Up @@ -181,10 +194,14 @@ class _TodayChartState extends State<TodayChart> {
bottomTitles: AxisTitles(
sideTitles: SideTitles(
showTitles: true,
reservedSize: 35,
reservedSize: 55,
interval: 1,
getTitlesWidget: (value, meta) =>
bottomTitleWidgets(value, meta, forecast),
getTitlesWidget: (value, meta) => bottomTitleWidgets(
value: value,
meta: meta,
forecast: forecast,
data: data,
),
),
),
leftTitles: const AxisTitles(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import '../../l10n/l10n.dart';
import '../theme_x.dart';
import '../weather_data_x.dart';

class TodayTile extends StatelessWidget {
class NowTile extends StatelessWidget {
final WeatherData data;
final String? cityName;
final double fontSize;
final String? position;
final String? time;
final BorderRadiusGeometry? borderRadius;

const TodayTile({
const NowTile({
super.key,
required this.data,
this.cityName,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/weather/view/weather_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import '../../../constants.dart';
import '../../app/app_model.dart';
import '../../app/side_bar.dart';
import '../../l10n/l10n.dart';
import 'forecast_chart.dart';
import 'today_chart.dart';
import 'daily_bar_chart.dart';
import 'hourly_line_chart.dart';

class WeatherPage extends StatelessWidget with WatchItMixin {
const WeatherPage({super.key, this.showDrawer = false});
Expand Down Expand Up @@ -59,7 +59,7 @@ class WeatherPage extends StatelessWidget with WatchItMixin {
),
),
),
body: showToday ? const TodayChart() : const ForeCastChart(),
body: showToday ? const HourlyLineChart() : const DailyBarChart(),
),
);
}
Expand Down

0 comments on commit d45f96f

Please sign in to comment.