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: evacuation screen and small refactor of file structure in digit… #489

Merged
merged 14 commits into from
Dec 18, 2024
4 changes: 4 additions & 0 deletions lib/config/ui_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,13 @@ abstract class DigitalGuideConfig {
EdgeInsets.symmetric(vertical: 24, horizontal: 24);
static const borderRadiusMedium = 8.0;
static const heightSmall = 8.0;
static const heightMedium = 16.0;
static const heightBig = 24.0;
static const heightHuge = 48.0;
static const mediumButtonPadding =
EdgeInsets.symmetric(vertical: 8, horizontal: 14);
static const paddingMedium = 16.0;
static const borderColor = Color(0x8077859D);
}
simon-the-shark marked this conversation as resolved.
Show resolved Hide resolved

abstract class AlertDialogConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class DigitalGuideResponse with _$DigitalGuideResponse {
required List<String> phoneNumbers,
@JsonKey(name: "surrounding") required int surroundingId,
required List<int> images,
@JsonKey(name: "evacuation_map") required int evacuationMapId,
String? imageUrl,
}) = _DigitalGuideResponse;

Expand All @@ -78,6 +79,8 @@ class DigitalGuideTranslation with _$DigitalGuideTranslation {
required String name,
@JsonKey(name: "extended_name") required String extendedName,
required String address,
@JsonKey(name: "evacuation_description")
required String evacuationDescription,
}) = _DigitalGuideTranslation;

factory DigitalGuideTranslation.fromJson(Map<String, dynamic> json) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import "dart:core";

import "package:fast_immutable_collections/fast_immutable_collections.dart";

import "../../tabs/entraces/data/models/digital_guide_entrace.dart";
import "../../tabs/evacuation/data/models/digital_guide_evacuation.dart";
import "digital_guide_response.dart";

class DigitalGuideResponseExtended {
Expand All @@ -19,6 +23,8 @@ class DigitalGuideResponseExtended {
required this.surroundingId,
required this.images,
required this.imageUrl,
required this.entraces,
required this.evacuation,
});

final int id;
Expand All @@ -36,10 +42,14 @@ class DigitalGuideResponseExtended {
final int surroundingId;
final List<int> images;
final String? imageUrl;
final DigitalGuideEvacuation evacuation;
final IList<DigitalGuideEntrace> entraces;

factory DigitalGuideResponseExtended.fromDigitalGuideResponse({
required DigitalGuideResponse digitalGuideResponse,
required String? imageUrl,
required DigitalGuideEvacuation evacuation,
required IList<DigitalGuideEntrace> entraces,
}) {
return DigitalGuideResponseExtended(
id: digitalGuideResponse.id,
Expand All @@ -57,6 +67,8 @@ class DigitalGuideResponseExtended {
surroundingId: digitalGuideResponse.surroundingId,
images: digitalGuideResponse.images,
imageUrl: imageUrl,
entraces: entraces,
evacuation: evacuation,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@ import "package:flutter/foundation.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:riverpod_annotation/riverpod_annotation.dart";

import "../../../../../api_base_rest/client/dio_client.dart";
import "../../../../../config/env.dart";
import "../../../../api_base_rest/client/dio_client.dart";
import "../../../../config/env.dart";
import "../../tabs/entraces/data/repository/entraces_repository.dart";
import "../../tabs/evacuation/data/repository/evacuation_repository.dart";
import "../models/digital_guide_response.dart";
import "../models/digital_guide_response_extended.dart";

part "digital_guide_repository.g.dart";

@riverpod
Future<DigitalGuideResponseExtended> getDigitalGuideData(
Future<DigitalGuideResponseExtended> getDigitalGuideDataExtended(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know who changed the convention, but I liked "digitalGuideRepository' convention more than 'getX' - but maybe that's just me

Ref ref,
int id,
) async {
final digitalGuideUrl = "${Env.digitalGuideUrl}/buildings/$id";
final dio = ref.read(restClientProvider);
dio.options.headers["Authorization"] =
"Token ${Env.digitalGuideAuthorizationToken}";
final response = await dio.get(digitalGuideUrl);
final digitalGuideResponse =
DigitalGuideResponse.fromJson(response.data as Map<String, dynamic>);
final imageUrl = await getImageUrl(ref, digitalGuideResponse.images[0]);
await ref.watch(getDigitalGuideBuildingDataProvider(id).future);
final imageUrl = await ref
.watch(getImageUrlProvider(digitalGuideResponse.images[0]).future);
final evacuation =
await ref.watch(getDigitalGuideEvacuationProvider(id).future);
final entraces = await ref
.watch(getDigitalGuideEntracesProvider(digitalGuideResponse.id).future);
return DigitalGuideResponseExtended.fromDigitalGuideResponse(
digitalGuideResponse: digitalGuideResponse,
imageUrl: imageUrl,
evacuation: evacuation,
entraces: entraces,
);
}

Expand All @@ -49,3 +53,18 @@ Future<String?> getImageUrl(Ref ref, int id) async {

return imageUrl;
}

@riverpod
Future<DigitalGuideResponse> getDigitalGuideBuildingData(
Ref ref,
int id,
) async {
final digitalGuideUrl = "${Env.digitalGuideUrl}/buildings/$id";
final dio = ref.read(restClientProvider);
dio.options.headers["Authorization"] =
"Token ${Env.digitalGuideAuthorizationToken}";
final response = await dio.get(digitalGuideUrl);
final digitalGuideResponse =
DigitalGuideResponse.fromJson(response.data as Map<String, dynamic>);
return digitalGuideResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ 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 "../../../../gen/assets.gen.dart";
import "../../../../utils/context_extensions.dart";
import "../../../../utils/determine_contact_icon.dart";
import "../../../../widgets/detail_views/contact_section.dart";
import "../../../../widgets/detail_views/detail_view_app_bar.dart";
import "../../../../widgets/my_cached_image.dart";
import "../../../../widgets/my_error_widget.dart";
import "../../../config/ui_config.dart";
import "../../../gen/assets.gen.dart";
import "../../../utils/context_extensions.dart";
import "../../../utils/determine_contact_icon.dart";
import "../../../widgets/detail_views/contact_section.dart";
import "../../../widgets/detail_views/detail_view_app_bar.dart";
import "../../../widgets/my_cached_image.dart";
import "../../../widgets/my_error_widget.dart";
import "../data/models/digital_guide_response_extended.dart";
import "../data/repository/digital_guide_repository.dart";
import "widgets/accessibility_button.dart";
Expand All @@ -29,7 +29,8 @@ class DigitalGuideView extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final asyncDigitalGuideData = ref.watch(getDigitalGuideDataProvider(id));
final asyncDigitalGuideData =
ref.watch(getDigitalGuideDataExtendedProvider(id));
// question: Should the app bar appear during loading or when there's an error?
// Now it doesn't, neither does it appear on SKS menu screen
return asyncDigitalGuideData.when(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "package:flutter/material.dart";

import "../../../../../config/ui_config.dart";
import "../../../../../theme/app_theme.dart";
import "../../../../config/ui_config.dart";
import "../../../../theme/app_theme.dart";

class AccessibilityButton extends StatelessWidget {
@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import "package:flutter/gestures.dart";
import "package:flutter/widgets.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";

import "../../../../../config/ui_config.dart";
import "../../../../../theme/app_theme.dart";
import "../../../../../utils/context_extensions.dart";
import "../../../../../utils/launch_url_util.dart";
import "../../../../config/ui_config.dart";
import "../../../../theme/app_theme.dart";
import "../../../../utils/context_extensions.dart";
import "../../../../utils/launch_url_util.dart";

class DigitalGuideDataSourceLink extends ConsumerWidget {
@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import "package:flutter/material.dart";
import "package:flutter/widgets.dart";

import "../../../../../utils/context_extensions.dart";
import "../../../../../widgets/my_expansion_tile.dart";
import "../../../amenities/presentation/amenities_expansion_tile_content.dart";
import "../../../localization/presentation/localization_expansion_tile_content.dart";
import "../../../surrounding/presentation/surroundings_expansion_tile_content.dart";
import "../../../../utils/context_extensions.dart";
import "../../../../widgets/my_expansion_tile.dart";
import "../../data/models/digital_guide_response_extended.dart";
import "../../localization/presentation/localization_expansion_tile_content.dart";
import "../../tabs/amenities/presentation/amenities_expansion_tile_content.dart";
import "../../tabs/evacuation/evacuation_widget.dart";
import "../../tabs/surrounding/presentation/surroundings_expansion_tile_content.dart";

typedef TileContent = ({String title, List<Widget> content});

Expand Down Expand Up @@ -70,7 +71,11 @@ class DigitalGuideFeaturesSection extends StatelessWidget {
),
(
title: context.localize.evacuation,
content: [LocalizationExpansionTileContent()],
content: [
EvacuationWidget(
digitalGuideResponseExtended: digitalGuideResponseExtended,
),
],
),
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import "package:flutter/material.dart";

import "../../../../config/ui_config.dart";
import "../../../../theme/app_theme.dart";

class DigitalGuideNavLink extends StatelessWidget {
const DigitalGuideNavLink({
super.key,
required this.onTap,
required this.text,
});

final VoidCallback onTap;
final String text;

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Container(
padding: DigitalGuideConfig.mediumButtonPadding,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(DigitalGuideConfig.borderRadiusMedium),
border: Border.all(
color: DigitalGuideConfig.borderColor,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
text,
style: context.textTheme.title,
),
Icon(
Icons.arrow_forward_ios,
color: context.colorTheme.blueAzure,
),
],
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "package:flutter/widgets.dart";

import "../../../../../config/ui_config.dart";
import "../../../../config/ui_config.dart";

class HeadlinesSection extends StatelessWidget {
const HeadlinesSection({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ 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/context_extensions.dart";
import "../../../../../utils/launch_url_util.dart";
import "../../../../config/ui_config.dart";
import "../../../../theme/app_theme.dart";
import "../../../../utils/context_extensions.dart";
import "../../../../utils/launch_url_util.dart";

class ReportChangeButton extends ConsumerWidget {
@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:flutter/widgets.dart";

import "../../../../gen/assets.gen.dart";
import "../../../../utils/context_extensions.dart";
import "../../../../utils/determine_contact_icon.dart";
import "../../../../widgets/detail_views/contact_section.dart";
import "../../general_info/data/models/digital_guide_response_extended.dart";
import "../../../../../gen/assets.gen.dart";
import "../../../../../utils/context_extensions.dart";
import "../../../../../utils/determine_contact_icon.dart";
import "../../../../../widgets/detail_views/contact_section.dart";
import "../../../data/models/digital_guide_response_extended.dart";

class AmenitiesExpansionTileContent extends StatelessWidget {
const AmenitiesExpansionTileContent({
Expand Down
tomasz-trela marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import "package:freezed_annotation/freezed_annotation.dart";

part "digital_guide_entrace.freezed.dart";
part "digital_guide_entrace.g.dart";

@freezed
class DigitalGuideEntrace with _$DigitalGuideEntrace {
const factory DigitalGuideEntrace({
required int id,
required DigitalGuideTranslationsEntrace translations,
}) = _DigitalGuideEntrace;

factory DigitalGuideEntrace.fromJson(Map<String, dynamic> json) =>
_$DigitalGuideEntraceFromJson(json);
}

@freezed
class DigitalGuideTranslationsEntrace with _$DigitalGuideTranslationsEntrace {
const factory DigitalGuideTranslationsEntrace({
required DigitalGuideTranslationEntrace pl,
}) = _DigitalGuideTranslationsEntrace;

factory DigitalGuideTranslationsEntrace.fromJson(Map<String, dynamic> json) =>
_$DigitalGuideTranslationsEntraceFromJson(json);
}

@freezed
class DigitalGuideTranslationEntrace with _$DigitalGuideTranslationEntrace {
const factory DigitalGuideTranslationEntrace({
required String name,
required String location,
}) = _DigitalGuideTranslationEntrace;

factory DigitalGuideTranslationEntrace.fromJson(Map<String, dynamic> json) =>
_$DigitalGuideTranslationEntraceFromJson(json);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:riverpod_annotation/riverpod_annotation.dart";

import "../../../../../../../api_base_rest/client/dio_client.dart";
import "../../../../../../../config/env.dart";

import "../models/digital_guide_entrace.dart";

part "entraces_repository.g.dart";

@riverpod
Future<IList<DigitalGuideEntrace>> getDigitalGuideEntraces(
Ref ref,
int buildingId,
) async {
final digitalGuideEntranceUrl =
"${Env.digitalGuideUrl}/entrances/?building=$buildingId";
final dio = ref.read(restClientProvider);
dio.options.headers["Authorization"] =
"Token ${Env.digitalGuideAuthorizationToken}";

final response = await dio.get(digitalGuideEntranceUrl);
final data = response.data as List<dynamic>;
final entrances = data
.map((json) => DigitalGuideEntrace.fromJson(json as Map<String, dynamic>))
.toIList();

return entrances;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import "package:freezed_annotation/freezed_annotation.dart";

part "digital_guide_evacuation.freezed.dart";
part "digital_guide_evacuation.g.dart";

@freezed
class DigitalGuideEvacuation with _$DigitalGuideEvacuation {
const factory DigitalGuideEvacuation({
required String evacuationDescription,
required String? evacuationMapUrl,
}) = _DigitalGuideEvacuation;

factory DigitalGuideEvacuation.fromJson(Map<String, dynamic> json) =>
_$DigitalGuideEvacuationFromJson(json);
}
Loading
Loading