Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/adjust sks menu #479

Merged
merged 6 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/features/sks-menu/data/models/dish_category_enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ enum DishCategory {
vegetarianDish,
meatDish,
sideDish,
drink;
drink,
technicalInfo;

@override
String toString() => name;
Expand All @@ -25,7 +26,8 @@ extension GetLocalizedNameX on DishCategory {
context.localize.sks_menu_vegetarian_dishes,
DishCategory.meatDish => context.localize.sks_menu_meat_dishes,
DishCategory.sideDish => context.localize.sks_menu_side_dishes,
DishCategory.drink => context.localize.sks_menu_drinks
DishCategory.drink => context.localize.sks_menu_drinks,
DishCategory.technicalInfo => context.localize.sks_menu_technical_info,
};
}
}
13 changes: 13 additions & 0 deletions lib/features/sks-menu/data/models/sks_menu_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ class SksMenuResponse with _$SksMenuResponse {
factory SksMenuResponse.fromJson(Map<String, dynamic> json) =>
simon-the-shark marked this conversation as resolved.
Show resolved Hide resolved
_$SksMenuResponseFromJson(json);
}

@freezed
class ExtendedSksMenuResponse with _$ExtendedSksMenuResponse {
const factory ExtendedSksMenuResponse({
required bool isMenuOnline,
required DateTime lastUpdate,
required List<SksMenuDish> meals,
required List<String> technicalInfos,
}) = _ExtendedSksMenuResponse;

factory ExtendedSksMenuResponse.fromJson(Map<String, dynamic> json) =>
_$ExtendedSksMenuResponseFromJson(json);
}
20 changes: 18 additions & 2 deletions lib/features/sks-menu/data/repository/sks_menu_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,34 @@ import "package:riverpod_annotation/riverpod_annotation.dart";

import "../../../../api_base_rest/client/dio_client.dart";
import "../../../../config/env.dart";
import "../models/dish_category_enum.dart";
import "../models/sks_menu_response.dart";

part "sks_menu_repository.g.dart";

