From 0f2b2f41cc3eb7c4b7b774adff2edd0abe449d55 Mon Sep 17 00:00:00 2001 From: Abhishek Shroff Date: Wed, 20 Nov 2024 20:46:55 +0530 Subject: [PATCH] [client] PathView reacts to changes in folderId --- client/lib/ui/explorer/path_view.dart | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/client/lib/ui/explorer/path_view.dart b/client/lib/ui/explorer/path_view.dart index cb33aaf6..f4de2ef9 100644 --- a/client/lib/ui/explorer/path_view.dart +++ b/client/lib/ui/explorer/path_view.dart @@ -31,26 +31,29 @@ class PathView extends StatefulWidget { class _PathViewState extends State { late String id; - Function()? removeListener; StreamSubscription? sub; + Function()? removeListener; Iterable? ancestors; @override void initState() { super.initState(); - id = context.read().folderId; - sub = context.read().db.parents(id).watch().listen((data) { - SystemChrome.setApplicationSwitcherDescription(ApplicationSwitcherDescription( - label: data.isEmpty ? 'Phylum' : "${data[0].name == "" ? "/" : data[0].name} | Phylum", - )); - setState(() { - ancestors = data.reversed; + removeListener = context.read().addListener((state) { + id = state.folderId; + sub = context.read().db.parents(id).watch().listen((data) { + SystemChrome.setApplicationSwitcherDescription(ApplicationSwitcherDescription( + label: data.isEmpty ? 'Phylum' : "${data[0].name == "" ? "/" : data[0].name} | Phylum", + )); + setState(() { + ancestors = data.reversed; + }); }); - }); + }, fireImmediately: true); } @override void dispose() { + removeListener?.call(); sub?.cancel(); super.dispose(); }