Skip to content

Commit

Permalink
fix: Navigating to settings, redirects to home page #812
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Nov 8, 2023
1 parent 6b8ae88 commit da04f06
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
18 changes: 11 additions & 7 deletions lib/components/root/sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import 'package:spotube/utils/platform.dart';
import 'package:spotube/utils/type_conversion_utils.dart';

class Sidebar extends HookConsumerWidget {
final int selectedIndex;
final int? selectedIndex;
final void Function(int) onSelectedIndexChanged;
final Widget child;

Expand Down Expand Up @@ -57,7 +57,7 @@ class Sidebar extends HookConsumerWidget {
ref.watch(userPreferencesProvider.select((s) => s.layoutMode));

final controller = useSidebarXController(
selectedIndex: selectedIndex,
selectedIndex: selectedIndex ?? 0,
extended: mediaQuery.lgAndUp,
);

Expand All @@ -75,17 +75,21 @@ class Sidebar extends HookConsumerWidget {
);

useEffect(() {
if (controller.selectedIndex != selectedIndex) {
controller.selectIndex(selectedIndex);
if (controller.selectedIndex != selectedIndex && selectedIndex != null) {
controller.selectIndex(selectedIndex!);
}
return null;
}, [selectedIndex]);

useEffect(() {
controller.addListener(() {
void listener() {
onSelectedIndexChanged(controller.selectedIndex);
});
return null;
}

controller.addListener(listener);
return () {
controller.removeListener(listener);
};
}, [controller]);

useEffect(() {
Expand Down
8 changes: 5 additions & 3 deletions lib/components/root/spotube_navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:spotube/provider/user_preferences_provider.dart';
final navigationPanelHeight = StateProvider<double>((ref) => 50);

class SpotubeNavigationBar extends HookConsumerWidget {
final int selectedIndex;
final int? selectedIndex;
final void Function(int) onSelectedIndexChanged;

const SpotubeNavigationBar({
Expand All @@ -33,7 +33,7 @@ class SpotubeNavigationBar extends HookConsumerWidget {
final layoutMode =
ref.watch(userPreferencesProvider.select((s) => s.layoutMode));

final insideSelectedIndex = useState<int>(selectedIndex);
final insideSelectedIndex = useState<int>(selectedIndex ?? 0);

final buttonColor = useBrightnessValue(
theme.colorScheme.inversePrimary,
Expand All @@ -46,7 +46,9 @@ class SpotubeNavigationBar extends HookConsumerWidget {
final panelHeight = ref.watch(navigationPanelHeight);

useEffect(() {
insideSelectedIndex.value = selectedIndex;
if (selectedIndex != null) {
insideSelectedIndex.value = selectedIndex!;
}
return null;
}, [selectedIndex]);

Expand Down
4 changes: 2 additions & 2 deletions lib/pages/root/root_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class RootApp extends HookConsumerWidget {

return Scaffold(
body: Sidebar(
selectedIndex: rootPaths[location] ?? 0,
selectedIndex: rootPaths[location],
onSelectedIndexChanged: onSelectIndexChanged,
child: child,
),
Expand All @@ -169,7 +169,7 @@ class RootApp extends HookConsumerWidget {
children: [
BottomPlayer(),
SpotubeNavigationBar(
selectedIndex: rootPaths[location] ?? 0,
selectedIndex: rootPaths[location],
onSelectedIndexChanged: onSelectIndexChanged,
),
],
Expand Down

0 comments on commit da04f06

Please sign in to comment.