6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 85de2a1b
Changed files
.../hotel_information/models/facilities.g.dart | 20 +++------ .../hotel_information/models/hotel.g.dart | 8 ++-- .../hotel_information/models/parking_info.g.dart | 4 +- .../hotel_information/models/restaurant.g.dart | 4 +- .../.generated/hotel_information/models/spa.g.dart | 4 +- .../authentication/authentication_repository.dart | 1 + .../components/hotel_information_menu.dart | 49 ++++++---------------- .../lib/hotel_information/models/facilities.dart | 24 +++++++++-- .../lib/hotel_information/models/hotel.dart | 2 +- .../lib/hotel_information/models/parking_info.dart | 10 ++--- .../lib/hotel_information/models/restaurant.dart | 7 ++-- .../lib/hotel_information/models/spa.dart | 10 ++--- .../repository/hotel_information_repository.dart | 6 ++- 13 files changed, 70 insertions(+), 79 deletions(-)
Diff
diff --git a/comwell_key_app/lib/.generated/hotel_information/models/facilities.g.dart b/comwell_key_app/lib/.generated/hotel_information/models/facilities.g.dart
index 2046e285..1538b704 100644
--- a/comwell_key_app/lib/.generated/hotel_information/models/facilities.g.dart
+++ b/comwell_key_app/lib/.generated/hotel_information/models/facilities.g.dart
@@ -6,19 +6,9 @@ part of '../../../hotel_information/models/facilities.dart';
// JsonSerializableGenerator
// **************************************************************************
-Facilities _$FacilitiesFromJson(Map<String, dynamic> json) => Facilities(
- restaurants: (json['restaurants'] as List<dynamic>)
- .map((e) => Restaurant.fromJson(e as Map<String, dynamic>))
- .toList(),
- spas: (json['spas'] as List<dynamic>)
- .map((e) => Spa.fromJson(e as Map<String, dynamic>))
- .toList(),
- parking: ParkingInfo.fromJson(json['parking'] as Map<String, dynamic>),
- );
-
-Map<String, dynamic> _$FacilitiesToJson(Facilities instance) =>
- <String, dynamic>{
- 'restaurants': instance.restaurants,
- 'spas': instance.spas,
- 'parking': instance.parking,
+Map<String, dynamic> _$FacilityToJson(Facility instance) => <String, dynamic>{
+ 'type': instance.type,
+ 'title': instance.title,
+ 'subtitle': instance.subtitle,
+ 'iconPath': instance.iconPath,
};
diff --git a/comwell_key_app/lib/.generated/hotel_information/models/hotel.g.dart b/comwell_key_app/lib/.generated/hotel_information/models/hotel.g.dart
index 85ef2105..103eae9b 100644
--- a/comwell_key_app/lib/.generated/hotel_information/models/hotel.g.dart
+++ b/comwell_key_app/lib/.generated/hotel_information/models/hotel.g.dart
@@ -6,7 +6,7 @@ part of '../../../hotel_information/models/hotel.dart';
// JsonSerializableGenerator
// **************************************************************************
-Hotel _$HotelFromJson(Map<String, dynamic> json) => Hotel(
+Hotel _$HotelFromJson(Map json) => Hotel(
id: json['id'] as String,
name: json['name'] as String,
address: json['address'] as String,
@@ -14,8 +14,8 @@ Hotel _$HotelFromJson(Map<String, dynamic> json) => Hotel(
country: json['country'] as String,
starRating: (json['starRating'] as num).toInt(),
image: json['image'] as String,
- facilities:
- Facilities.fromJson(json['facilities'] as Map<String, dynamic>),
+ facilities: (json['facilities'] as List<dynamic>)
+ .map((e) => Facility.fromJson(Map<String, dynamic>.from(e as Map))),
);
Map<String, dynamic> _$HotelToJson(Hotel instance) => <String, dynamic>{
@@ -26,5 +26,5 @@ Map<String, dynamic> _$HotelToJson(Hotel instance) => <String, dynamic>{
'country': instance.country,
'starRating': instance.starRating,
'image': instance.image,
- 'facilities': instance.facilities,
+ 'facilities': instance.facilities.map((e) => e.toJson()).toList(),
};
diff --git a/comwell_key_app/lib/.generated/hotel_information/models/parking_info.g.dart b/comwell_key_app/lib/.generated/hotel_information/models/parking_info.g.dart
index a6a054c4..f083b85b 100644
--- a/comwell_key_app/lib/.generated/hotel_information/models/parking_info.g.dart
+++ b/comwell_key_app/lib/.generated/hotel_information/models/parking_info.g.dart
@@ -6,8 +6,9 @@ part of '../../../hotel_information/models/parking_info.dart';
// JsonSerializableGenerator
// **************************************************************************
-ParkingInfo _$ParkingInfoFromJson(Map<String, dynamic> json) => ParkingInfo(
+ParkingInfo _$ParkingInfoFromJson(Map json) => ParkingInfo(
title: json['title'] as String,
+ subtitle: json['subtitle'] as String,
description: json['description'] as String,
electricCharging: json['electricCharging'] as bool,
electricChargingTitle: json['electricChargingTitle'] as String,
@@ -18,6 +19,7 @@ ParkingInfo _$ParkingInfoFromJson(Map<String, dynamic> json) => ParkingInfo(
Map<String, dynamic> _$ParkingInfoToJson(ParkingInfo instance) =>
<String, dynamic>{
'title': instance.title,
+ 'subtitle': instance.subtitle,
'description': instance.description,
'electricCharging': instance.electricCharging,
'electricChargingTitle': instance.electricChargingTitle,
diff --git a/comwell_key_app/lib/.generated/hotel_information/models/restaurant.g.dart b/comwell_key_app/lib/.generated/hotel_information/models/restaurant.g.dart
index 2e9bd771..2c1ad32d 100644
--- a/comwell_key_app/lib/.generated/hotel_information/models/restaurant.g.dart
+++ b/comwell_key_app/lib/.generated/hotel_information/models/restaurant.g.dart
@@ -6,11 +6,12 @@ part of '../../../hotel_information/models/restaurant.dart';
// JsonSerializableGenerator
// **************************************************************************
-Restaurant _$RestaurantFromJson(Map<String, dynamic> json) => Restaurant(
+Restaurant _$RestaurantFromJson(Map json) => Restaurant(
name: json['name'] as String,
description: json['description'] as String,
imageUrl: json['imageUrl'] as String,
address: json['address'] as String,
+ subtitle: json['subtitle'] as String,
openingHours: json['openingHours'] as String,
phoneNumber: json['phoneNumber'] as String,
email: json['email'] as String,
@@ -18,6 +19,7 @@ Restaurant _$RestaurantFromJson(Map<String, dynamic> json) => Restaurant(
Map<String, dynamic> _$RestaurantToJson(Restaurant instance) =>
<String, dynamic>{
+ 'subtitle': instance.subtitle,
'name': instance.name,
'description': instance.description,
'imageUrl': instance.imageUrl,
diff --git a/comwell_key_app/lib/.generated/hotel_information/models/spa.g.dart b/comwell_key_app/lib/.generated/hotel_information/models/spa.g.dart
index 714a5096..948ee666 100644
--- a/comwell_key_app/lib/.generated/hotel_information/models/spa.g.dart
+++ b/comwell_key_app/lib/.generated/hotel_information/models/spa.g.dart
@@ -6,14 +6,16 @@ part of '../../../hotel_information/models/spa.dart';
// JsonSerializableGenerator
// **************************************************************************
-Spa _$SpaFromJson(Map<String, dynamic> json) => Spa(
+Spa _$SpaFromJson(Map json) => Spa(
title: json['title'] as String,
+ subtitle: json['subtitle'] as String,
description: json['description'] as String,
image: json['image'] as String,
);
Map<String, dynamic> _$SpaToJson(Spa instance) => <String, dynamic>{
'title': instance.title,
+ 'subtitle': instance.subtitle,
'description': instance.description,
'image': instance.image,
};
diff --git a/comwell_key_app/lib/authentication/authentication_repository.dart b/comwell_key_app/lib/authentication/authentication_repository.dart
index cefd4d86..60eaeadf 100644
--- a/comwell_key_app/lib/authentication/authentication_repository.dart
+++ b/comwell_key_app/lib/authentication/authentication_repository.dart
@@ -32,6 +32,7 @@ class AuthenticationRepository {
Future<bool> doesTokenExist() async {
String? refreshtoken = await secureStorage.read(constants.refreshToken);
String? accesstoken = await secureStorage.read(constants.accessToken);
+ print("qqq $accesstoken");
if (refreshtoken != null && accesstoken != null) {
return true;
diff --git a/comwell_key_app/lib/hotel_information/components/hotel_information_menu.dart b/comwell_key_app/lib/hotel_information/components/hotel_information_menu.dart
index 5f0ed9c0..655f1c4c 100644
--- a/comwell_key_app/lib/hotel_information/components/hotel_information_menu.dart
+++ b/comwell_key_app/lib/hotel_information/components/hotel_information_menu.dart
@@ -18,11 +18,6 @@ class HotelInformationMenu extends StatelessWidget {
final height = MediaQuery.of(context).size.height;
final cubit = context.read<HotelInformationCubit>();
final hotel = cubit.hotel;
- final hotelHasRestaurant =
- hotel.facilities.any((facility) => facility is Restaurant);
- final hotelHasSpa = hotel.facilities.any((facility) => facility is Spa);
- final hotelHasParking =
- hotel.facilities.any((facility) => facility is ParkingInfo);
return ListView(
shrinkWrap: true,
children: [
@@ -41,37 +36,19 @@ class HotelInformationMenu extends StatelessWidget {
Text(hotel.name,
style: Theme.of(context).textTheme.headlineLarge),
const SizedBox(height: 16),
- if (hotelHasRestaurant)
- HotelInformationListTile(
- iconPath: "assets/icons/ic_chefs_hat.svg",
- title: "hotel_information_page_menu_restaurants_title".tr(),
- subtitle:
- "hotel_information_page_menu_restaurants_subtitle".tr(),
- onClick: () {
- context.pushNamed(
- "${AppRoutes.hotelInformation.name}/${AppRoutes.restaurants.name}");
- },
- ),
- const SizedBox(height: 6),
- if (hotelHasSpa)
- HotelInformationListTile(
- iconPath: "assets/icons/ic_spa.svg",
- title: "hotel_information_page_menu_spa_title".tr(),
- subtitle: "hotel_information_page_menu_spa_subtitle".tr(),
- onClick: () {
- context.pushNamed(
- "${AppRoutes.hotelInformation.name}/${AppRoutes.spa.name}");
- },
- ),
- const SizedBox(height: 6),
- if (hotelHasParking)
- HotelInformationListTile(
- iconPath: "assets/icons/ic_car.svg",
- title: "hotel_information_page_menu_parking_title".tr(),
- subtitle: "",
- onClick: cubit.onParkingClicked,
- ),
- const SizedBox(height: 6),
+ ...hotel.facilities.map((facility) {
+ return Padding(
+ padding: const EdgeInsets.only(bottom: 6.0),
+ child: HotelInformationListTile(
+ iconPath: facility.iconPath,
+ title: facility.title,
+ subtitle: facility.subtitle,
+ onClick: () {
+ context.pushNamed("${AppRoutes.hotelInformation.name}/${facility.type}/");
+ },
+ ),
+ );
+ }),
HotelInformationListTile(
iconPath: "assets/icons/ic_info.svg",
title: "hotel_information_page_menu_other_info_title".tr(),
diff --git a/comwell_key_app/lib/hotel_information/models/facilities.dart b/comwell_key_app/lib/hotel_information/models/facilities.dart
index 7cf48532..bf492bfb 100644
--- a/comwell_key_app/lib/hotel_information/models/facilities.dart
+++ b/comwell_key_app/lib/hotel_information/models/facilities.dart
@@ -6,10 +6,28 @@ import 'package:json_annotation/json_annotation.dart';
part '../../.generated/hotel_information/models/facilities.g.dart';
-@JsonSerializable()
+@JsonSerializable(createFactory: false)
class Facility {
final String type;
+ final String title;
+ final String subtitle;
+ final String iconPath;
- Facility({required this.type});
-}
+ Facility({
+ required this.type,
+ required this.title,
+ required this.subtitle,
+ required this.iconPath,
+ });
+
+ factory Facility.fromJson(Json json) {
+ return switch (json["type"] as String) {
+ "restaurant" => Restaurant.fromJson(json),
+ "spa" => Spa.fromJson(json),
+ "parking" => ParkingInfo.fromJson(json),
+ _ => throw Exception("Unsupported facility type")
+ };
+ }
+ Json toJson() => _$FacilityToJson(this);
+}
diff --git a/comwell_key_app/lib/hotel_information/models/hotel.dart b/comwell_key_app/lib/hotel_information/models/hotel.dart
index cabffa72..8b184b74 100644
--- a/comwell_key_app/lib/hotel_information/models/hotel.dart
+++ b/comwell_key_app/lib/hotel_information/models/hotel.dart
@@ -26,7 +26,7 @@ class Hotel {
required this.facilities,
});
- factory Hotel.fromJson(Map<String, dynamic> json) => _$HotelFromJson(json);
+ factory Hotel.fromJson(Json json) => _$HotelFromJson(json);
Json toJson() => _$HotelToJson(this);
}
diff --git a/comwell_key_app/lib/hotel_information/models/parking_info.dart b/comwell_key_app/lib/hotel_information/models/parking_info.dart
index 2da8d124..81ff1067 100644
--- a/comwell_key_app/lib/hotel_information/models/parking_info.dart
+++ b/comwell_key_app/lib/hotel_information/models/parking_info.dart
@@ -6,22 +6,20 @@ part '../../.generated/hotel_information/models/parking_info.g.dart';
@JsonSerializable()
class ParkingInfo extends Facility {
- final String title;
final String description;
final bool electricCharging;
final String electricChargingTitle;
final String electricChargingDescription;
ParkingInfo({
- required this.title,
+ required super.title,
+ required super.subtitle,
required this.description,
required this.electricCharging,
required this.electricChargingTitle,
required this.electricChargingDescription,
- }) : super(type: "parking");
+ }) : super(type: "parking", iconPath: "assets/icons/ic_car.svg");
- Json toJson() => _$ParkingInfoToJson(this);
-
- factory ParkingInfo.fromJson(Map<String, dynamic> json) =>
+ factory ParkingInfo.fromJson(Json json) =>
_$ParkingInfoFromJson(json);
}
diff --git a/comwell_key_app/lib/hotel_information/models/restaurant.dart b/comwell_key_app/lib/hotel_information/models/restaurant.dart
index 3db54abe..71190951 100644
--- a/comwell_key_app/lib/hotel_information/models/restaurant.dart
+++ b/comwell_key_app/lib/hotel_information/models/restaurant.dart
@@ -19,13 +19,12 @@ class Restaurant extends Facility {
required this.description,
required this.imageUrl,
required this.address,
+ required super.subtitle,
required this.openingHours,
required this.phoneNumber,
required this.email,
- }) : super(type: "restaurant");
+ }) : super(type: "restaurant", title: name, iconPath: "assets/icons/ic_chefs_hat.svg");
- Json toJson() => _$RestaurantToJson(this);
-
- factory Restaurant.fromJson(Map<String, dynamic> json) =>
+ factory Restaurant.fromJson(Json json) =>
_$RestaurantFromJson(json);
}
diff --git a/comwell_key_app/lib/hotel_information/models/spa.dart b/comwell_key_app/lib/hotel_information/models/spa.dart
index 10330e99..68ab4389 100644
--- a/comwell_key_app/lib/hotel_information/models/spa.dart
+++ b/comwell_key_app/lib/hotel_information/models/spa.dart
@@ -6,17 +6,15 @@ part '../../.generated/hotel_information/models/spa.g.dart';
@JsonSerializable()
class Spa extends Facility {
- final String title;
final String description;
final String image;
Spa({
- required this.title,
+ required super.title,
+ required super.subtitle,
required this.description,
required this.image,
- }) : super(type: "spa");
+ }) : super(type: "spa", iconPath: "assets/icons/ic_spa.svg");
- Json toJson() => _$SpaToJson(this);
-
- factory Spa.fromJson(Map<String, dynamic> json) => _$SpaFromJson(json);
+ factory Spa.fromJson(Json json) => _$SpaFromJson(json);
}
diff --git a/comwell_key_app/lib/hotel_information/repository/hotel_information_repository.dart b/comwell_key_app/lib/hotel_information/repository/hotel_information_repository.dart
index 761681a9..7ad14b6a 100644
--- a/comwell_key_app/lib/hotel_information/repository/hotel_information_repository.dart
+++ b/comwell_key_app/lib/hotel_information/repository/hotel_information_repository.dart
@@ -1,4 +1,3 @@
-import 'package:comwell_key_app/hotel_information/models/facilities.dart';
import 'package:comwell_key_app/hotel_information/models/hotel.dart';
import 'package:comwell_key_app/hotel_information/models/parking_info.dart';
@@ -19,6 +18,7 @@ class HotelInformationRepository {
facilities: [
Restaurant(
name: 'Restaurant 1',
+ subtitle: "Visit",
description: 'Description 1',
imageUrl: 'assets/images/restaurant1.jpg',
address: 'Address 1',
@@ -27,6 +27,7 @@ class HotelInformationRepository {
email: 'email@comwell.com'),
Restaurant(
name: 'Restaurant 2',
+ subtitle: "Visit",
description: 'Description 1',
imageUrl: 'assets/images/restaurant1.jpg',
address: 'Address 2',
@@ -35,14 +36,17 @@ class HotelInformationRepository {
email: 'email@comwell.com'),
Spa(
title: 'Spa 1',
+ subtitle: "Visit",
description: 'Description 1',
image: 'assets/images/spa1.jpg'),
Spa(
title: 'Spa 2',
+ subtitle: "Visit",
description: 'Description 2',
image: 'assets/images/spa2.jpg'),
ParkingInfo(
title: 'Parking',
+ subtitle: "Park here",
description: 'Description',
electricCharging: true,
electricChargingTitle: 'Electric Charging',