Skip to content

Commit

Permalink
feat(planner-advert): setup presentation layer
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolaj-jalocha committed Jan 25, 2025
1 parent 27dbab4 commit 7ddf5cc
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/features/home_view/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "package:flutter/material.dart";
import "../../config/ui_config.dart";
import "../../theme/app_theme.dart";
import "../academic_calendar/widgets/academic_calendar_consumer.dart";
import "../planner_advert/widgets/planner_advert_widget.dart";
import "keep_alive_home_view_providers.dart";
import "widgets/buildings_section/buildings_section.dart";
import "widgets/logo_app_bar.dart";
Expand All @@ -23,6 +24,7 @@ class HomeView extends StatelessWidget {
padding: EdgeInsets.only(top: 12, bottom: 4),
child: NavActionsSection(),
),
PlannerAdvertBanner(),
const ScienceClubsSection(),
const BuildingsSection(),
].lock;
Expand All @@ -35,7 +37,7 @@ class HomeView extends StatelessWidget {
child: ListView.separated(
itemBuilder: (context, index) => sections[index],
separatorBuilder: (context, index) => SizedBox(
height: index == 1 ? 0 : HomeViewConfig.paddingMedium,
height: index == 1 || index == 2 ? 0 : HomeViewConfig.paddingMedium,
),
itemCount: sections.length,
),
Expand Down
1 change: 1 addition & 0 deletions lib/features/offline_messages/messages_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extension GqlOfflineMessageX on BuildContext {
TtlKey.guideDetailsRepository => localize.offline_guide_details,
TtlKey.guideRepository => localize.offline_guide_posts,
TtlKey.changelogRepository => localize.offline_changelog,
TtlKey.plannerAdvertRepository => localize.general_offline,
};

String gqlOfflineMessageLocalized(TtlKey key) {
Expand Down
56 changes: 56 additions & 0 deletions lib/features/planner_advert/widgets/planner_advert_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import "dart:async";

import "package:flutter/material.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";

import "../../../config/ui_config.dart";
import "../../../theme/app_theme.dart";
import "../../../utils/launch_url_util.dart";
import "../../../widgets/loading_widgets/simple_previews/horizontal_rectangular_section_loading.dart";
import "../../../widgets/my_error_widget.dart";
import "../../../widgets/technical_message.dart";
import "../repository/planner_advert_repository.dart";

class PlannerAdvertBanner extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final state = ref.watch(plannerAdvertContentRepositoryProvider);
return switch (state) {
AsyncError(:final error) => MyErrorWidget(error),
AsyncValue(:final PlannerAdvertContent value) =>
_PlannerAdvertBanner(value),
_ => const HorizontalRectangularSectionLoading()
};
}
}

class _PlannerAdvertBanner extends ConsumerWidget {
const _PlannerAdvertBanner(
this.data,
);

final PlannerAdvertContent data;

@override
Widget build(BuildContext context, WidgetRef ref) {
return data.isEnabled
? Padding(
padding: const EdgeInsets.symmetric(
horizontal: HomeViewConfig.paddingSmall,
),
child: TechnicalMessage(
title: data.title,
message: data.description,
alertType: AlertType.info,
icon: Icon(
Icons.open_in_new_rounded,
color: context.colorTheme.whiteSoap,
),
onTap: () async {
unawaited(ref.launch(data.url));
},
),
)
: const SizedBox.shrink();
}
}
3 changes: 2 additions & 1 deletion lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -303,5 +303,6 @@
"lodge": "Portiernia",
"dressing_room": "Szatnia",
"no_lodge_in_the_building": "W tym budynku nie ma portierni",
"no_dressing_room_in_the_building": "W tym budynku nie ma szatni"
"no_dressing_room_in_the_building": "W tym budynku nie ma szatni",
"general_offline" : "pobierania danych"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "package:flutter/material.dart";

import "../../../../config/ui_config.dart";
import "../../../../theme/app_theme.dart";
import "../../data/models/dish_category_enum.dart";
import "../config/ui_config.dart";
import "../features/sks-menu/data/models/dish_category_enum.dart";
import "../theme/app_theme.dart";

enum AlertType { info, error }

Expand All @@ -12,10 +12,14 @@ class TechnicalMessage extends StatelessWidget {
required this.message,
this.title,
this.alertType = AlertType.error,
this.icon,
this.onTap,
});
final String message;
final String? title;
final AlertType alertType;
final Icon? icon;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
return Padding(
Expand All @@ -30,6 +34,8 @@ class TechnicalMessage extends StatelessWidget {
? context.colorTheme.orangePomegranade
: context.colorTheme.blueAzure,
child: ListTile(
onTap: onTap,
trailing: icon,
title: Text(
title ?? DishCategory.technicalInfo.getLocalizedName(context),
style: context.textTheme.titleWhite,
Expand Down

0 comments on commit 7ddf5cc

Please sign in to comment.