Skip to content

Commit

Permalink
fix: Dont show error screen if schedule not loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
0niel committed Jan 10, 2024
1 parent 14dba8b commit ad212de
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/schedule/view/schedule_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,19 @@ class _SchedulePageState extends State<SchedulePage> {

@override
Widget build(BuildContext context) {
return BlocBuilder<ScheduleBloc, ScheduleState>(
return BlocConsumer<ScheduleBloc, ScheduleState>(
listener: (context, state) {
if (state.status == ScheduleStatus.failure) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ошибка при загрузке расписания'),
),
);
}
},
buildWhen: (previous, current) =>
current.status != ScheduleStatus.failure &&
current.selectedSchedule != null,
builder: (context, state) {
if (state.selectedSchedule == null &&
state.status != ScheduleStatus.loading) {
Expand All @@ -70,11 +82,12 @@ class _SchedulePageState extends State<SchedulePage> {
return const Center(
child: CircularProgressIndicator(),
);
} else if (state.status == ScheduleStatus.failure) {
} else if (state.status == ScheduleStatus.failure &&
state.selectedSchedule == null) {
return LoadingErrorMessage(onTap: () {
context.go('/schedule/search');
});
} else if (state.status == ScheduleStatus.loaded) {
} else if (state.selectedSchedule != null) {
return Scaffold(
backgroundColor: AppTheme.colors.background01,
body: NestedScrollView(
Expand Down Expand Up @@ -207,9 +220,11 @@ class _SchedulePageState extends State<SchedulePage> {
),
),
);
} else {
return const Center(
child: CircularProgressIndicator(),
);
}

return Container();
},
);
}
Expand Down

0 comments on commit ad212de

Please sign in to comment.