fixed disclaimer not showing on first visit
This commit is contained in:
parent
08ef784f57
commit
c443a1d567
@ -24,6 +24,11 @@ class LoadableStateConsumer<TController extends Bloc<LoadableHydratedBlocEvent<T
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var loadableState = context.watch<TController>().state;
|
var loadableState = context.watch<TController>().state;
|
||||||
|
|
||||||
|
if(!loadableState.isLoading && onLoad != null) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) => onLoad!(loadableState.data));
|
||||||
|
}
|
||||||
|
|
||||||
var childWidget = ConditionalWrapper(
|
var childWidget = ConditionalWrapper(
|
||||||
condition: loadableState.reFetch != null,
|
condition: loadableState.reFetch != null,
|
||||||
wrapper: (child) => RefreshIndicator(
|
wrapper: (child) => RefreshIndicator(
|
||||||
|
@ -103,10 +103,9 @@ abstract class LoadableHydratedBloc<
|
|||||||
Map<String, dynamic>? toJson(LoadableState<TState> state) {
|
Map<String, dynamic>? toJson(LoadableState<TState> state) {
|
||||||
Map<String, dynamic>? data;
|
Map<String, dynamic>? data;
|
||||||
try {
|
try {
|
||||||
data = toStorage(state.data);
|
data = state.data == null ? null : toStorage(state.data);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
log('Failed to save state ${TState.toString()}: ${e.toString()}');
|
log('Failed to save state ${TState.toString()}: ${e.toString()}');
|
||||||
data = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return LoadableSaveContext.wrap(
|
return LoadableSaveContext.wrap(
|
||||||
|
@ -26,7 +26,7 @@ class AppModule {
|
|||||||
Modules.marianumMessage: AppModule('Marianum Message', Icons.newspaper, MarianumMessageListView.new),
|
Modules.marianumMessage: AppModule('Marianum Message', Icons.newspaper, MarianumMessageListView.new),
|
||||||
Modules.roomPlan: AppModule('Raumplan', Icons.location_pin, Roomplan.new),
|
Modules.roomPlan: AppModule('Raumplan', Icons.location_pin, Roomplan.new),
|
||||||
Modules.gradeAveragesCalculator: AppModule('Notendurschnittsrechner', Icons.calculate, GradeAveragesView.new),
|
Modules.gradeAveragesCalculator: AppModule('Notendurschnittsrechner', Icons.calculate, GradeAveragesView.new),
|
||||||
Modules.holidays: AppModule('Schulferien', Icons.time_to_leave, HolidaysView.new),
|
Modules.holidays: AppModule('Schulferien', Icons.flight, HolidaysView.new),
|
||||||
};
|
};
|
||||||
|
|
||||||
static AppModule getModule(Modules module) => modules()[module]!;
|
static AppModule getModule(Modules module) => modules()[module]!;
|
||||||
|
@ -16,6 +16,7 @@ class HolidaysBloc extends LoadableHydratedBloc<HolidaysEvent, HolidaysState, Ho
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool showPastHolidays() => innerState?.showPastHolidays ?? false;
|
bool showPastHolidays() => innerState?.showPastHolidays ?? false;
|
||||||
|
bool showDisclaimerOnEntry() => innerState?.showDisclaimer ?? false;
|
||||||
List<Holiday>? getHolidays() => innerState?.holidays
|
List<Holiday>? getHolidays() => innerState?.holidays
|
||||||
.where((element) => showPastHolidays() || DateTime.parse(element.end).isAfter(DateTime.now()))
|
.where((element) => showPastHolidays() || DateTime.parse(element.end).isAfter(DateTime.now()))
|
||||||
.toList() ?? [];
|
.toList() ?? [];
|
||||||
|
@ -6,6 +6,7 @@ import '../../../../../widget/list_view_util.dart';
|
|||||||
import '../../../../../widget/centeredLeading.dart';
|
import '../../../../../widget/centeredLeading.dart';
|
||||||
import '../../../../../widget/debug/debugTile.dart';
|
import '../../../../../widget/debug/debugTile.dart';
|
||||||
import '../../../../../widget/string_extensions.dart';
|
import '../../../../../widget/string_extensions.dart';
|
||||||
|
import '../../../infrastructure/loadableState/loadable_state.dart';
|
||||||
import '../../../infrastructure/loadableState/view/loadable_state_consumer.dart';
|
import '../../../infrastructure/loadableState/view/loadable_state_consumer.dart';
|
||||||
import '../../../infrastructure/utilityWidgets/bloc_module.dart';
|
import '../../../infrastructure/utilityWidgets/bloc_module.dart';
|
||||||
import '../bloc/holidays_bloc.dart';
|
import '../bloc/holidays_bloc.dart';
|
||||||
@ -16,7 +17,7 @@ class HolidaysView extends StatelessWidget {
|
|||||||
const HolidaysView({super.key});
|
const HolidaysView({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => BlocModule(
|
Widget build(BuildContext context) => BlocModule<HolidaysBloc, LoadableState<HolidaysState>>(
|
||||||
create: (context) => HolidaysBloc(),
|
create: (context) => HolidaysBloc(),
|
||||||
autoRebuild: true,
|
autoRebuild: true,
|
||||||
child: (context, bloc, state) {
|
child: (context, bloc, state) {
|
||||||
@ -28,10 +29,7 @@ class HolidaysView extends StatelessWidget {
|
|||||||
'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'
|
'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/'),
|
'Die Daten stammen von https://ferien-api.de/'),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(child: const Text('Okay'), onPressed: () {
|
TextButton(child: const Text('Okay'), onPressed: () => Navigator.of(context).pop()),
|
||||||
bloc.add(DisclaimerDismissed());
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -63,6 +61,10 @@ class HolidaysView extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: LoadableStateConsumer<HolidaysBloc, HolidaysState>(
|
body: LoadableStateConsumer<HolidaysBloc, HolidaysState>(
|
||||||
|
onLoad: (state) {
|
||||||
|
if(state.showDisclaimer) showDisclaimer();
|
||||||
|
bloc.add(DisclaimerDismissed());
|
||||||
|
},
|
||||||
child: (state, loading) => ListViewUtil.fromList<Holiday>(bloc.getHolidays(), (holiday) {
|
child: (state, loading) => ListViewUtil.fromList<Holiday>(bloc.getHolidays(), (holiday) {
|
||||||
var holidayType = holiday.name.split(' ').first.capitalize();
|
var holidayType = holiday.name.split(' ').first.capitalize();
|
||||||
String formatDate(String date) => Jiffy.parse(date).format(pattern: 'dd.MM.yyyy');
|
String formatDate(String date) => Jiffy.parse(date).format(pattern: 'dd.MM.yyyy');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user