54 lines
1.4 KiB
Dart
54 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:intl/intl.dart';
|
||
|
||
import 'package:timetrack/features/reports/domain/report_data.dart';
|
||
|
||
class PeriodNavigator extends StatelessWidget {
|
||
const PeriodNavigator({
|
||
super.key,
|
||
required this.period,
|
||
required this.periodStart,
|
||
required this.periodEnd,
|
||
required this.onPrevious,
|
||
required this.onNext,
|
||
});
|
||
|
||
final ReportPeriod period;
|
||
final DateTime periodStart;
|
||
final DateTime periodEnd;
|
||
final VoidCallback onPrevious;
|
||
final VoidCallback onNext;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
IconButton(
|
||
icon: const Icon(Icons.chevron_left),
|
||
onPressed: onPrevious,
|
||
),
|
||
Text(
|
||
_label(),
|
||
style: Theme.of(context).textTheme.titleSmall,
|
||
),
|
||
IconButton(
|
||
icon: const Icon(Icons.chevron_right),
|
||
onPressed: onNext,
|
||
),
|
||
],
|
||
);
|
||
}
|
||
|
||
String _label() {
|
||
switch (period) {
|
||
case ReportPeriod.day:
|
||
return DateFormat('EEE, d MMM y').format(periodStart);
|
||
case ReportPeriod.week:
|
||
return '${DateFormat('d MMM').format(periodStart)} – '
|
||
'${DateFormat('d MMM y').format(periodEnd.subtract(const Duration(days: 1)))}';
|
||
case ReportPeriod.month:
|
||
return DateFormat('MMMM y').format(periodStart);
|
||
}
|
||
}
|
||
}
|