@@ -6,6 +6,7 @@ import 'package:latlong2/latlong.dart';
66import '../../core/di/injection.dart' ;
77import '../../core/errors/failures.dart' ;
88import '../../core/hybrid_engine.dart' ;
9+ import '../../models/discount_type.dart' ;
910import '../../models/fare_formula.dart' ;
1011import '../../models/fare_result.dart' ;
1112import '../../models/location.dart' ;
@@ -140,9 +141,22 @@ class MainScreenController extends ChangeNotifier {
140141 return _settingsService.hasSetDiscountType ();
141142 }
142143
143- /// Set user discount type preference
144- Future <void > setUserDiscountType (dynamic discountType) async {
144+ /// Set user discount type preference and update local passenger state.
145+ Future <void > setUserDiscountType (DiscountType discountType) async {
145146 await _settingsService.setUserDiscountType (discountType);
147+
148+ // Update local passenger counts based on the selected discount type
149+ // Assuming a total of 1 passenger when first setting the preference
150+ if (discountType == DiscountType .discounted) {
151+ _regularPassengers = 0 ;
152+ _discountedPassengers = 1 ;
153+ } else {
154+ _regularPassengers = 1 ;
155+ _discountedPassengers = 0 ;
156+ }
157+ _passengerCount = _regularPassengers + _discountedPassengers;
158+
159+ notifyListeners ();
146160 }
147161
148162 /// Search locations with debounce for autocomplete
@@ -204,7 +218,9 @@ class MainScreenController extends ChangeNotifier {
204218 }
205219 }
206220
207- /// Swap origin and destination
221+ /// Swap origin and destination.
222+ /// Note: Fare results are preserved on swap since the route distance
223+ /// remains the same (just reversed direction).
208224 void swapLocations () {
209225 if (_originLocation == null && _destinationLocation == null ) return ;
210226
@@ -217,7 +233,12 @@ class MainScreenController extends ChangeNotifier {
217233 _destinationLocation = tempLocation;
218234 _destinationLatLng = tempLatLng;
219235
220- _resetResult ();
236+ // Note: We do NOT reset fare results on swap.
237+ // The fare is based on distance which is the same regardless of direction.
238+ // Only clear route points so they can be recalculated.
239+ _routePoints = [];
240+ _routeResult = null ;
241+
221242 notifyListeners ();
222243
223244 if (_originLocation != null && _destinationLocation != null ) {
@@ -297,10 +318,18 @@ class MainScreenController extends ChangeNotifier {
297318
298319 final List <FareResult > results = [];
299320 final trafficFactor = await _settingsService.getTrafficFactor ();
321+ final hasSetPrefs = await _settingsService.hasSetTransportModePreferences ();
300322 final hiddenModes = await _settingsService.getHiddenTransportModes ();
301323
302324 final visibleFormulas = _availableFormulas.where ((formula) {
303325 final modeSubTypeKey = '${formula .mode }::${formula .subType }' ;
326+
327+ if (! hasSetPrefs) {
328+ // New user - use default enabled modes
329+ final defaultModes = SettingsService .getDefaultEnabledModes ();
330+ return defaultModes.contains (modeSubTypeKey);
331+ }
332+ // Existing user - check hidden modes
304333 return ! hiddenModes.contains (modeSubTypeKey);
305334 }).toList ();
306335
@@ -338,7 +367,7 @@ class MainScreenController extends ChangeNotifier {
338367 results.add (
339368 FareResult (
340369 transportMode: '${formula .mode } (${formula .subType })' ,
341- fare: fare,
370+ fare: _passengerCount > 0 ? fare / _passengerCount : fare,
342371 indicatorLevel: indicator,
343372 isRecommended: false ,
344373 passengerCount: _passengerCount,
0 commit comments