Role Switch Widget
Component Detail
Description
Shared widget that allows users holding multiple roles to switch their active role within the app session. Triggers role state update and causes conditional navigation and content to re-render throughout the app.
role-switch-widget
Summaries
The Role Switch Widget enables users who hold multiple roles within the platform to seamlessly transition between those roles without logging out or starting a new session. This directly reduces friction for power users — such as coordinators who also act as mentors — improving retention and satisfaction. By surfacing the right content and navigation for each role instantly, the app feels purpose-built for every user type, delivering a premium experience that reduces support requests and increases daily active usage. The shared nature of this component means it is built once and reused across the entire app, lowering total development cost and ensuring a consistent experience as new roles are introduced over time.
The Role Switch Widget is a medium-complexity shared component with broad impact across the app. Because it triggers a global role state update that causes re-renders in navigation, content areas, and conditional UI, it must be delivered early in the project timeline — downstream feature work depends on this component being stable. It has a direct dependency on the role-state-manager and role-repository, so those services must be available before integration testing can begin. QA must cover all role combinations, including edge cases where a user holds more than two roles.
Accessibility testing is required since the widget must clearly indicate the current active role. Regression testing after any role or permission change is essential.
The Role Switch Widget is a shared Flutter widget implementing the build(BuildContext context) lifecycle with four key interfaces: getAvailableRoles() fetches the user's assigned roles from role-repository, getCurrentActiveRole() reads from role-state-manager, and onRoleSelected(Role newRole) dispatches a role change event that propagates through the app's state management layer (likely Riverpod or BLoC). The widget depends on role-state-manager for reactive state and role-repository for data access. It consumes the user-role data model. Because role selection triggers conditional re-renders throughout the widget tree, care must be taken to minimize rebuild scope — prefer scoped providers over global rebuilds.
The component is marked shared (is_shared: true), so changes carry wide regression risk.
Responsibilities
- Display available roles for the current user
- Trigger active role change in app state
- Provide accessible role-selection UI with clear current-role indicator
Interfaces
build(BuildContext context)
getAvailableRoles()
onRoleSelected(Role newRole)
getCurrentActiveRole()
Relationships
Dependencies (2)
Components this component depends on