Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into refactor/lazy-prov…
Browse files Browse the repository at this point in the history
…ider
  • Loading branch information
bdmendes committed Jul 12, 2023
2 parents 9304191 + c535768 commit dd041a1
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 119 deletions.
2 changes: 1 addition & 1 deletion uni/app_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.30+148
1.5.31+149
1 change: 1 addition & 0 deletions uni/lib/model/providers/faculty_locations_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO Implement this library.
51 changes: 19 additions & 32 deletions uni/lib/view/locations/locations.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:uni/model/entities/location_group.dart';
import 'package:uni/model/providers/lazy/faculty_locations_provider.dart';
import 'package:uni/model/request_status.dart';
import 'package:uni/view/common_widgets/page_title.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/general.dart';
import 'package:uni/view/common_widgets/request_dependent_widget_builder.dart';
import 'package:uni/view/lazy_consumer.dart';
import 'package:uni/view/locations/widgets/faculty_maps.dart';
import 'package:uni/view/locations/widgets/marker.dart';
import 'package:uni/view/locations/widgets/faculty_map.dart';

class LocationsPage extends StatefulWidget {
const LocationsPage({Key? key}) : super(key: key);
Expand Down Expand Up @@ -45,44 +44,32 @@ class LocationsPageView extends StatelessWidget {
final RequestStatus status;

const LocationsPageView(
{super.key, required this.locations, this.status = RequestStatus.none});
{super.key, required this.locations, required this.status});

@override
Widget build(BuildContext context) {
return Column(mainAxisSize: MainAxisSize.max, children: [
upperMenuContainer(context),
Container(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
height: MediaQuery.of(context).size.height * 0.75,
alignment: Alignment.center,
child: //TODO:: add support for multiple faculties
getMap(context),
)
width: MediaQuery.of(context).size.width * 0.95,
padding: const EdgeInsets.fromLTRB(0, 0, 0, 4.0),
child: PageTitle(name: 'Locais: ${getLocation()}')),
Container(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
height: MediaQuery.of(context).size.height * 0.75,
alignment: Alignment.center,
child: RequestDependentWidgetBuilder(
status: status,
builder: () => FacultyMap(faculty: "FEUP", locations: locations),
hasContentPredicate: locations.isNotEmpty,
onNullContent:
const Center(child: Text('Não existem locais disponíveis')),
)
// TODO: add support for multiple faculties
)
]);
}

Container upperMenuContainer(BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width * 0.95,
padding: const EdgeInsets.fromLTRB(0, 0, 0, 4.0),
child: PageTitle(name: 'Locais: ${getLocation()}'));
//TODO:: add support for multiple faculties
}

Widget getMap(BuildContext context) {
if (status != RequestStatus.successful) {
return const Center(child: CircularProgressIndicator());
}
return FacultyMaps.getFeupMap(locations);
}

String getLocation() {
return 'FEUP';
}

List<Marker> getMarkers() {
return locations.map((location) {
return LocationMarker(location.latlng, location);
}).toList();
}
}
35 changes: 35 additions & 0 deletions uni/lib/view/locations/widgets/faculty_map.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:latlong2/latlong.dart';
import 'package:uni/model/entities/location_group.dart';
import 'package:uni/view/locations/widgets/map.dart';


class FacultyMap extends StatelessWidget {
final String faculty;
final List<LocationGroup> locations;

const FacultyMap({Key? key, required this.faculty, required this.locations})
: super(key: key);

@override
Widget build(BuildContext context) {
switch (faculty) {
case 'FEUP':
return LocationsMap(
northEastBoundary: LatLng(41.17986, -8.59298),
southWestBoundary: LatLng(41.17670, -8.59991),
center: LatLng(41.17731, -8.59522),
locations: locations,
);
default:
return Container(); // Should not happen
}
}

static Color getFontColor(BuildContext context) {
return Theme.of(context).brightness == Brightness.light
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.tertiary;
}
}

30 changes: 0 additions & 30 deletions uni/lib/view/locations/widgets/faculty_maps.dart

This file was deleted.

39 changes: 29 additions & 10 deletions uni/lib/view/locations/widgets/floorless_marker_popup.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:uni/model/entities/location.dart';
import 'package:uni/model/entities/location_group.dart';
import 'package:uni/view/locations/widgets/faculty_maps.dart';
import 'package:uni/view/locations/widgets/faculty_map.dart';

class FloorlessLocationMarkerPopup extends StatelessWidget {
const FloorlessLocationMarkerPopup(this.locationGroup,
Expand All @@ -26,22 +26,41 @@ class FloorlessLocationMarkerPopup extends StatelessWidget {
spacing: 8,
children: (showId
? <Widget>[Text(locationGroup.id.toString())]
: <Widget>[]) +
buildLocations(context, locations),
: <Widget>[])
+ locations.map((location) => LocationRow(location: location))
.toList(),
)),
);
}

List<Widget> buildLocations(BuildContext context, List<Location> locations) {
return locations
.map((location) => Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(location.description(),
textAlign: TextAlign.left,
style: TextStyle(color: FacultyMaps.getFontColor(context)))
],
))
mainAxisSize: MainAxisSize.min,
children: [
Text(location.description(),
textAlign: TextAlign.left,
style: TextStyle(color: FacultyMap.getFontColor(context)))
],
))
.toList();
}
}

