Commit 13bc4e8
Changed files (4)
lib
lib/components/display_interval_picker.dart
@@ -1,5 +1,7 @@
import 'package:blood_pressure_app/model/settings_store.dart';
import 'package:flutter/material.dart';
+import 'package:flutter_gen/gen_l10n/app_localizations.dart';
+import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
class IntervalPicker extends StatelessWidget {
@@ -8,47 +10,73 @@ class IntervalPicker extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Consumer<Settings>(builder: (context, settings, child) {
- return Row(children: [
- Expanded(
- flex: 30,
- child: MaterialButton(
- onPressed: () {
- settings.moveDisplayDataByStep(-1);
- },
- child: const Icon(
- Icons.chevron_left,
- size: 48,
- ),
- ),
- ),
- Expanded(
- flex: 40,
- child: DropdownButton<int>(
- value: settings.graphStepSize,
- isExpanded: true,
- onChanged: (int? value) {
- if (value != null) {
- settings.changeStepSize(value);
- }
- },
- items: TimeStep.options.map<DropdownMenuItem<int>>((v) {
- return DropdownMenuItem(value: v, child: Text(TimeStep.getName(v, context)));
- }).toList(),
+ return Column(
+ children: [
+ Consumer<Settings>(builder: (context, settings, child) {
+ switch (settings.graphStepSize) {
+ case TimeStep.day:
+ return Text(DateFormat.yMMMd(AppLocalizations.of(context)!.localeName).format(settings.displayDataStart));
+ case TimeStep.week:
+ final dayOfYear = int.parse(DateFormat("D").format(settings.displayDataStart));
+ final weekOfYear = ((dayOfYear - settings.displayDataStart.weekday + 10) / 7).floor();
+ return Text(AppLocalizations.of(context)!.weekOfYear(weekOfYear, settings.displayDataStart.year));
+ case TimeStep.month:
+ return Text(DateFormat.yMMM(AppLocalizations.of(context)!.localeName).format(settings.displayDataStart));
+ case TimeStep.year:
+ return Text(DateFormat.y(AppLocalizations.of(context)!.localeName).format(settings.displayDataStart));
+ case TimeStep.lifetime:
+ return const Text('-');
+ default:
+ assert(false);
+ return const Text('-');
+ }
+ }),
+ const SizedBox(
+ height: 2,
),
- ),
- Expanded(
- flex: 30,
- child: MaterialButton(
- onPressed: () {
- settings.moveDisplayDataByStep(1);
- },
- child: const Icon(
- Icons.chevron_right,
- size: 48,
+ Row(children: [
+ Expanded(
+ flex: 30,
+ child: MaterialButton(
+ onPressed: () {
+ settings.moveDisplayDataByStep(-1);
+ },
+ child: const Icon(
+ Icons.chevron_left,
+ size: 48,
+ ),
+ ),
),
- ),
- ),
- ]);
+ Expanded(
+ flex: 40,
+ child: DropdownButton<int>(
+ value: settings.graphStepSize,
+ isExpanded: true,
+ onChanged: (int? value) {
+ if (value != null) {
+ settings.changeStepSize(value);
+ }
+ },
+ items: TimeStep.options.map<DropdownMenuItem<int>>((v) {
+ return DropdownMenuItem(value: v, child: Text(TimeStep.getName(v, context)));
+ }).toList(),
+ ),
+ ),
+ Expanded(
+ flex: 30,
+ child: MaterialButton(
+ onPressed: () {
+ settings.moveDisplayDataByStep(1);
+ },
+ child: const Icon(
+ Icons.chevron_right,
+ size: 48,
+ ),
+ ),
+ ),
+ ]),
+ ],
+ );
});
}
}
lib/components/measurement_graph.dart
@@ -197,23 +197,6 @@ class MeasurementGraph extends StatelessWidget {
const SizedBox(
height: 2,
),
- Consumer<Settings>(builder: (context, settings, child) {
- final formatter = DateFormat(settings.dateFormatString);
- return Row(
- children: [
- (settings.graphStepSize == TimeStep.lifetime)
- ? const Text('-')
- : Text(formatter.format(settings.displayDataStart)),
- const Spacer(),
- (settings.graphStepSize == TimeStep.lifetime)
- ? Text(AppLocalizations.of(context)!.now)
- : Text(formatter.format(settings.displayDataEnd)),
- ],
- );
- }),
- const SizedBox(
- height: 2,
- ),
const IntervalPicker()
],
),
lib/l10n/app_de.arb
@@ -177,5 +177,16 @@
"week": "Woche",
"month": "Monat",
"year": "Jahr",
- "lifetime": "Lebenszeit"
+ "lifetime": "Lebenszeit",
+ "weekOfYear": "Woche {weekNum}, {year}",
+ "@weekOfYear": {
+ "placeholders": {
+ "weekNum": {
+ "type": "int"
+ },
+ "year": {
+ "type": "int"
+ }
+ }
+ }
}
\ No newline at end of file
lib/l10n/app_en.arb
@@ -174,5 +174,16 @@
"week": "week",
"month": "month",
"year": "year",
- "lifetime": "lifetime"
+ "lifetime": "lifetime",
+ "weekOfYear": "week {weekNum}, {year}",
+ "@weekOfYear": {
+ "placeholders": {
+ "weekNum": {
+ "type": "int"
+ },
+ "year": {
+ "type": "int"
+ }
+ }
+ }
}
\ No newline at end of file