feat: Fix layout overflow and enhance responsive design for dashboard#189
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds comprehensive documentation comments to the HomePageScaffold and introduces a new landscape layout for mobile devices. It also updates the dashboard layout and viewportFraction logic to better support tablet and mobile orientations. The review identified a significant issue regarding the lifecycle management of PageController within the _homebody method, which needs to be moved to initState and dispose to prevent memory leaks and state resets. Additionally, a suggestion was made to improve text handling in the landscape layout by adding maxLines and overflow properties to prevent UI overflow.
| /// Determines which main body layout to render based on current state and orientation. | ||
| /// Viewport Fraction Logic:** | ||
| /// - Mobile Portrait: `0.65` (Shows edges of adjacent cards). | ||
| /// - Mobile Landscape: `0.95` (Nearly full screen due to side-by-side layout). | ||
| /// - Tablet Portrait: `0.8` (Larger screen balance). | ||
| /// - Tablet Landscape: `0.7` (Optimized for wide screen aspect ratios). |
There was a problem hiding this comment.
The PageController is being instantiated inside the _homebody method, which is called during every build (e.g., on orientation change or when setState is called). This causes the scroll position to reset to 0 and adds a new listener on every rebuild, leading to memory leaks and a broken user experience when swiping. The PageController should be managed in the state's initState and dispose methods. To handle dynamic viewportFraction, you should recreate the controller only when the orientation changes, ensuring you preserve the current page and dispose of the previous controller.
| Widget titleWidget = Text( | ||
| announcement.title, | ||
| textAlign: TextAlign.center, | ||
| style: TextStyle( | ||
| fontSize: 20.0, | ||
| color: Theme.of(context).colorScheme.onSurfaceVariant, | ||
| fontWeight: FontWeight.w500, | ||
| ), | ||
| ); |
There was a problem hiding this comment.
In the landscape phone layout, the announcement title is constrained to half the screen width. Long titles might overflow the available vertical space if they wrap too many times. Consider adding maxLines and overflow to the Text widget to ensure a consistent layout.
Widget titleWidget = Text(
announcement.title,
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 20.0,
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontWeight: FontWeight.w500,
),
);
This pull request enhances the
HomePageScaffoldinap_common_flutter_uiwith improved documentation, responsive layout logic, and code readability. The most significant changes include comprehensive DartDoc comments for public APIs, refactored and clarified layout methods for mobile and tablet devices, and improved logic for carousel and dashboard layouts.Documentation Improvements
HomePageScaffoldclass, its constructor, and all public fields and methods, making the widget's API much more understandable for future maintainers and users. [1] [2] [3] [4] [5] [6] [7] [8]Responsive Layout Enhancements
_buildLandscapePhonePageViewfor optimized landscape layouts on mobile, using a side-by-side row for images and titles.Layout and Sizing Logic
viewportFractionlogic in_homebodyto better fit different device types and orientations, ensuring carousel cards are sized appropriately.Code Quality and Maintainability