dart format
This commit is contained in:
@@ -19,17 +19,19 @@ class HolidaysView extends StatelessWidget {
|
||||
const HolidaysView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => BlocModule<HolidaysBloc, LoadableState<HolidaysState>>(
|
||||
Widget build(
|
||||
BuildContext context,
|
||||
) => BlocModule<HolidaysBloc, LoadableState<HolidaysState>>(
|
||||
create: (context) => HolidaysBloc(),
|
||||
autoRebuild: true,
|
||||
child: (context, bloc, state) {
|
||||
void showDisclaimer() => InfoDialog.show(
|
||||
context,
|
||||
'Sämtliche Datumsangaben sind ohne Gewähr.\n'
|
||||
'Ich übernehme weder Verantwortung für die Richtigkeit der Daten noch hafte ich für wirtschaftliche Schäden die aus der Verwendung dieser Daten entstehen können.\n\n'
|
||||
'Die Daten stammen von https://ferien-api.de/',
|
||||
title: 'Richtigkeit und Bereitstellung der Daten',
|
||||
);
|
||||
context,
|
||||
'Sämtliche Datumsangaben sind ohne Gewähr.\n'
|
||||
'Ich übernehme weder Verantwortung für die Richtigkeit der Daten noch hafte ich für wirtschaftliche Schäden die aus der Verwendung dieser Daten entstehen können.\n\n'
|
||||
'Die Daten stammen von https://ferien-api.de/',
|
||||
title: 'Richtigkeit und Bereitstellung der Daten',
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -42,79 +44,110 @@ class HolidaysView extends StatelessWidget {
|
||||
PopupMenuButton<bool>(
|
||||
initialValue: bloc.showPastHolidays(),
|
||||
icon: const Icon(Icons.history),
|
||||
itemBuilder: (context) => [true, false].map((e) => PopupMenuItem<bool>(
|
||||
value: e,
|
||||
enabled: e != bloc.showPastHolidays(),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(e ? Icons.history_outlined : Icons.history_toggle_off_outlined, color: Theme.of(context).colorScheme.onSurface),
|
||||
const SizedBox(width: 15),
|
||||
Text(e ? 'Alle anzeigen' : 'Nur zukünftige anzeigen')
|
||||
],
|
||||
itemBuilder: (context) => [true, false]
|
||||
.map(
|
||||
(e) => PopupMenuItem<bool>(
|
||||
value: e,
|
||||
enabled: e != bloc.showPastHolidays(),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
e
|
||||
? Icons.history_outlined
|
||||
: Icons.history_toggle_off_outlined,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
Text(e ? 'Alle anzeigen' : 'Nur zukünftige anzeigen'),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
)).toList(),
|
||||
.toList(),
|
||||
onSelected: (e) => bloc.add(SetPastHolidaysVisible(e)),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: LoadableStateConsumer<HolidaysBloc, HolidaysState>(
|
||||
onLoad: (state) {
|
||||
if(state.showDisclaimer) showDisclaimer();
|
||||
if (state.showDisclaimer) showDisclaimer();
|
||||
bloc.add(DisclaimerDismissed());
|
||||
},
|
||||
child: (state, loading) => ListViewUtil.fromList<Holiday>(bloc.getHolidays(), (holiday) {
|
||||
var holidayType = holiday.name.split(' ').first.capitalize();
|
||||
String formatDate(String date) => Jiffy.parse(date).format(pattern: 'dd.MM.yyyy');
|
||||
String getYear(String date, {String format = 'yyyy'}) => Jiffy.parse(date).format(pattern: format);
|
||||
child: (state, loading) => ListViewUtil.fromList<Holiday>(
|
||||
bloc.getHolidays(),
|
||||
(holiday) {
|
||||
var holidayType = holiday.name.split(' ').first.capitalize();
|
||||
String formatDate(String date) =>
|
||||
Jiffy.parse(date).format(pattern: 'dd.MM.yyyy');
|
||||
String getYear(String date, {String format = 'yyyy'}) =>
|
||||
Jiffy.parse(date).format(pattern: format);
|
||||
|
||||
String getHolidayYear(String startDate, String endDate) => getYear(startDate) == getYear(endDate)
|
||||
String getHolidayYear(String startDate, String endDate) =>
|
||||
getYear(startDate) == getYear(endDate)
|
||||
? getYear(startDate)
|
||||
: '${getYear(startDate)}/${getYear(endDate, format: 'yy')}';
|
||||
|
||||
return ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.calendar_month)),
|
||||
title: Text('$holidayType ${getHolidayYear(holiday.start, holiday.end)}'),
|
||||
subtitle: Text('${formatDate(holiday.start)} - ${formatDate(holiday.end)}'),
|
||||
onTap: () => showDetailsBottomSheet(
|
||||
context,
|
||||
header: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 12),
|
||||
child: Text(
|
||||
'$holidayType ${holiday.year} in Hessen',
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
return ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.calendar_month)),
|
||||
title: Text(
|
||||
'$holidayType ${getHolidayYear(holiday.start, holiday.end)}',
|
||||
),
|
||||
children: (sheetCtx) => [
|
||||
ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.signpost_outlined)),
|
||||
title: Text(holiday.name.capitalize()),
|
||||
subtitle: Text(holiday.slug.capitalize()),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.date_range_outlined),
|
||||
title: Text('vom ${formatDate(holiday.start)}'),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.date_range_outlined),
|
||||
title: Text('bis zum ${formatDate(holiday.end)}'),
|
||||
),
|
||||
if (DateTime.parse(holiday.start).difference(DateTime.now()).isNegative)
|
||||
ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.content_paste_search_outlined)),
|
||||
title: Text(Jiffy.parse(holiday.start).fromNow()),
|
||||
)
|
||||
else
|
||||
ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.timer_outlined)),
|
||||
title: AnimatedTime(callback: () => DateTime.parse(holiday.start).difference(DateTime.now())),
|
||||
subtitle: Text(Jiffy.parse(holiday.start).fromNow()),
|
||||
subtitle: Text(
|
||||
'${formatDate(holiday.start)} - ${formatDate(holiday.end)}',
|
||||
),
|
||||
onTap: () => showDetailsBottomSheet(
|
||||
context,
|
||||
header: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 12),
|
||||
child: Text(
|
||||
'$holidayType ${holiday.year} in Hessen',
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
DebugTile(sheetCtx).jsonData(holiday.toJson()),
|
||||
],
|
||||
),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
);
|
||||
}),
|
||||
),
|
||||
children: (sheetCtx) => [
|
||||
ListTile(
|
||||
leading: const CenteredLeading(
|
||||
Icon(Icons.signpost_outlined),
|
||||
),
|
||||
title: Text(holiday.name.capitalize()),
|
||||
subtitle: Text(holiday.slug.capitalize()),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.date_range_outlined),
|
||||
title: Text('vom ${formatDate(holiday.start)}'),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.date_range_outlined),
|
||||
title: Text('bis zum ${formatDate(holiday.end)}'),
|
||||
),
|
||||
if (DateTime.parse(
|
||||
holiday.start,
|
||||
).difference(DateTime.now()).isNegative)
|
||||
ListTile(
|
||||
leading: const CenteredLeading(
|
||||
Icon(Icons.content_paste_search_outlined),
|
||||
),
|
||||
title: Text(Jiffy.parse(holiday.start).fromNow()),
|
||||
)
|
||||
else
|
||||
ListTile(
|
||||
leading: const CenteredLeading(
|
||||
Icon(Icons.timer_outlined),
|
||||
),
|
||||
title: AnimatedTime(
|
||||
callback: () => DateTime.parse(
|
||||
holiday.start,
|
||||
).difference(DateTime.now()),
|
||||
),
|
||||
subtitle: Text(Jiffy.parse(holiday.start).fromNow()),
|
||||
),
|
||||
DebugTile(sheetCtx).jsonData(holiday.toJson()),
|
||||
],
|
||||
),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user