Skip to content

Commit 5e60b90

Browse files
committed
♻️ refactor: enhance discount handling and transport mode UX persistence
- Add passenger state management when setting discount type - Fix location search loading indicator timing with post-frame callback - Load saved transport mode preferences on modal initialization - Clean up injection.config.dart formatting
1 parent c84cc55 commit 5e60b90

4 files changed

Lines changed: 66 additions & 41 deletions

File tree

lib/src/core/di/injection.config.dart

Lines changed: 28 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/presentation/controllers/main_screen_controller.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:latlong2/latlong.dart';
66
import '../../core/di/injection.dart';
77
import '../../core/errors/failures.dart';
88
import '../../core/hybrid_engine.dart';
9+
import '../../models/discount_type.dart';
910
import '../../models/fare_formula.dart';
1011
import '../../models/fare_result.dart';
1112
import '../../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

lib/src/presentation/widgets/main_screen/location_input_section.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,11 @@ class _LocationFieldState extends State<_LocationField> {
222222
final results = await widget.onSearchLocations(query);
223223
return results;
224224
} finally {
225-
// Clear loading state after fetching (success or error)
226-
_isSearching.value = false;
225+
// Delay clearing the loading state until after the current frame completes
226+
// so the autocomplete options have time to render before the spinner disappears.
227+
WidgetsBinding.instance.addPostFrameCallback((_) {
228+
_isSearching.value = false;
229+
});
227230
}
228231
}
229232

lib/src/presentation/widgets/main_screen/transport_mode_selection_modal.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ class _TransportModeSelectionModalState
6868
void initState() {
6969
super.initState();
7070
_groupedFormulas = _groupFormulas();
71+
_loadSavedPreferences();
72+
}
73+
74+
/// Loads saved transport mode preferences and initializes selected modes.
75+
/// Modes that are NOT in the hidden set should be marked as selected.
76+
Future<void> _loadSavedPreferences() async {
77+
final hiddenModes = await widget.settingsService.getHiddenTransportModes();
78+
79+
setState(() {
80+
for (final formula in widget.availableFormulas) {
81+
final modeSubTypeKey = '${formula.mode}::${formula.subType}';
82+
// Mode is selected if it's NOT hidden
83+
if (!hiddenModes.contains(modeSubTypeKey)) {
84+
_selectedModes.add(modeSubTypeKey);
85+
}
86+
}
87+
});
7188
}
7289

7390
Map<String, List<FareFormula>> _groupFormulas() {

0 commit comments

Comments
 (0)