Skip to content

Commit

Permalink
fix reload issue for moving journey address on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-ishita-g committed Dec 20, 2024
1 parent 51b913a commit b6538d2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/lib/ui/flow/journey/timeline/journey_timeline_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class JourneyTimelineScreen extends ConsumerStatefulWidget {
class _JourneyTimelineScreenState extends ConsumerState<JourneyTimelineScreen> {
late JourneyTimelineViewModel notifier;
final Map<LatLng, String> _addressCache = {};
final Map<String, String> _movingJourneyAddressCache = {};

@override
void initState() {
Expand Down Expand Up @@ -337,6 +338,16 @@ class _JourneyTimelineScreenState extends ConsumerState<JourneyTimelineScreen> {
LatLng toLatLng,
String formattedTime,
) {
final cacheKey = '${fromLatLng.latitude},${fromLatLng.longitude}_'
'${toLatLng.latitude},${toLatLng.longitude}';

if (_movingJourneyAddressCache.containsKey(cacheKey)) {
return _placeInfo(
address: _movingJourneyAddressCache[cacheKey]!,
formattedTime: formattedTime,
);
}

return FutureBuilder(
future: _getMovingJourneyAddress(fromLatLng, toLatLng),
builder: (_, snapshot) {
Expand All @@ -348,6 +359,7 @@ class _JourneyTimelineScreenState extends ConsumerState<JourneyTimelineScreen> {
} else if (snapshot.hasData) {
final address = snapshot.data ??
context.l10n.journey_timeline_unknown_address_text;
_movingJourneyAddressCache[cacheKey] = address;
return _placeInfo(address: address, formattedTime: formattedTime);
} else {
return _placeInfo(
Expand Down

0 comments on commit b6538d2

Please sign in to comment.