Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions frontend/ui/lib/services/places_services_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,31 @@ class PlacesApiServices {
return completer.future;
}

Future<String> getGoodBannerPhoto(String placeId) {
Completer<String> completer = Completer();
final request = PlaceDetailsRequest()..placeId = placeId;
placesService.getDetails(request, (result, status) async {
if (status == PlacesServiceStatus.OK) {
num widthHeightRatio = 1;
int idealIndex = 0;

for (int i = 0; i < result.photos.length; i++) {
PlacePhoto photo = result.photos[i];
if (photo.width / photo.height > widthHeightRatio) {
widthHeightRatio = photo.width/photo.height;
idealIndex = i;
}
}

completer.complete(result.photos[idealIndex].getUrl(PhotoOptions()));
}
else {
completer.complete(null);
}
});
return completer.future;
}

Future<List<PlaceWrapper>> getNearbyPlaces(
TripService tripService, String tripId) async {
Completer<List<PlaceWrapper>> completer = Completer();
Expand Down
77 changes: 57 additions & 20 deletions frontend/ui/lib/widgets/place_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ typedef _OnLoad = Future<List<PlaceBlockWidget>> Function();
class PlaceListFromServiceWidget extends StatelessWidget {
final Trip trip;
final String pageName;
final PlacesApiServices placesApiServices;
final _OnLoad getPlaceBlockWidgets;

PlaceListFromServiceWidget(
this.trip, this.pageName, this.getPlaceBlockWidgets);
this.trip, this.pageName, this.placesApiServices, this.getPlaceBlockWidgets);

@override
Widget build(BuildContext context) {
return FutureBuilder(
future: getPlaceBlockWidgets.call(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return PlaceListWidget(trip, pageName, snapshot.data);
return PlaceListWidgetWithImage(trip, pageName, placesApiServices, snapshot.data);
}
if (snapshot.hasError) {
Scaffold.of(context).showSnackBar(SnackBar(
Expand All @@ -41,32 +42,68 @@ class PlaceListFromServiceWidget extends StatelessWidget {
}
}

class PlaceListWidget extends StatelessWidget {
class PlaceListWidgetWithImage extends StatelessWidget {
final Trip trip;
final String pageName;
final PlacesApiServices placesApiServices;
final List<PlaceBlockWidget> placeBlocks;

PlaceListWidget(this.trip, this.pageName, this.placeBlocks);
PlaceListWidgetWithImage(this.trip, this.pageName, this.placesApiServices, this.placeBlocks);

@override
Widget build(BuildContext context) {
return Container(
color: Theme.of(context).scaffoldBackgroundColor,
child: CustomScrollView(
slivers: [
SliverAppBar(
pinned: true,
floating: true,
snap: true,
expandedHeight: 250.0,
automaticallyImplyLeading: false, //Gets rid of appBar back arrow
flexibleSpace: FlexibleSpaceBar(
title: Text(pageName),
background: Image.network(
'https://www.gannett-cdn.com/presto/2019/02/01/USAT/2af52e69-3fd1-4438-99d7-487a9b51d03c-GettyImages-878868924.jpg',
fit: BoxFit.cover,
), //Everybackground is seattle
return FutureBuilder(
future: placesApiServices.getGoodBannerPhoto(trip.placesApiPlaceId),
builder: (context, snapshot) {
if (snapshot.hasData) {
if (snapshot.data == null) {
return PlaceListWidget(trip, pageName, 'https://www.gannett-cdn.com/presto/2019/02/01/USAT/2af52e69-3fd1-4438-99d7-487a9b51d03c-GettyImages-878868924.jpg', placeBlocks);
}
return PlaceListWidget(trip, pageName, snapshot.data, placeBlocks);
}
if (snapshot.hasError) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text("Error getting trip"),
action: SnackBarAction(
label: "Retry",
onPressed: () {}, //TODO: Make retry button actually work.
),
));
return Container();
}
return CircularProgressIndicator();
},
);
}


}

class PlaceListWidget extends StatelessWidget {
final Trip trip;
final String pageName;
final String photoUrl;
final List<PlaceBlockWidget> placeBlocks;

PlaceListWidget(this.trip, this.pageName, this.photoUrl, this.placeBlocks);

@override
Widget build(BuildContext context) {
print(photoUrl);
return CustomScrollView(
slivers: [
SliverAppBar(
pinned: true,
floating: true,
snap: true,
expandedHeight: 250.0,
automaticallyImplyLeading: false, //Gets rid of appBar back arrow
flexibleSpace: FlexibleSpaceBar(
title: Text(pageName),
background: Image.network(
photoUrl,
fit: BoxFit.cover,
), //Everybackground is seattle
),
SliverList(
delegate: SliverChildBuilderDelegate(
Expand Down
8 changes: 4 additions & 4 deletions frontend/ui/lib/widgets/recommended_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ class RecommendedWidgetFromService extends StatelessWidget {
class RecommendedWidget extends StatelessWidget {
final TripService tripService;
final PlaceVisitService placeVisitService;
final PlacesApiServices placesApiService;
final PlacesApiServices placesApiServices;
final Trip trip;

RecommendedWidget(this.tripService, this.placeVisitService,
this.placesApiService, this.trip);
this.placesApiServices, this.trip);

Future<List<PlaceBlockWidget>> getNearbyPlaceBlockWidgets() async {
List<PlaceWrapper> placeWrappers =
await placesApiService.getNearbyPlaces(tripService, trip.id);
await placesApiServices.getNearbyPlaces(tripService, trip.id);
List<PlaceVisit> placeVisits = placeWrappers
.map((placeWrapper) => PlaceVisit(
name: placeWrapper.name,
Expand All @@ -76,6 +76,6 @@ class RecommendedWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PlaceListFromServiceWidget(
trip, 'Recommended Places To Visit', getNearbyPlaceBlockWidgets);
trip, 'Recommended Places To Visit', placesApiServices, getNearbyPlaceBlockWidgets);
}
}
2 changes: 1 addition & 1 deletion frontend/ui/lib/widgets/trip_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TripViewWidgetFromService extends StatelessWidget {
builder: (context, snapshot) {
if (snapshot.hasData) {
return PlaceListFromServiceWidget(
snapshot.data, snapshot.data.name, getPlaceBlockWidgets);
snapshot.data, snapshot.data.name, placesApiServices, getPlaceBlockWidgets);
}
if (snapshot.hasError) {
Scaffold.of(context).showSnackBar(SnackBar(
Expand Down
21 changes: 14 additions & 7 deletions frontend/ui/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
version: "2.4.2"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
charcode:
dependency: transitive
description:
Expand All @@ -35,7 +42,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
version: "1.14.13"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -127,7 +134,7 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.6"
version: "0.12.8"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -195,7 +202,7 @@ packages:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
version: "1.9.5"
stream_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -223,14 +230,14 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.16"
version: "0.2.17"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.2.0"
url_launcher:
dependency: "direct main"
description:
Expand Down Expand Up @@ -281,5 +288,5 @@ packages:
source: hosted
version: "2.0.8"
sdks:
dart: ">=2.7.0 <3.0.0"
dart: ">=2.9.0-14.0.dev <3.0.0"
flutter: ">=1.12.13+hotfix.6 <2.0.0"