-
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
#128 implement guide detail view #147
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4e45206
#128 - implement guide detail view - setup data layer
mikolaj-jalocha 5ce1a09
#128 - implement guide detail view - setup front end layer
mikolaj-jalocha ad35cd0
#128 - implement guide detail view - setup front end layer
mikolaj-jalocha d912343
#128 - implement guide detail view - code cleanup
mikolaj-jalocha 4ee4a97
#128 - implement guide detail view - configure temporary navigation
mikolaj-jalocha 58c7264
#128 - implement guide detail view - setup error message
mikolaj-jalocha 9e07b05
#128 - implement guide detail view - loading
mikolaj-jalocha 6e944f0
#128 - implement guide detail view - pr fixes
mikolaj-jalocha 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import "package:auto_route/auto_route.dart"; | ||
import "package:flutter/material.dart"; | ||
import "package:flutter_riverpod/flutter_riverpod.dart"; | ||
import "package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart"; | ||
|
||
import "../../api_base/directus_assets_url.dart"; | ||
import "../../config/ui_config.dart"; | ||
import "../../theme/app_theme.dart"; | ||
import "../../utils/context_extensions.dart"; | ||
import "../../widgets/detail_views/detail_view_app_bar.dart"; | ||
import "../../widgets/loading_widgets/shimmer_loading.dart"; | ||
import "../../widgets/loading_widgets/simple_previews/preview_text_prototype.dart"; | ||
import "../../widgets/my_cached_image.dart"; | ||
import "../../widgets/my_error_widget.dart"; | ||
import "repository/guide_detail_view_repository.dart"; | ||
import "widgets/my_expansion_tile.dart"; | ||
|
||
@RoutePage() | ||
class GuideDetailView extends StatelessWidget { | ||
const GuideDetailView({ | ||
@PathParam("id") required this.id, | ||
super.key, | ||
}); | ||
|
||
final String id; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: DetailViewAppBar(context, title: context.localize.guide), | ||
body: _GuideDetailDataView(id: id), | ||
); | ||
} | ||
} | ||
|
||
class _GuideDetailDataView extends ConsumerWidget { | ||
final String id; | ||
|
||
const _GuideDetailDataView({required this.id}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final state = ref.watch(guideDetailsRepositoryProvider(id)); | ||
return switch (state) { | ||
AsyncLoading() => const _GuideDetailLoading(), | ||
AsyncError(:final error) => MyErrorWidget(error), | ||
AsyncValue(:final value) => ListView( | ||
children: [ | ||
MyCachedImage(value?.cover?.filename_disk?.directusUrl), | ||
Padding( | ||
padding: | ||
const EdgeInsets.all(GuideDetailViewConfig.paddingMedium), | ||
child: HtmlWidget( | ||
value?.description ?? "", | ||
textStyle: context.textTheme.body.copyWith(fontSize: 16), | ||
), | ||
), | ||
ListView.separated( | ||
shrinkWrap: true, | ||
physics: const ClampingScrollPhysics(), | ||
padding: const EdgeInsets.only( | ||
bottom: GuideDetailViewConfig.paddingLarge, | ||
), | ||
itemCount: value?.questions?.length ?? 0, | ||
itemBuilder: (context, index) { | ||
final question = value?.questions?[index]?.FAQ_id; | ||
return MyExpansionTile( | ||
title: question?.question ?? "", | ||
description: question?.answer ?? "", | ||
); | ||
}, | ||
separatorBuilder: (context, index) => const SizedBox( | ||
height: 8, | ||
), | ||
), | ||
], | ||
) | ||
}; | ||
} | ||
} | ||
|
||
class _GuideDetailLoading extends StatelessWidget { | ||
const _GuideDetailLoading(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Shimmer( | ||
linearGradient: shimmerGradient, | ||
child: ListView( | ||
physics: const NeverScrollableScrollPhysics(), | ||
children: [ | ||
ShimmerLoadingItem( | ||
child: Container( | ||
color: Colors.white, | ||
width: double.infinity, | ||
height: 300, | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(GuideDetailViewConfig.paddingMedium), | ||
child: ListView.separated( | ||
shrinkWrap: true, | ||
physics: const NeverScrollableScrollPhysics(), | ||
itemBuilder: (context, _) { | ||
return ShimmerLoadingItem( | ||
child: PreviewTextPrototype( | ||
width: double.infinity, | ||
), | ||
); | ||
}, | ||
separatorBuilder: (context, _) => const SizedBox( | ||
height: 8, | ||
), | ||
itemCount: 5, | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(GuideDetailViewConfig.paddingMedium), | ||
child: ShimmerLoadingItem( | ||
child: ListView.separated( | ||
shrinkWrap: true, | ||
physics: const NeverScrollableScrollPhysics(), | ||
itemBuilder: (context, _) { | ||
return const MyExpansionTileLoading(); | ||
}, | ||
separatorBuilder: (context, _) => const SizedBox( | ||
height: 8, | ||
), | ||
itemCount: 3, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
lib/features/guide_detail_view/repository/getGuideDetails.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,15 @@ | ||
query GetGuideDetails($id: ID!) { | ||
FAQ_Types_by_id(id: $id){ | ||
name, | ||
cover { | ||
filename_disk | ||
}, | ||
description, | ||
questions { | ||
FAQ_id { | ||
question, | ||
answer | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
lib/features/guide_detail_view/repository/guide_detail_view_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,24 @@ | ||
import "package:riverpod_annotation/riverpod_annotation.dart"; | ||
import "../../../api_base/watch_query_adapter.dart"; | ||
import "../../../config/ttl_config.dart"; | ||
import "getGuideDetails.graphql.dart"; | ||
|
||
part "guide_detail_view_repository.g.dart"; | ||
|
||
typedef GuideDetails = Query$GetGuideDetails$FAQ_Types_by_id; | ||
typedef _GetGuideDetails = WatchOptions$Query$GetGuideDetails; | ||
typedef _Vars = Variables$Query$GetGuideDetails; | ||
@riverpod | ||
Stream<GuideDetails?> guideDetailsRepository( | ||
GuideDetailsRepositoryRef ref, | ||
String id, | ||
) async* { | ||
final stream = ref.watchQueryWithCache( | ||
_GetGuideDetails( | ||
eagerlyFetchResults: true, | ||
variables: _Vars(id: id), | ||
), | ||
TtlKey.guideDetailsRepository, | ||
); | ||
yield* stream.map((event) => event?.FAQ_Types_by_id); | ||
} |
71 changes: 71 additions & 0 deletions
71
lib/features/guide_detail_view/widgets/my_expansion_tile.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,71 @@ | ||
import "package:flutter/material.dart"; | ||
|
||
import "../../../config/ui_config.dart"; | ||
import "../../../theme/app_theme.dart"; | ||
import "../../../widgets/loading_widgets/shimmer_loading.dart"; | ||
|
||
class MyExpansionTile extends StatelessWidget { | ||
final String title; | ||
final String description; | ||
|
||
const MyExpansionTile({ | ||
required this.title, | ||
required this.description, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: const EdgeInsets.symmetric( | ||
horizontal: GuideDetailViewConfig.paddingMedium, | ||
), | ||
child: ExpansionTile( | ||
mikolaj-jalocha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
title: Text(title, style: context.textTheme.title), | ||
backgroundColor: context.colorTheme.greyLight, | ||
collapsedBackgroundColor: context.colorTheme.greyLight, | ||
shape: RoundedRectangleBorder( | ||
borderRadius: | ||
BorderRadius.circular(GuideDetailViewConfig.borderRadius), | ||
), | ||
collapsedShape: RoundedRectangleBorder( | ||
borderRadius: | ||
BorderRadius.circular(GuideDetailViewConfig.borderRadius), | ||
), | ||
iconColor: context.colorTheme.orangePomegranade, | ||
collapsedIconColor: context.colorTheme.orangePomegranade, | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.symmetric( | ||
vertical: GuideDetailViewConfig.paddingSmall, | ||
), | ||
child: ListTile( | ||
title: Text( | ||
description, | ||
style: context.textTheme.body.copyWith(fontSize: 14), | ||
), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} | ||
|
||
class MyExpansionTileLoading extends StatelessWidget { | ||
const MyExpansionTileLoading(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ShimmerLoadingItem( | ||
child: Container( | ||
decoration: BoxDecoration( | ||
color: Colors.white, | ||
borderRadius: | ||
BorderRadius.circular(GuideDetailViewConfig.borderRadius), | ||
), | ||
width: double.infinity, | ||
height: 45, | ||
), | ||
); | ||
} | ||
} |
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
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
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.
oh damn. ListView inside a ListView and it works. Crazy but very good job :)
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.
That's because Stack Overflow and those 2 magic lines:
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
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.
Yeah I know but still crazy