fix: refresh timeline by key

This commit is contained in:
wuzihao051119 2025-07-16 19:13:45 +08:00 committed by mertalev
parent bcac0983d7
commit 34786f3d48
No known key found for this signature in database
GPG Key ID: DF6ABC77AAD98C95

View File

@ -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<MapBottomSheet> createState() => _MapBottomSheetState();
}
class _MapBottomSheetState extends ConsumerState<MapBottomSheet> {
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(),
),
],
),
),
],
);
}
}