Skip to content

Commit

Permalink
Merge pull request #70 from andreytakhtamirov/1.3.3-bugfixes
Browse files Browse the repository at this point in the history
1.3.3 bug fixes
  • Loading branch information
andreytakhtamirov authored Jun 21, 2024
2 parents 9dd8a22 + 740ece7 commit 3cf513e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 37 deletions.
1 change: 1 addition & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@
97C147041CF9000F007C117D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
STRIP_INSTALLED_PRODUCT = NO;
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down
16 changes: 7 additions & 9 deletions lib/widgets/list_items/feature_item.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'package:flutter/material.dart';
import 'package:trailblaze/data/feature.dart';
import 'package:geolocator/geolocator.dart' as geo;
import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart' as mbm;
import 'package:turf/turf.dart' as turf;

class FeatureItem extends StatelessWidget {
final Feature feature;
final geo.Position? userLocation;
final turf.Position? userLocation;
final void Function() onClicked;

const FeatureItem({
Expand All @@ -21,12 +19,11 @@ class FeatureItem extends StatelessWidget {
return "";
}

final point1Coord = mbm.Point(
coordinates:
mbm.Position(userLocation!.longitude, userLocation!.latitude),
final point1Coord = turf.Point(
coordinates: turf.Position(userLocation!.lng, userLocation!.lat),
);
final point2Coord = mbm.Point(
coordinates: mbm.Position(feature.center['lon'], feature.center['lat']),
final point2Coord = turf.Point(
coordinates: turf.Position(feature.center['lon'], feature.center['lat']),
);

final distance = turf.distance(point1Coord, point2Coord);
Expand Down Expand Up @@ -68,7 +65,8 @@ class FeatureItem extends StatelessWidget {
child: FittedBox(
child: Icon(
Icons.forest_rounded,
color: Theme.of(context).colorScheme.tertiary,
color:
Theme.of(context).colorScheme.tertiary,
),
),
),
Expand Down
6 changes: 3 additions & 3 deletions lib/widgets/map/panels/features_panel.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart' as geo;
import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart' as mbm;
import 'package:sliding_up_panel/sliding_up_panel.dart';
import 'package:trailblaze/constants/map_constants.dart';
import 'package:trailblaze/constants/ui_control_constants.dart';
Expand All @@ -24,7 +24,7 @@ class FeaturesPanel extends StatelessWidget {
final PanelController panelController;
final PageController pageController;
final List<Feature>? features;
final geo.Position? userLocation;
final mbm.Position? userLocation;
final double? selectedDistanceMeters;
final Function(int page) onFeaturePageChanged;
final Function(double distance) onDistanceChanged;
Expand Down Expand Up @@ -116,7 +116,7 @@ class FeaturesPanel extends StatelessWidget {
context,
MaterialPageRoute(
builder: (context) => DistanceSelectorScreen(
center: [userLocation!.longitude, userLocation!.latitude],
center: [userLocation!.lng.toDouble(), userLocation!.lat.toDouble()],
initialDistanceMeters: selectedDistanceMeters ??
kDefaultFeatureDistanceMeters,
minDistanceKm: kMinFeatureDistanceMeters / 1000,
Expand Down
22 changes: 9 additions & 13 deletions lib/widgets/map/panels/place_info_panel.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart' as mbm;
import 'package:mapbox_search/mapbox_search.dart';
import 'package:trailblaze/util/distance_helper.dart';
import 'package:trailblaze/util/format_helper.dart';
import 'package:turf/turf.dart' as turf;

class PlaceInfoPanel extends StatefulWidget {
const PlaceInfoPanel({
Expand All @@ -12,7 +11,7 @@ class PlaceInfoPanel extends StatefulWidget {
this.userLocation,
}) : super(key: key);
final MapBoxPlace? selectedPlace;
final Position? userLocation;
final mbm.Position? userLocation;

@override
State<PlaceInfoPanel> createState() => _PlaceInfoPanelState();
Expand All @@ -26,16 +25,13 @@ class _PlaceInfoPanelState extends State<PlaceInfoPanel> {
return null;
}

final point1Coord = mbm.Point(
coordinates: mbm.Position(
widget.userLocation!.latitude, widget.userLocation!.longitude),
);
final point2Coord = mbm.Point(
coordinates: mbm.Position(
widget.selectedPlace!.center![1], widget.selectedPlace!.center![0]),
);

return turf.distance(point1Coord, point2Coord, turf.Unit.meters);
return DistanceHelper.euclideanDistance(
mbm.Point(
coordinates: mbm.Position(widget.selectedPlace?.center?[0] ?? 0,
widget.selectedPlace?.center?[1] ?? 0)),
mbm.Point(
coordinates: widget.userLocation!,
));
}

@override
Expand Down
9 changes: 5 additions & 4 deletions lib/widgets/map/picked_locations_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PickedLocationsWidget extends StatefulWidget {
final void Function() onExpand;
final void Function() onCollapse;
final void Function() onBackClicked;
final void Function(TransportationMode, num) onOptionsChanged;
final void Function(TransportationMode, num, bool isSilent) onOptionsChanged;
final void Function(bool) onMapControlChanged;

const PickedLocationsWidget({
Expand Down Expand Up @@ -106,6 +106,7 @@ class _PickedLocationsWidgetState extends State<PickedLocationsWidget> {
.floorToDouble(); // Initially select the mean of the min and max.
});
_onSliderChanged(_selectedValue);
_onSliderChangeEnd(_selectedValue, isSilentUpdate: true);
}

void _onSliderChanged(double value) {
Expand All @@ -115,8 +116,8 @@ class _PickedLocationsWidgetState extends State<PickedLocationsWidget> {
});
}

void _onSliderChangeEnd(value) async {
widget.onOptionsChanged(widget.selectedMode, _selectedDistance);
void _onSliderChangeEnd(double value, {bool isSilentUpdate = false}) async {
widget.onOptionsChanged(widget.selectedMode, _selectedDistance, isSilentUpdate);
}

int _determineCurrentState() {
Expand Down Expand Up @@ -350,7 +351,7 @@ class _PickedLocationsWidgetState extends State<PickedLocationsWidget> {
_showBlendSlider(showTitle: true),
TransportationModeWidget(
onSelected: (mode) =>
{widget.onOptionsChanged(mode, _selectedDistance)},
{widget.onOptionsChanged(mode, _selectedDistance, false)},
initialMode: widget.selectedMode,
isMinifiedView:
widget.selectedMode == TransportationMode.none),
Expand Down
28 changes: 21 additions & 7 deletions lib/widgets/map_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class _MapWidgetState extends State<MapWidget>
num? _influenceValue;
List<TrailblazeRoute> routesList = [];
TrailblazeRoute? _selectedRoute;
bool _fetchRouteOnNextUpdate = false;
bool _isContentLoading = false;
bool _mapStyleTouchContext = false;
bool _routeControlsTouchContext = false;
Expand All @@ -82,7 +83,7 @@ class _MapWidgetState extends State<MapWidget>
double _fabHeight = kPanelFabHeight;
double _panelOptionsHeight = kPanelFabHeight;
double? _selectedDistanceMeters = kDefaultFeatureDistanceMeters;
geo.Position? _userLocation;
mbm.Position? _userLocation;
final GlobalKey _topWidgetKey = GlobalKey();
final GlobalKey _shareWidgetKey = GlobalKey();
double _panelPosition = 0;
Expand Down Expand Up @@ -563,7 +564,7 @@ class _MapWidgetState extends State<MapWidget>

setState(() {
_startingLocation = myLocation;
_userLocation = position;
_userLocation = mbm.Position(position.longitude, position.latitude);
});

return position;
Expand Down Expand Up @@ -1169,14 +1170,22 @@ class _MapWidgetState extends State<MapWidget>
}
}

void _onRouteSettingsChanged(TransportationMode mode, num? influenceValue) {
void _onRouteSettingsChanged(
TransportationMode mode, num? influenceValue, bool isSilent) {
setState(() {
_selectedMode = mode.value;
_influenceValue = influenceValue;
_routeControlsTouchContext = false;
});

_getDirectionsFromSettings();
if (!isSilent || _fetchRouteOnNextUpdate) {
if (_fetchRouteOnNextUpdate) {
setState(() {
_fetchRouteOnNextUpdate = false;
});
}
_getDirectionsFromSettings();
}
}

Future<void> _showEditDirectionsScreen() async {
Expand All @@ -1196,7 +1205,7 @@ class _MapWidgetState extends State<MapWidget>
return;
}

final List<dynamic> waypoints = result['waypoints'];
//final List<dynamic> waypoints = result['waypoints']; TODO not implemented
final MapBoxPlace startingLocation = result['startingLocation'];
final MapBoxPlace endingLocation = result['endingLocation'];

Expand All @@ -1206,7 +1215,10 @@ class _MapWidgetState extends State<MapWidget>

annotationHelper?.deleteAllAnnotations();
_onSelectPlace(endingLocation);
_displayRoute(_selectedMode, waypoints);

setState(() {
_fetchRouteOnNextUpdate = true;
});
}

void _onStyleChanged(String newStyleId) async {
Expand Down Expand Up @@ -1889,7 +1901,9 @@ class _MapWidgetState extends State<MapWidget>
duration: const Duration(milliseconds: 300),
child: RoundTripControlsWidget(
onBackClicked: _onDirectionsBackClicked,
onModeChanged: _onRouteSettingsChanged,
onModeChanged: (TransportationMode mode, double? distance) {
_onRouteSettingsChanged(mode, distance, false);
},
selectedMode: getTransportationModeFromString(_selectedMode),
selectedDistanceMeters: _selectedDistanceMeters,
onDistanceChanged: _queryForRoundTrip,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.3.1
version: 1.3.3

environment:
sdk: '>=3.2.0'
Expand Down

0 comments on commit 3cf513e

Please sign in to comment.