Skip to content

Commit

Permalink
add no schedule for this week description
Browse files Browse the repository at this point in the history
  • Loading branch information
smart7even committed Jan 4, 2024
1 parent 6a77668 commit d55071b
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 17 deletions.
60 changes: 54 additions & 6 deletions lib/feature/schedule/widget/schedule_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ class _SchedulePageState extends State<SchedulePage>
BuildContext context,
int newIndex,
int? week,
Map<int, ScheduleDetails> data,
) async {
if (week == null) {
return;
Expand Down Expand Up @@ -414,6 +413,44 @@ class _SchedulePageState extends State<SchedulePage>
);
}

void onNextWeek() {
final currentPage = controller.page;
final week = scheduleBLoC.state.currentWeek;

if (currentPage == null) {
return;
}

final newPage = currentPage + 1;

controller.animateToPage(
newPage.round(),
duration: const Duration(milliseconds: 300),
curve: Curves.easeIn,
);

onPageChanged(context, newPage.round(), week);
}

void onPreviousWeek() {
final currentPage = controller.page;
final week = scheduleBLoC.state.currentWeek;

if (currentPage == null) {
return;
}

final newPage = currentPage - 1;

controller.animateToPage(
newPage.round(),
duration: const Duration(milliseconds: 300),
curve: Curves.easeIn,
);

onPageChanged(context, newPage.round(), week);
}

Widget _buildPageView(
BuildContext context,
ScheduleState state,
Expand Down Expand Up @@ -518,8 +555,7 @@ class _SchedulePageState extends State<SchedulePage>
body: PageView.builder(
controller: controller,
scrollDirection: Axis.horizontal,
onPageChanged: (int newIndex) =>
onPageChanged(context, newIndex, week, data),
onPageChanged: (int newIndex) => onPageChanged(context, newIndex, week),
itemBuilder: (context, index) {
debugPrint('index: ${index - initialPageIndex}');
int? currentWeek;
Expand All @@ -529,14 +565,26 @@ class _SchedulePageState extends State<SchedulePage>
}

if (currentWeek == null) {
return const ScheduleWidget(schedule: Schedule.empty());
return ScheduleWidget(
schedule: const Schedule.empty(),
onNextWeek: onNextWeek,
onPreviousWeek: onPreviousWeek,
);
}

if (currentWeek < 0 || currentWeek > 52) {
return const ScheduleWidget(schedule: Schedule.empty());
return ScheduleWidget(
schedule: const Schedule.empty(),
onNextWeek: onNextWeek,
onPreviousWeek: onPreviousWeek,
);
}

return ScheduleWidget(schedule: data[currentWeek]?.schedule);
return ScheduleWidget(
schedule: data[currentWeek]?.schedule,
onNextWeek: onNextWeek,
onPreviousWeek: onPreviousWeek,
);
},
),
);
Expand Down
58 changes: 51 additions & 7 deletions lib/feature/schedule/widget/schedule_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import 'package:uneconly/feature/schedule/widget/lesson_tile.dart';
/// {@endtemplate}
class ScheduleWidget extends StatelessWidget {
final Schedule? schedule;
final VoidCallback? onNextWeek;
final VoidCallback? onPreviousWeek;

/// {@macro schedule_widget}
const ScheduleWidget({
super.key,
required this.schedule,
this.onNextWeek,
this.onPreviousWeek,
});

List<Widget> _buildSchedule(BuildContext context) {
List<Widget> slivers = [];
Expand Down Expand Up @@ -109,12 +119,6 @@ class ScheduleWidget extends StatelessWidget {
return slivers;
}

/// {@macro schedule_widget}
const ScheduleWidget({
super.key,
required this.schedule,
});

@override
Widget build(BuildContext context) {
final currentSchedule = schedule;
Expand All @@ -127,7 +131,47 @@ class ScheduleWidget extends StatelessWidget {

if (currentSchedule.daySchedules.isEmpty) {
return Center(
child: Text(AppLocalizations.of(context)!.noSchedule),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(AppLocalizations.of(context)!.noSchedule),
const SizedBox(
height: 8,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
AppLocalizations.of(context)!.noScheduleDescription,
textAlign: TextAlign.center,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
onPreviousWeek?.call();
},
child: const Icon(
Icons.arrow_left,
),
),
const SizedBox(
width: 16,
),
ElevatedButton(
onPressed: () {
onNextWeek?.call();
},
child: const Icon(
Icons.arrow_right,
),
),
],
),
],
),
);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"schedule": "Schedule",
"week": "week",
"now": "now",
"noSchedule": "No schedule",
"noSchedule": "No schedule for this week",
"loadingSchedule": "Loading schedule",
"today": "Today",
"tomorrow": "Tomorrow",
Expand Down Expand Up @@ -37,5 +37,6 @@
"removeFromFavorites": "Remove from favorites",
"favoriteGroups": "Favorite groups",
"addFirstFavoriteGroup": "List is empty. Add groups to favorites to access it quickly",
"add": "Add"
"add": "Add",
"noScheduleDescription": "Swipe left to see the schedule for the next week or right to see the schedule for the previous week"
}
5 changes: 3 additions & 2 deletions lib/l10n/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"schedule": "Расписание",
"week": "неделя",
"now": "сейчас",
"noSchedule": "Нет расписания",
"noSchedule": "Нет расписания на эту неделю",
"loadingSchedule": "Загружаем расписание",
"today": "Сегодня",
"tomorrow": "Завтра",
Expand Down Expand Up @@ -34,5 +34,6 @@
"removeFromFavorites": "Удалить из избранного",
"favoriteGroups": "Избранные группы",
"addFirstFavoriteGroup": "Список пуст. Добавляйте группы в избранное, чтобы быстро получать к ним доступ",
"add": "Добавить"
"add": "Добавить",
"noScheduleDescription": "Свайпните влево, чтобы посмотреть расписание на следующую неделю, или вправо, чтобы посмотреть на предыдущую"
}

0 comments on commit d55071b

Please sign in to comment.