From d6ad9b65bf71cd62bb88365895649472246e91c2 Mon Sep 17 00:00:00 2001 From: processing Date: Wed, 3 May 2023 14:09:05 +0100 Subject: [PATCH 1/2] Refactored locations widgets. --- uni/lib/view/locations/locations.dart | 38 +++------- .../view/locations/widgets/faculty_map.dart | 35 +++++++++ .../view/locations/widgets/faculty_maps.dart | 30 -------- .../widgets/floorless_marker_popup.dart | 39 +++++++--- uni/lib/view/locations/widgets/map.dart | 10 +-- uni/lib/view/locations/widgets/marker.dart | 21 +++-- .../view/locations/widgets/marker_popup.dart | 76 +++++++++++-------- 7 files changed, 136 insertions(+), 113 deletions(-) create mode 100644 uni/lib/view/locations/widgets/faculty_map.dart delete mode 100644 uni/lib/view/locations/widgets/faculty_maps.dart diff --git a/uni/lib/view/locations/locations.dart b/uni/lib/view/locations/locations.dart index b9ce8722c..f4bb785d1 100644 --- a/uni/lib/view/locations/locations.dart +++ b/uni/lib/view/locations/locations.dart @@ -1,14 +1,11 @@ import 'package:flutter/material.dart'; -import 'package:flutter_map/flutter_map.dart'; import 'package:provider/provider.dart'; import 'package:uni/model/request_status.dart'; import 'package:uni/model/entities/location_group.dart'; import 'package:uni/model/providers/faculty_locations_provider.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/locations/widgets/faculty_maps.dart'; -import 'package:uni/view/locations/widgets/map.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); @@ -48,39 +45,24 @@ class LocationsPageView extends StatelessWidget { @override Widget build(BuildContext context) { return Column(mainAxisSize: MainAxisSize.max, children: [ - upperMenuContainer(context), + Container( + 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: //TODO:: add support for multiple faculties - getMap(context), + child: (locations == null || status != RequestStatus.successful) + ? null + : FacultyMap(faculty: "FEUP", locations: locations!) + //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 - } - - LocationsMap? getMap(BuildContext context) { - if (locations == null || status != RequestStatus.successful) { - return null; - } - return FacultyMaps.getFeupMap(locations!); - } - String getLocation() { return 'FEUP'; } - - List getMarkers() { - return locations!.map((location) { - return LocationMarker(location.latlng, location); - }).toList(); - } } diff --git a/uni/lib/view/locations/widgets/faculty_map.dart b/uni/lib/view/locations/widgets/faculty_map.dart new file mode 100644 index 000000000..29e8c3bdb --- /dev/null +++ b/uni/lib/view/locations/widgets/faculty_map.dart @@ -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 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; + } +} + diff --git a/uni/lib/view/locations/widgets/faculty_maps.dart b/uni/lib/view/locations/widgets/faculty_maps.dart deleted file mode 100644 index 7d113e654..000000000 --- a/uni/lib/view/locations/widgets/faculty_maps.dart +++ /dev/null @@ -1,30 +0,0 @@ -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 FacultyMaps { - static LocationsMap? getFacultyMap( - String faculty, List locations) { - switch (faculty) { - case 'FEUP': - return getFeupMap(locations); - } - return null; - } - - static LocationsMap getFeupMap(List locations) { - return LocationsMap( - northEastBoundary: LatLng(41.17986, -8.59298), - southWestBoundary: LatLng(41.17670, -8.59991), - center: LatLng(41.17731, -8.59522), - locations: locations, - ); - } - - static getFontColor(BuildContext context) { - return Theme.of(context).brightness == Brightness.light - ? Theme.of(context).colorScheme.primary - : Theme.of(context).colorScheme.tertiary; - } -} diff --git a/uni/lib/view/locations/widgets/floorless_marker_popup.dart b/uni/lib/view/locations/widgets/floorless_marker_popup.dart index c7129ab87..e7b3743a7 100644 --- a/uni/lib/view/locations/widgets/floorless_marker_popup.dart +++ b/uni/lib/view/locations/widgets/floorless_marker_popup.dart @@ -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, @@ -26,8 +26,9 @@ class FloorlessLocationMarkerPopup extends StatelessWidget { spacing: 8, children: (showId ? [Text(locationGroup.id.toString())] - : []) + - buildLocations(context, locations), + : []) + + locations.map((location) => LocationRow(location: location)) + .toList(), )), ); } @@ -35,13 +36,31 @@ class FloorlessLocationMarkerPopup extends StatelessWidget { List buildLocations(BuildContext context, List 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))) + ], + ); + } +} diff --git a/uni/lib/view/locations/widgets/map.dart b/uni/lib/view/locations/widgets/map.dart index 95cc68a49..42c8a13d9 100644 --- a/uni/lib/view/locations/widgets/map.dart +++ b/uni/lib/view/locations/widgets/map.dart @@ -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)), @@ -82,12 +84,6 @@ class LocationsMap extends StatelessWidget { ), ]); } - - List _getMarkers() { - return locations.map((location) { - return LocationMarker(location.latlng, location); - }).toList(); - } } class CachedTileProvider extends TileProvider { diff --git a/uni/lib/view/locations/widgets/marker.dart b/uni/lib/view/locations/widgets/marker.dart index d3cca2d33..13bda1c9e 100644 --- a/uni/lib/view/locations/widgets/marker.dart +++ b/uni/lib/view/locations/widgets/marker.dart @@ -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; @@ -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); } diff --git a/uni/lib/view/locations/widgets/marker_popup.dart b/uni/lib/view/locations/widgets/marker_popup.dart index 87b653fd8..7f6ed3dda 100644 --- a/uni/lib/view/locations/widgets/marker_popup.dart +++ b/uni/lib/view/locations/widgets/marker_popup.dart @@ -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, @@ -25,33 +25,36 @@ class LocationMarkerPopup extends StatelessWidget { children: (showId ? [Text(locationGroup.id.toString())] : []) + - buildFloors(context), + getEntries().map((entry) => + Floor(floor: entry.key, locations: entry.value) + ).toList(), )), ); } - List buildFloors(BuildContext context) { - //Sort by floor + List>> getEntries() { final List>> 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 locations = entry.value; +class Floor extends StatelessWidget { + final List 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 buildFloor( - BuildContext context, floor, List 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, @@ -59,31 +62,40 @@ class LocationMarkerPopup extends StatelessWidget { 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 buildLocations( - BuildContext context, List 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)) + ], + ); } } From c53576866cbc261ad16a067dec65e80305ba2129 Mon Sep 17 00:00:00 2001 From: Process-ing Date: Wed, 12 Jul 2023 14:07:39 +0000 Subject: [PATCH 2/2] Bump app version [no ci] --- uni/app_version.txt | 2 +- uni/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/uni/app_version.txt b/uni/app_version.txt index c3c43d8a8..87a049733 100644 --- a/uni/app_version.txt +++ b/uni/app_version.txt @@ -1 +1 @@ -1.5.30+148 \ No newline at end of file +1.5.31+149 \ No newline at end of file diff --git a/uni/pubspec.yaml b/uni/pubspec.yaml index 3a8ff43a8..79103313c 100644 --- a/uni/pubspec.yaml +++ b/uni/pubspec.yaml @@ -20,7 +20,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # To change it manually, override the value in app_version.txt. # The app version code is automatically also bumped by CI. # Do not change it manually. -version: 1.5.30+148 +version: 1.5.31+149 environment: sdk: ">=2.17.1 <3.0.0"