class LocationRow extends StatelessWidget {
final Location location;

const LocationRow({Key? key, required this.location}) : super(key: key);

@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(location.description(),
textAlign: TextAlign.left,
style: TextStyle(color: FacultyMap.getFontColor(context)))
],
);
}
}
10 changes: 3 additions & 7 deletions uni/lib/view/locations/widgets/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class LocationsMap extends StatelessWidget {
),
PopupMarkerLayerWidget(
options: PopupMarkerLayerOptions(
markers: _getMarkers(),
markers: locations.map((location) {
return LocationMarker(location.latlng, location);
}).toList(),
popupController: _popupLayerController,
popupAnimation: const PopupAnimation.fade(
duration: Duration(milliseconds: 400)),
Expand All @@ -82,12 +84,6 @@ class LocationsMap extends StatelessWidget {
),
]);
}

List<Marker> _getMarkers() {
return locations.map((location) {
return LocationMarker(location.latlng, location);
}).toList();
}
}

class CachedTileProvider extends TileProvider {
Expand Down
21 changes: 15 additions & 6 deletions uni/lib/view/locations/widgets/marker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:uni/model/entities/location.dart';
import 'package:uni/model/entities/location_group.dart';
import 'package:uni/view/locations/widgets/faculty_maps.dart';
import 'package:uni/view/locations/widgets/faculty_map.dart';

class LocationMarker extends Marker {
final LocationGroup locationGroup;
Expand All @@ -22,18 +22,27 @@ class LocationMarker extends Marker {
color: Theme.of(ctx).colorScheme.primary,
),
borderRadius: const BorderRadius.all(Radius.circular(20))),
child: getIcon(locationGroup.getLocationWithMostWeight(), ctx),
child: MarkerIcon(
location: locationGroup.getLocationWithMostWeight()
),
),
);
}

class MarkerIcon extends StatelessWidget {
final Location? location;

const MarkerIcon({Key? key, this.location}) : super(key: key);

static Widget getIcon(Location? location, BuildContext context) {
@override
Widget build(BuildContext context) {
if (location == null) {
return Container();
}

final Color fontColor = FacultyMaps.getFontColor(context);
if (location.icon is IconData) {
return Icon(location.icon, color: fontColor, size: 12);
final Color fontColor = FacultyMap.getFontColor(context);
if (location?.icon is IconData) {
return Icon(location?.icon, color: fontColor, size: 12);
} else {
return Icon(Icons.device_unknown, color: fontColor, size: 12);
}
Expand Down
76 changes: 44 additions & 32 deletions uni/lib/view/locations/widgets/marker_popup.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:uni/model/entities/location.dart';
import 'package:uni/model/entities/location_group.dart';
import 'package:uni/view/locations/widgets/faculty_maps.dart';
import 'package:uni/view/locations/widgets/faculty_map.dart';

class LocationMarkerPopup extends StatelessWidget {
const LocationMarkerPopup(this.locationGroup,
Expand All @@ -25,65 +25,77 @@ class LocationMarkerPopup extends StatelessWidget {
children: (showId
? <Widget>[Text(locationGroup.id.toString())]
: <Widget>[]) +
buildFloors(context),
getEntries().map((entry) =>
Floor(floor: entry.key, locations: entry.value)
).toList(),
)),
);
}

List<Widget> buildFloors(BuildContext context) {
//Sort by floor
List<MapEntry<int, List<Location>>> getEntries() {
final List<MapEntry<int, List<Location>>> entries =
locationGroup.floors.entries.toList();
locationGroup.floors.entries.toList();
entries.sort((current, next) => -current.key.compareTo(next.key));
return entries;
}
}

return entries.map((entry) {
final int floor = entry.key;
final List<Location> locations = entry.value;
class Floor extends StatelessWidget {
final List<Location> locations;
final int floor;

return Row(children: buildFloor(context, floor, locations));
}).toList();
}
const Floor({Key? key, required this.locations, required this.floor})
: super(key: key);

List<Widget> buildFloor(
BuildContext context, floor, List<Location> locations) {
final Color fontColor = FacultyMaps.getFontColor(context);
@override
Widget build(BuildContext context) {
final Color fontColor = FacultyMap.getFontColor(context);

final String floorString =
0 <= floor && floor <= 9 //To maintain layout of popup
? ' $floor'
: '$floor';
0 <= floor && floor <= 9 //To maintain layout of popup
? ' $floor'
: '$floor';

final Widget floorCol = Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.fromLTRB(8.0, 0.0, 8.0, 0.0),
child:
Text('Andar $floorString', style: TextStyle(color: fontColor)))
Text('Andar $floorString', style: TextStyle(color: fontColor)))
],
);
final Widget locationsColumn = Container(
padding: const EdgeInsets.fromLTRB(8.0, 0.0, 8.0, 0.0),
decoration:
BoxDecoration(border: Border(left: BorderSide(color: fontColor))),
BoxDecoration(border: Border(left: BorderSide(color: fontColor))),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: buildLocations(context, locations, fontColor),
children: locations
.map((location) =>
LocationRow(location: location, color: fontColor))
.toList(),
));
return [floorCol, locationsColumn];
return Row(children: [floorCol, locationsColumn]);
}
}

List<Widget> buildLocations(
BuildContext context, List<Location> locations, Color color) {
return locations
.map((location) => Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(location.description(),
textAlign: TextAlign.left, style: TextStyle(color: color))
],
))
.toList();
class LocationRow extends StatelessWidget {
final Location location;
final Color color;

const LocationRow({Key? key, required this.location, required this.color})
: super(key: key);

@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(location.description(),
textAlign: TextAlign.left, style: TextStyle(color: color))
],
);
}
}
Loading

0 comments on commit dd041a1

Please sign in to comment.