[client] PathView reacts to changes in folderId

This commit is contained in:
Abhishek Shroff
2024-11-20 20:46:55 +05:30
parent 537d392452
commit 0f2b2f41cc

View File

@@ -31,26 +31,29 @@ class PathView extends StatefulWidget {
class _PathViewState extends State<PathView> {
late String id;
Function()? removeListener;
StreamSubscription? sub;
Function()? removeListener;
Iterable<ParentsResult>? ancestors;
@override
void initState() {
super.initState();
id = context.read<ExplorerViewState>().folderId;
sub = context.read<PhylumAccount>().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<ExplorerViewController>().addListener((state) {
id = state.folderId;
sub = context.read<PhylumAccount>().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();
}