From 34786f3d4818e125748ca798a8039f3b5a63acce Mon Sep 17 00:00:00 2001 From: wuzihao051119 Date: Wed, 16 Jul 2025 19:13:45 +0800 Subject: [PATCH] fix: refresh timeline by key --- .../bottom_sheet/map_bottom_sheet.widget.dart | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/mobile/lib/presentation/widgets/bottom_sheet/map_bottom_sheet.widget.dart b/mobile/lib/presentation/widgets/bottom_sheet/map_bottom_sheet.widget.dart index bc8239a5d3..e5b7a0ee67 100644 --- a/mobile/lib/presentation/widgets/bottom_sheet/map_bottom_sheet.widget.dart +++ b/mobile/lib/presentation/widgets/bottom_sheet/map_bottom_sheet.widget.dart @@ -6,37 +6,45 @@ import 'package:immich_mobile/presentation/widgets/timeline/timeline.widget.dart import 'package:immich_mobile/providers/infrastructure/timeline.provider.dart'; import 'package:maplibre_gl/maplibre_gl.dart'; -class MapBottomSheet extends ConsumerWidget { +class MapBottomSheet extends ConsumerStatefulWidget { const MapBottomSheet({super.key}); @override - Widget build(BuildContext context, WidgetRef ref) { + ConsumerState createState() => _MapBottomSheetState(); +} + +class _MapBottomSheetState extends ConsumerState { + GlobalKey key = GlobalKey(); + + @override + Widget build(BuildContext context) { LatLngBounds bounds = ref.watch(mapStateProvider.select((s) => s.bounds)); ref.listen(mapStateProvider, (previous, next) async { bounds = next.bounds; + key = GlobalKey(); }); - return ProviderScope( - overrides: [ - // TODO: when ProviderScope changed, we should refresh timeline - timelineServiceProvider.overrideWith((ref) { - final timelineService = - ref.watch(timelineFactoryProvider).map(bounds); - ref.onDispose(timelineService.dispose); - return timelineService; - }), - ], - child: const BaseBottomSheet( - initialChildSize: 0.25, - shouldCloseOnMinExtent: false, - actions: [], - slivers: [ - SliverFillRemaining( - child: Timeline(), + return BaseBottomSheet( + initialChildSize: 0.25, + shouldCloseOnMinExtent: false, + actions: [], + slivers: [ + SliverFillRemaining( + child: ProviderScope( + key: key, + overrides: [ + timelineServiceProvider.overrideWith((ref) { + final timelineService = + ref.watch(timelineFactoryProvider).map(bounds); + ref.onDispose(timelineService.dispose); + return timelineService; + }), + ], + child: const Timeline(), ), - ], - ), + ), + ], ); } }