2021-08-03 22:02:42 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-12-01 23:09:53 +01:00
|
|
|
|
|
|
|
import '../../../bloc/theme/theme_bloc.dart';
|
|
|
|
import '../../../models/themes/theme.dart';
|
2021-08-03 22:02:42 +02:00
|
|
|
|
|
|
|
class DateDivider extends StatelessWidget {
|
|
|
|
final String? text;
|
|
|
|
final DateTime? date;
|
2021-08-08 23:16:54 +02:00
|
|
|
final EdgeInsets? margin;
|
2021-08-03 22:02:42 +02:00
|
|
|
|
2021-08-08 23:16:54 +02:00
|
|
|
const DateDivider({
|
|
|
|
this.text,
|
|
|
|
this.date,
|
|
|
|
this.margin = const EdgeInsets.symmetric(vertical: 10),
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
2021-08-03 22:02:42 +02:00
|
|
|
|
|
|
|
String getHumanReadableDate(DateTime date) {
|
|
|
|
const Map<int, String> monthTable = {
|
|
|
|
1: 'Jan',
|
|
|
|
2: 'Feb',
|
|
|
|
3: 'Mar',
|
|
|
|
4: 'Apr',
|
|
|
|
5: 'May',
|
|
|
|
6: 'Jun',
|
|
|
|
7: 'Jul',
|
|
|
|
8: 'Aug',
|
|
|
|
9: 'Sep',
|
|
|
|
10: 'Oct',
|
|
|
|
11: 'Nov',
|
|
|
|
12: 'Dec',
|
|
|
|
};
|
|
|
|
|
2021-08-08 23:16:54 +02:00
|
|
|
final int day = date.day;
|
|
|
|
final String month = monthTable[date.month]!;
|
|
|
|
final int year = date.year;
|
2021-12-01 23:09:53 +01:00
|
|
|
return '$day. $month $year';
|
2021-08-03 22:02:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-12-01 23:09:53 +01:00
|
|
|
final Widget header = (text != null)
|
|
|
|
? Text(text!)
|
|
|
|
: (date != null)
|
|
|
|
? Text(getHumanReadableDate(date!))
|
|
|
|
: const SizedBox.shrink();
|
2021-08-03 22:02:42 +02:00
|
|
|
|
2021-08-08 23:16:54 +02:00
|
|
|
final ColorSet _menuColors =
|
|
|
|
BlocProvider.of<ThemeBloc>(context).state.theme.menuGreyNormal;
|
|
|
|
|
2021-08-03 22:02:42 +02:00
|
|
|
return Container(
|
2021-08-08 23:16:54 +02:00
|
|
|
decoration: BoxDecoration(color: _menuColors.background),
|
2021-12-01 23:09:53 +01:00
|
|
|
padding: const EdgeInsets.symmetric(
|
2021-08-03 22:02:42 +02:00
|
|
|
vertical: 5,
|
|
|
|
horizontal: 10,
|
|
|
|
),
|
2021-12-01 23:09:53 +01:00
|
|
|
margin: margin,
|
|
|
|
child: DefaultTextStyle.merge(
|
|
|
|
child: header,
|
|
|
|
style: TextStyle(color: _menuColors.foreground),
|
|
|
|
),
|
2021-08-03 22:02:42 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|