Home Overview
The Home feature serves as the primary navigation hub of the application after the user is authenticated and onboarded. It presents a user interface with a main content area, a bottom navigation bar for switching between primary sections (tabs), and a slide-out drawer for accessing settings, support, and other application-level actions.
The HomePage widget is the core of this feature. It utilizes a ZoomDrawer for the side menu and a ChicletSegmentedButton for tab navigation. Each tab is defined by a HomeTab object, which encapsulates the tab's title, icon, body content, and any specific actions available in the app bar for that tab.
Class Diagram
This diagram shows the main classes and widgets involved in the Home feature and their relationships.
Key Relationships
HomePage
manages a list ofHomeTab
objects.HomePage
uses aZoomDrawerController
to control theZoomDrawer
.- The
ZoomDrawer
displays:HomeDrawer
as its menu screen.- The main content (
Scaffold
managed byHomePage
) as its main screen.
HomePage
usesChicletSegmentedButton
(composed ofChicletButtonSegments
) for tab navigation.HomePage
displays aPrimaryAppBar
, which can display aUserAvatar
.
Sequence Diagram
This diagram illustrates the sequence of interactions when a user taps on a tab in the bottom navigation bar.
Flow Summary
- The User taps on a
ChicletButtonSegment
representing a tab. - The
onPressed
callback of theChicletButtonSegment
is triggered. - Inside
HomePageState
,setState
is called to update_selectedTabIndex
. - The
HomePage
rebuilds.
TheAnimatedSwitcher
receives the newtabBody
widget. - The
AnimatedSwitcher
transitions to display the NewTabContent (thetabBody
of the newly selectedHomeTab
). - The
PrimaryAppBar
updates itstabTitle
andtabAction
based on the new selected tab.
Home Feature State Management
Unlike the other features, the Home feature does not manage its state using a bloc or cubit.
This is because the state of the HomePage
is fairly simple and only requires keeping track of the tab index.
Thus, HomePage
is managed using a StatefulWidget
that tracks:
Managed State
-
_selectedTabIndex
(int)
An integer representing the index of the currently active tab.
This determines whichHomeTab
’s content and app bar details are displayed. -
_drawerController
(ZoomDrawerController)
Manages the state (open/closed) of theZoomDrawer
.
Interactions with this controller (e.g., toggling the drawer) are handled by theZoomDrawer
widget itself,
but the controller instance is held byHomePageState
.
State Transitions for Tab Selection
-
Initial State
_selectedTabIndex
is initialized (e.g., to0
).- The content and app bar for the first tab are displayed.
-
User Interaction
- The user taps on a
ChicletButtonSegment
inside theChicletSegmentedButton
.
- The user taps on a
-
onPressed
Callback- The
onPressed
callback of the tapped segment is invoked.
- The
-
setState()
- Inside the callback,
setState()
is called, updating_selectedTabIndex
to the index of the tapped segment.
- Inside the callback,
-
Rebuild
- The
HomePage
widget and its relevant children (likeAnimatedSwitcher
for the body
andPrimaryAppBar
) rebuild.
- The
UI Update
-
The
AnimatedSwitcher
displays thetabBody
of theHomeTab
at the new_selectedTabIndex
. -
The
PrimaryAppBar
updates itstabTitle
andtabAction
based on the properties
of theHomeTab
at the new_selectedTabIndex
.
This internal state management is suitable for HomePage
because its state is primarily concerned
with local UI presentation (which tab is active, drawer visibility)
and doesn’t need to be shared across unrelated features.
External Dependencies
The Home feature leverages several external packages to achieve its functionality and appearance:
- Purpose: Provides custom UI elements.
- Usage:
ChicletSegmentedButton
andChicletButtonSegment
are used to create the stylized bottom tab navigation bar inHomePage
.ChicletAnimatedButton
is used for the action button within thePrimaryAppBar
(e.g., "New Session", "New Message").
- Purpose: Implements the main drawer navigation.
- Usage:
- The
ZoomDrawer
widget wraps theHomePage
’s main screen and theHomeDrawer
, providing the characteristic zoom/slide animation. ZoomDrawerController
is used to programmatically control the drawer’s state (e.g., toggling from thePrimaryAppBar
).
- The
- Purpose: State management and dependency injection.
- Usage:
- While
HomePage
itself usesStatefulWidget
for local UI state,HomeDrawer
accessesAuthenticationRepository
(typically viacontext.read(AuthenticationRepository)()
). UserAvatar
(used inPrimaryAppBar
) also reads fromAppBloc
andUserRepository
.
- While
- Purpose: Adds entrance animations to widgets.
- Usage:
- Used in
PrimaryAppBar
to animate the appearance of the tab title and action widgets, enhancing visual appeal when switching tabs or when the app bar first appears.
- Used in
- Purpose: Efficiently loads and caches network images.
- Usage:
- Employed by the
UserAvatar
widget (displayed in thePrimaryAppBar
) to show the user’s profile picture, with placeholder and error handling.
- Employed by the
- Purpose: Generates placeholder avatars.
- Usage:
- Used by the
UserAvatar
widget as a fallback when a user’s profile image is not available, providing a visually consistent placeholder based on the user’s name.
- Used by the
These packages contribute significantly to the user experience and structural organization of the Home feature.