@riverpod
Future<SksMenuResponse> getSksMenuData(Ref ref) async {
Future<ExtendedSksMenuResponse> getSksMenuData(Ref ref) async {
final mealsUrl = "${Env.sksUrl}/meals/current";

final dio = ref.read(restClientProvider);
final response = await dio.get(mealsUrl);
final SksMenuResponse sksMenuResponse =
SksMenuResponse.fromJson(response.data as Map<String, dynamic>);

return sksMenuResponse;
final trueMeals = sksMenuResponse.meals
.where((e) => e.category != DishCategory.technicalInfo)
.toList();
final technicalInfos = sksMenuResponse.meals
.where((e) => e.category == DishCategory.technicalInfo)
.map((e) => e.name)
.toList();

return ExtendedSksMenuResponse(
isMenuOnline: sksMenuResponse.isMenuOnline,
lastUpdate: sksMenuResponse.lastUpdate,
meals: trueMeals,
technicalInfos: [
...technicalInfos,
],
);
}
118 changes: 65 additions & 53 deletions lib/features/sks-menu/presentation/sks_menu_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import "../../../config/ui_config.dart";
import "../../../gen/assets.gen.dart";
import "../../../utils/context_extensions.dart";
import "../../../widgets/detail_views/detail_view_app_bar.dart";
import "../../home_view/widgets/paddings.dart";
import "../../../widgets/my_text_button.dart";
import "../../sks_people_live/presentation/widgets/sks_user_data_button.dart";
import "../data/models/sks_menu_response.dart";
import "../data/repository/sks_menu_repository.dart";
import "widgets/sks_menu_data_source_link.dart";
import "widgets/sks_menu_header.dart";
import "widgets/sks_menu_section.dart";
import "widgets/sks_menu_view_loading.dart";
import "widgets/technical_message.dart";

@RoutePage()
class SksMenuView extends HookConsumerWidget {
Expand Down Expand Up @@ -60,7 +61,7 @@ class _SksMenuView extends StatelessWidget {
required this.isLastMenuButtonClicked,
});

final SksMenuResponse sksMenuData;
final ExtendedSksMenuResponse sksMenuData;
final bool isLastMenuButtonClicked;

@override
Expand All @@ -76,16 +77,20 @@ class _SksMenuView extends StatelessWidget {
),
body: ListView(
children: [
if (!sksMenuData.isMenuOnline)
TechnicalMessage(
color: context.colorTheme.blueAzure,
title: context.localize.sks_note,
message: context.localize.sks_menu_you_see_last_menu,
),
for (final technicalInfo in sksMenuData.technicalInfos)
TechnicalMessage(message: technicalInfo),
SksMenuHeader(
dateTimeOfLastUpdate: sksMenuData.lastUpdate.toIso8601String(),
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: HomeViewConfig.paddingMedium,
),
child: MediumHorizontalPadding(
child: SksMenuSection(sksMenuData.meals),
),
padding: const EdgeInsets.all(HomeViewConfig.paddingMedium),
child: SksMenuSection(sksMenuData.meals),
),
const SksMenuDataSourceLink(),
const SizedBox(
Expand Down Expand Up @@ -113,55 +118,21 @@ class _SKSMenuLottieAnimation extends HookWidget {
if (error != null) {
Logger().e(error.toString());
}
final animationSize = MediaQuery.sizeOf(context).width * 0.6;

return Scaffold(
backgroundColor: context.colorTheme.whiteSoap,
appBar: DetailViewAppBar(
actions: const [
SksUserDataButton(),
],
),
body: Stack(
alignment: Alignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 200),
if (isAnimationCompleted.value)
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text(
context.localize.sks_menu_closed,
style: context.textTheme.headline,
textAlign: TextAlign.center,
),
),
if (error != null && isAnimationCompleted.value)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
error.toString(),
style: context.textTheme.titleGrey,
textAlign: TextAlign.center,
),
),
if (onShowLastMenuTap != null && isAnimationCompleted.value)
Padding(
padding: const EdgeInsets.only(top: 16),
child: ElevatedButton(
onPressed: onShowLastMenuTap,
child: Text(
context.localize.sks_show_last_menu,
style: context.textTheme.lightTitle,
textAlign: TextAlign.center,
),
),
),
],
),
Align(
child: SizedBox.square(
dimension: 200,
body: Center(
child: Column(
children: [
const Spacer(),
SizedBox.square(
dimension: animationSize,
child: Lottie.asset(
Assets.animations.sksClosed,
fit: BoxFit.cover,
Expand All @@ -170,14 +141,55 @@ class _SKSMenuLottieAnimation extends HookWidget {
renderCache: RenderCache.drawingCommands,
onLoaded: (composition) {
final totalDuration = composition.duration;
Future.delayed(totalDuration, () {
Future.delayed(
totalDuration *
0.8, // in my opinion the animation is a bit boring at the end, so we can show the texts a bit earlier
simon-the-shark marked this conversation as resolved.
Show resolved Hide resolved
() {
isAnimationCompleted.value = true;
});
},
),
),
),
],
Opacity(
opacity: isAnimationCompleted.value ? 1 : 0,
child: Transform.translate(
offset: Offset(
0,
-(animationSize *
0.10), // the animation has some extra space at the bottom
),
child: Column(
children: [
Text(
context.localize.sks_menu_closed,
style: context.textTheme.headline.copyWith(
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
if (error != null)
Text(
error.toString(),
style: context.textTheme.titleGrey,
textAlign: TextAlign.center,
),
if (onShowLastMenuTap != null)
Padding(
padding: const EdgeInsets.only(top: 12),
child: MyTextButton(
actionTitle: context.localize.sks_show_last_menu,
onClick: onShowLastMenuTap,
showBorder: true,
color: context.colorTheme.blueAzure,
),
),
],
),
),
),
const Spacer(flex: 2),
],
),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,31 @@ class SksMenuDataSourceLink extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
return Text.rich(
TextSpan(
text: "${context.localize.data_come_from_website}: ",
style: const TextStyle(
fontWeight: FontWeight.bold,
),
children: [
TextSpan(
text: SksMenuConfig.sksDataSource.replaceFirst("https://", "www."),
style: context.textTheme.bodyOrange.copyWith(
decoration: TextDecoration.underline,
decorationColor: context.colorTheme.orangePomegranade,
fontWeight: FontWeight.bold,
),
recognizer: TapGestureRecognizer()
..onTap = () async => ref.launch(SksMenuConfig.sksDataSource),
return Padding(
padding: const EdgeInsets.all(16),
child: Text.rich(
TextSpan(
text: "${context.localize.data_come_from_website}: ",
style: const TextStyle(
fontWeight: FontWeight.bold,
),
],
children: [
TextSpan(
text:
SksMenuConfig.sksDataSource.replaceFirst("https://", "www."),
style: context.textTheme.bodyOrange.copyWith(
decoration: TextDecoration.underline,
decorationColor: context.colorTheme.orangePomegranade,
fontWeight: FontWeight.bold,
),
recognizer: TapGestureRecognizer()
..onTap = () async => ref.launch(SksMenuConfig.sksDataSource),
),
],
),
textAlign: TextAlign.center,
style: context.textTheme.body,
),
textAlign: TextAlign.center,
style: context.textTheme.body,
);
}
}
41 changes: 41 additions & 0 deletions lib/features/sks-menu/presentation/widgets/technical_message.dart
simon-the-shark marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import "package:flutter/material.dart";

import "../../../../config/ui_config.dart";
import "../../../../theme/app_theme.dart";
import "../../data/models/dish_category_enum.dart";

class TechnicalMessage extends StatelessWidget {
const TechnicalMessage({
super.key,
required this.message,
this.title,
this.color,
});
final String message;
final String? title;
final Color? color;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(
HomeViewConfig.paddingMedium,
),
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
simon-the-shark marked this conversation as resolved.
Show resolved Hide resolved
child: ColoredBox(
color: color ?? context.colorTheme.orangePomegranade,
child: ListTile(
title: Text(
title ?? DishCategory.technicalInfo.getLocalizedName(context),
style: context.textTheme.titleWhite,
),
subtitle: Text(
message,
style: context.textTheme.bodyWhite,
),
),
),
),
);
}
}
5 changes: 4 additions & 1 deletion lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,8 @@
"sks_menu_closed" : "SKS Menu jest teraz niedostępne",
"sks_show_last_menu" : "Pokaż ostatnio dostępne menu",
"confirm": "Zatwierdź",
"push_notifications_dialog_info": "Obecnie nie korzystamy z powiadomień push, ale planujemy dodać je w przyszłości. Możesz wyrazić na nie zgodę już teraz."
"push_notifications_dialog_info": "Obecnie nie korzystamy z powiadomień push, ale planujemy dodać je w przyszłości. Możesz wyrazić na nie zgodę już teraz.",
"sks_menu_technical_info": "KOMUNIKAT",
"sks_note": "UWAGA",
"sks_menu_you_see_last_menu": "Aktualne menu SKS jest niedostępne. Przeglądasz ostatnio dostępną wersję."
}
16 changes: 13 additions & 3 deletions lib/widgets/my_text_button.dart
simon-the-shark marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,35 @@ class MyTextButton extends StatelessWidget {
super.key,
this.onClick,
required this.actionTitle,
this.showBorder = false,
this.color,
});

final VoidCallback? onClick;
final String actionTitle;

final bool showBorder;
final Color? color;
@override
Widget build(BuildContext context) {
return TextButton(
onPressed: onClick,
style: TextButton.styleFrom(
padding: const EdgeInsets.all(12),
side: showBorder
? BorderSide(
color: color ?? context.colorTheme.orangePomegranade,
)
: null,
),
child: Text(
actionTitle,
style: onClick == null
? context.textTheme.boldBodyOrange.copyWith(
color: context.colorTheme.greyPigeon,
color: color ?? context.colorTheme.greyPigeon,
)
: context.textTheme.boldBodyOrange,
: context.textTheme.boldBodyOrange.copyWith(
color: color ?? context.colorTheme.orangePomegranade,
),
),
);
}
Expand Down
Loading