-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add planner advert #557
Merged
Merged
Add planner advert #557
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
27dbab4
feat(planner-advert): setup data layer
mikolaj-jalocha 7ddf5cc
feat(planner-advert): setup presentation layer
mikolaj-jalocha 0967c7a
chore(planner-advert): code cleanup
mikolaj-jalocha 1246c3c
feat(planner-advert): PR suggestions
mikolaj-jalocha f5c460c
Merge branch 'main' into feat/planner-advert
simon-the-shark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
lib/features/planner_advert/repository/getPlannerAdvertContent.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
query GetPlannerAdvertContent { | ||
PlannerAdvert { | ||
isEnabled, | ||
title, | ||
description, | ||
url | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
lib/features/planner_advert/repository/planner_advert_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import "package:flutter_riverpod/flutter_riverpod.dart"; | ||
import "package:riverpod_annotation/riverpod_annotation.dart"; | ||
|
||
import "../../../api_base/query_adapter.dart"; | ||
import "../../../config/ttl_config.dart"; | ||
import "getPlannerAdvertContent.graphql.dart"; | ||
|
||
part "planner_advert_repository.g.dart"; | ||
|
||
typedef PlannerAdvertContent = Query$GetPlannerAdvertContent$PlannerAdvert; | ||
|
||
@riverpod | ||
Future<PlannerAdvertContent?> plannerAdvertContentRepository(Ref ref) async { | ||
final results = await ref.queryGraphql( | ||
Options$Query$GetPlannerAdvertContent(), | ||
TtlKey.plannerAdvertRepository, | ||
); | ||
|
||
return results?.PlannerAdvert; | ||
} |
56 changes: 56 additions & 0 deletions
56
lib/features/planner_advert/widgets/planner_advert_widget.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
mikolaj-jalocha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
? 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)); | ||
}, | ||
mikolaj-jalocha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
), | ||
) | ||
: const SizedBox.shrink(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rizontal_rectangular_section_loading.dart → ...rizontal_rectangular_section_loading.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you check how this will behave when the advert is turned off?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I did, imo not bad (please see the pic below). If you like, I will reduce it a bit, but one question arise. Do you have an idea how to do it right? Currently I can't see other options that manually added spacers (besides making HomeScreen Consumer widget, imo wrong way).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no better ideas. If you don't want any
if
s in the separator, then u can give padding directly to children, just by wrapping them inPadding
, but here this will look bad. Imo the current solution is okThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also the padding seems fine