Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save clembabs/c1feecff7f4a5dc09d26b75a9b3d081e to your computer and use it in GitHub Desktop.

Select an option

Save clembabs/c1feecff7f4a5dc09d26b75a9b3d081e to your computer and use it in GitHub Desktop.
Flutter Onesignal deeplinking service
class TabNavigationService {
static final TabNavigationService _instance = TabNavigationService._internal();
factory TabNavigationService() => _instance;
TabNavigationService._internal();
/// Switch to a specific tab in the bottom navigation
void switchToTab(int tabIndex) {
final context = Routes.navKey.currentContext;
if (context == null) return;
final bottomNavBloc = context.read<BottomNavigationBloc>();
switch (tabIndex) {
case 0:
bottomNavBloc.add(const OpenHomeTab());
break;
case 1:
bottomNavBloc.add(const OpenAssetsTab());
break;
case 2:
bottomNavBloc.add(const OpenHistoryTab());
break;
default:
debugPrint('Invalid tab index: $tabIndex');
}
}
/// Get the current tab index
int getCurrentTabIndex(BuildContext context) {
final state = context.read<BottomNavigationBloc>().state;
if (state is HomeTab) return 0;
if (state is AssetsTab) return 1;
if (state is HistoryTab) return 2;
return 0; // Default to home tab
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment