cake_wallet/lib/src/screens/dashboard/widgets/date_section_raw.dart

49 lines
1.5 KiB
Dart
Raw Normal View History

2020-01-04 19:31:52 +00:00
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:provider/provider.dart';
import 'package:cake_wallet/src/stores/settings/settings_store.dart';
2020-01-04 19:31:52 +00:00
class DateSectionRaw extends StatelessWidget {
2020-01-08 12:26:34 +00:00
DateSectionRaw({this.date});
2020-01-04 19:31:52 +00:00
static final nowDate = DateTime.now();
final DateTime date;
@override
Widget build(BuildContext context) {
final diffDays = date.difference(nowDate).inDays;
2020-01-08 12:26:34 +00:00
final isToday = nowDate.day == date.day &&
nowDate.month == date.month &&
nowDate.year == date.year;
final settingsStore = Provider.of<SettingsStore>(context);
final currentLanguage = settingsStore.languageCode;
final dateSectionDateFormat = settingsStore.getCurrentDateFormat(
formatUSA: "yyyy MMM d",
formatDefault: "d MMM yyyy");
2020-01-04 19:31:52 +00:00
var title = "";
2020-01-08 12:26:34 +00:00
2020-01-04 19:31:52 +00:00
if (isToday) {
title = S.of(context).today;
} else if (diffDays == 0) {
title = S.of(context).yesterday;
} else if (diffDays > -7 && diffDays < 0) {
final dateFormat = DateFormat.EEEE(currentLanguage);
2020-01-04 19:31:52 +00:00
title = dateFormat.format(date);
} else {
title = dateSectionDateFormat.format(date);
}
return Container(
height: 35,
alignment: Alignment.center,
color: Colors.transparent,
child: Text(title,
style: TextStyle(
fontSize: 12,
color: Theme.of(context).textTheme.overline.backgroundColor
))
2020-01-04 19:31:52 +00:00
);
}
}