-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(digital-guide): add lodge section (#545)
* feat(digital-guide): setup data layer * feat(digital-guide): setup presentation layer * feat(digital-guide): docs * apply pr suggestion Co-authored-by: Szymon Kowaliński <szymon@kowalinski.dev> * feta(digital-guide): apply pr suggestion --------- Co-authored-by: Szymon Kowaliński <szymon@kowalinski.dev>
- Loading branch information
1 parent
a44f76e
commit 3abd001
Showing
6 changed files
with
168 additions
and
2 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
lib/features/digital_guide_view/tabs/lodge/data/models/digital_guide_lodge.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,38 @@ | ||
import "package:freezed_annotation/freezed_annotation.dart"; | ||
|
||
part "digital_guide_lodge.freezed.dart"; | ||
part "digital_guide_lodge.g.dart"; | ||
|
||
@freezed | ||
class DigitalGuideLodge with _$DigitalGuideLodge { | ||
const factory DigitalGuideLodge({ | ||
required int id, | ||
required DigitalGuideTranslationsLodge translations, | ||
@JsonKey(name: "images") required List<int>? imagesIds, | ||
}) = _DigitalGuideLodge; | ||
|
||
factory DigitalGuideLodge.fromJson(Map<String, dynamic> json) => | ||
_$DigitalGuideLodgeFromJson(json); | ||
} | ||
|
||
@freezed | ||
class DigitalGuideTranslationsLodge with _$DigitalGuideTranslationsLodge { | ||
const factory DigitalGuideTranslationsLodge({ | ||
required DigitalGuideTranslationLodge pl, | ||
}) = _DigitalGuideTranslationsLodge; | ||
|
||
factory DigitalGuideTranslationsLodge.fromJson(Map<String, dynamic> json) => | ||
_$DigitalGuideTranslationsLodgeFromJson(json); | ||
} | ||
|
||
@freezed | ||
class DigitalGuideTranslationLodge with _$DigitalGuideTranslationLodge { | ||
@JsonSerializable(fieldRename: FieldRename.snake) | ||
const factory DigitalGuideTranslationLodge({ | ||
required String location, | ||
required String workingDaysAndHours, | ||
required String comment, | ||
}) = _DigitalGuideTranslationLodge; | ||
factory DigitalGuideTranslationLodge.fromJson(Map<String, dynamic> json) => | ||
_$DigitalGuideTranslationLodgeFromJson(json); | ||
} |
25 changes: 25 additions & 0 deletions
25
lib/features/digital_guide_view/tabs/lodge/data/repository/lodges_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,25 @@ | ||
import "package:fast_immutable_collections/fast_immutable_collections.dart"; | ||
import "package:flutter_riverpod/flutter_riverpod.dart"; | ||
import "package:riverpod_annotation/riverpod_annotation.dart"; | ||
|
||
import "../../../../data/api/digital_guide_get_and_cache.dart"; | ||
import "../../../../data/models/digital_guide_response.dart"; | ||
import "../models/digital_guide_lodge.dart"; | ||
|
||
part "lodges_repository.g.dart"; | ||
|
||
@riverpod | ||
Future<IList<DigitalGuideLodge>> lodgesRepository( | ||
Ref ref, | ||
DigitalGuideResponse building, | ||
) async { | ||
final endpoint = "lodges/?building=${building.id}"; | ||
return ref.getAndCacheDataFromDigitalGuide( | ||
endpoint, | ||
(List<dynamic> json) => json | ||
.whereType<Map<String, dynamic>>() | ||
.map(DigitalGuideLodge.fromJson) | ||
.toIList(), | ||
onRetry: () => ref.invalidateSelf(), | ||
); | ||
} |
89 changes: 89 additions & 0 deletions
89
...igital_guide_view/tabs/lodge/presentation/digital_guide_lodge_expansion_tile_content.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,89 @@ | ||
import "package:fast_immutable_collections/fast_immutable_collections.dart"; | ||
import "package:flutter/material.dart"; | ||
import "package:flutter_riverpod/flutter_riverpod.dart"; | ||
|
||
import "../../../../../config/ui_config.dart"; | ||
import "../../../../../theme/app_theme.dart"; | ||
import "../../../../../utils/context_extensions.dart"; | ||
import "../../../../../widgets/my_error_widget.dart"; | ||
import "../../../data/models/digital_guide_response.dart"; | ||
import "../../../presentation/widgets/digital_guide_photo_row.dart"; | ||
import "../data/models/digital_guide_lodge.dart"; | ||
import "../data/repository/lodges_repository.dart"; | ||
|
||
class DigitalGuideLodgeExpansionTileContent extends ConsumerWidget { | ||
const DigitalGuideLodgeExpansionTileContent(this.digitalGuideResponse); | ||
|
||
final DigitalGuideResponse digitalGuideResponse; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final lodgeResponse = | ||
ref.watch(lodgesRepositoryProvider(digitalGuideResponse)); | ||
return lodgeResponse.when( | ||
data: (data) => | ||
_DigitalGuideLodgeExpansionTileContent(lodge: data.firstOrNull), | ||
error: (error, _) => MyErrorWidget(error), | ||
loading: () => const Center( | ||
child: CircularProgressIndicator(), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class _DigitalGuideLodgeExpansionTileContent extends StatelessWidget { | ||
final DigitalGuideLodge? lodge; | ||
|
||
const _DigitalGuideLodgeExpansionTileContent({ | ||
required this.lodge, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (lodge == null) { | ||
return Center(child: Text(context.localize.no_lodge_in_the_building)); | ||
} | ||
final lodgeInformation = lodge!.translations.pl; | ||
return Padding( | ||
padding: const EdgeInsets.all(DigitalGuideConfig.paddingMedium), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text(context.localize.localization, style: context.textTheme.title), | ||
Padding( | ||
padding: const EdgeInsets.symmetric( | ||
vertical: DigitalGuideConfig.heightSmall, | ||
), | ||
child: Text(lodgeInformation.location), | ||
), | ||
Text(context.localize.working_hours, style: context.textTheme.title), | ||
const SizedBox( | ||
height: DigitalGuideConfig.heightSmall, | ||
), | ||
Text(lodgeInformation.workingDaysAndHours), | ||
const SizedBox( | ||
height: DigitalGuideConfig.heightSmall, | ||
), | ||
if (lodgeInformation.comment.isNotEmpty) | ||
Padding( | ||
padding: const EdgeInsets.only( | ||
bottom: DigitalGuideConfig.paddingSmall, | ||
), | ||
child: Text( | ||
context.localize.additional_information, | ||
style: context.textTheme.title, | ||
), | ||
), | ||
Text(lodgeInformation.comment), | ||
if (lodgeInformation.comment.isNotEmpty) | ||
const SizedBox( | ||
height: DigitalGuideConfig.heightMedium, | ||
), | ||
DigitalGuidePhotoRow( | ||
imagesIDs: lodge!.imagesIds?.toIList() ?? const IList.empty(), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
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