Skip to content

Conversation

@lollipopkit
Copy link
Owner

@lollipopkit lollipopkit commented Sep 2, 2025

Fixes #887

Summary by Sourcery

Enable users to customize which tabs appear on the home page and their order by introducing a persistent homeTabs setting, a new AppTab model with Hive support, and a dedicated configuration UI in the app settings.

New Features:

  • Introduce a homeTabs setting to store and persist a custom list of home page tabs via Hive
  • Add a HomeTabsConfigPage UI to the settings for selecting and reordering home tabs
  • Define a new AppTab enum with a HiveType adapter for tab persistence

Enhancements:

  • Update HomePage to dynamically render navigation destinations and pages based on the configured homeTabs

Build:

  • Bump fl_lib dependency reference and enable local override in pubspec

Chores:

  • Register the new AppTabAdapter in the Hive registrar

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 2, 2025

Reviewer's Guide

This PR adds support for user-customizable home page tabs by introducing a new AppTab model with Hive persistence, wiring it into the settings store and UI, refactors SettingsStore property declarations for consistency, and updates the fl_lib dependency.

File-Level Changes

Change Details Files
Add customizable home tabs feature
  • Define AppTab enum with Hive annotations and generate type adapter
  • Extend SettingsStore with homeTabs listProperty including custom fromObj/toObj
  • Register AppTabAdapter in both HiveInterface and IsolatedHiveInterface
  • Update HomePage to fetch and use dynamic _tabs instead of static AppTab.values
  • Add HomeTabsConfigPage UI and link it via settings entry in SettingsPage
lib/data/model/app/tab.dart
lib/data/model/app/tab.g.dart
lib/hive/hive_registrar.g.dart
lib/data/store/setting.dart
lib/view/page/home.dart
lib/view/page/setting/entries/home_tabs.dart
lib/view/page/setting/entries/app.dart
lib/view/page/setting/entry.dart
Refactor SettingsStore property declarations
  • Collapse multi-line propertyDefault and listProperty calls into single-line invocations
  • Adjust formatting for fromObj closures in windowState property
lib/data/store/setting.dart
Update fl_lib dependency
  • Bump fl_lib git ref from v1.0.345 to v1.0.346
  • Enable local path override for fl_lib in dependency_overrides
pubspec.yaml

Assessment against linked issues

Issue Objective Addressed Explanation
#887 Allow users to customize which tabs are displayed on the home page.
#887 Persist and load the user's custom tab selection for the home page.
#887 Provide a UI in the settings for users to select and reorder home page tabs.

Possibly linked issues

  • new: custom tabs #887: The PR adds a new setting and UI to allow users to customize and reorder the tabs displayed on the home page, directly addressing the issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Remove or guard the dprint debug statements in SettingStore.homeTabs.fromObj to avoid noisy logs in production.
  • Extract the AppTab parsing logic in homeTabs.fromObj into a standalone helper or utility function to improve readability and testability.
  • Consider subscribing to changes in the homeTabs store within HomePage so that updating the tab order in settings takes effect immediately without a restart.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Remove or guard the dprint debug statements in SettingStore.homeTabs.fromObj to avoid noisy logs in production.
- Extract the AppTab parsing logic in homeTabs.fromObj into a standalone helper or utility function to improve readability and testability.
- Consider subscribing to changes in the homeTabs store within HomePage so that updating the tab order in settings takes effect immediately without a restart.

## Individual Comments

### Comment 1
<location> `lib/view/page/setting/entries/home_tabs.dart:81` </location>
<code_context>
+
+  Widget _buildTabItem(AppTab tab, int index, bool isSelected) {
+    return Card(
+      key: ValueKey('${tab.name}_$index'),
+      margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
+      child: ReorderableDragStartListener(
</code_context>

<issue_to_address>
Using index in ValueKey may cause unnecessary widget rebuilds.

Use a unique property like tab.name for the ValueKey to ensure widget identity remains stable when reordering.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
      key: ValueKey('${tab.name}_$index'),
=======
      key: ValueKey(tab.name),
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `lib/view/page/setting/entries/home_tabs.dart:83` </location>
<code_context>
+    return Card(
+      key: ValueKey('${tab.name}_$index'),
+      margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
+      child: ReorderableDragStartListener(
+        index: index,
+        child: ListTile(
</code_context>

<issue_to_address>
ReorderableDragStartListener is used for both selected and available tabs.

Only wrap selected tab items with ReorderableDragStartListener to prevent drag handles from appearing on non-reorderable available tabs.
</issue_to_address>

### Comment 3
<location> `lib/view/page/setting/entries/home_tabs.dart:117` </location>
<code_context>
+  }
+
+  void _removeTab(AppTab tab) {
+    if (_selectedTabs.length <= 1) {
+      context.showSnackBar(l10n.atLeastOneTab);
+      return;
+    }
</code_context>

<issue_to_address>
Preventing removal of the last tab is good, but consider disabling the delete icon.

Disabling or hiding the delete icon when only one tab remains would improve user experience by preventing unnecessary actions.

Suggested implementation:

```
  void _removeTab(AppTab tab) {

```

```
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar(
        title: Text(l10n.homeTabs),
      ),
      body: ListView.builder(
        itemCount: _selectedTabs.length,
        itemBuilder: (context, index) {
          final tab = _selectedTabs[index];
          final canRemove = _selectedTabs.length > 1;
          return ListTile(
            title: Text(tab.label),
            trailing: IconButton(
              icon: Icon(Icons.delete),
              onPressed: canRemove ? () => _removeTab(tab) : null,
              color: canRemove ? null : Theme.of(context).disabledColor,
              tooltip: canRemove ? l10n.removeTab : l10n.atLeastOneTab,
            ),
          );
        },
      ),

```

- If you use a custom widget for tab list items, apply the same logic to the delete icon there.
- If you want to hide the icon instead of disabling it, replace the `IconButton` with `canRemove ? IconButton(...) : SizedBox.shrink()`.
- Make sure `tab.label` and `l10n.removeTab`/`l10n.atLeastOneTab` exist or adjust as needed for your localization and tab model.
</issue_to_address>

### Comment 4
<location> `lib/data/model/app/tab.g.dart:31` </location>
<code_context>
+
+  @override
+  void write(BinaryWriter writer, AppTab obj) {
+    switch (obj) {
+      case AppTab.server:
+        writer.writeByte(0);
+      case AppTab.ssh:
+        writer.writeByte(1);
+      case AppTab.file:
+        writer.writeByte(2);
+      case AppTab.snippet:
+        writer.writeByte(3);
+    }
</code_context>

<issue_to_address>
Missing break statements in switch cases may cause unintended fallthrough.

Add break statements after each case in the switch to prevent unintended fallthrough and ensure only the correct byte is written.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


Widget _buildTabItem(AppTab tab, int index, bool isSelected) {
return Card(
key: ValueKey('${tab.name}_$index'),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Using index in ValueKey may cause unnecessary widget rebuilds.

Use a unique property like tab.name for the ValueKey to ensure widget identity remains stable when reordering.

Suggested change
key: ValueKey('${tab.name}_$index'),
key: ValueKey(tab.name),

return Card(
key: ValueKey('${tab.name}_$index'),
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: ReorderableDragStartListener(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: ReorderableDragStartListener is used for both selected and available tabs.

Only wrap selected tab items with ReorderableDragStartListener to prevent drag handles from appearing on non-reorderable available tabs.

Comment on lines +117 to +118
if (_selectedTabs.length <= 1) {
context.showSnackBar(l10n.atLeastOneTab);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Preventing removal of the last tab is good, but consider disabling the delete icon.

Disabling or hiding the delete icon when only one tab remains would improve user experience by preventing unnecessary actions.

Suggested implementation:

  void _removeTab(AppTab tab) {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar(
        title: Text(l10n.homeTabs),
      ),
      body: ListView.builder(
        itemCount: _selectedTabs.length,
        itemBuilder: (context, index) {
          final tab = _selectedTabs[index];
          final canRemove = _selectedTabs.length > 1;
          return ListTile(
            title: Text(tab.label),
            trailing: IconButton(
              icon: Icon(Icons.delete),
              onPressed: canRemove ? () => _removeTab(tab) : null,
              color: canRemove ? null : Theme.of(context).disabledColor,
              tooltip: canRemove ? l10n.removeTab : l10n.atLeastOneTab,
            ),
          );
        },
      ),

  • If you use a custom widget for tab list items, apply the same logic to the delete icon there.
  • If you want to hide the icon instead of disabling it, replace the IconButton with canRemove ? IconButton(...) : SizedBox.shrink().
  • Make sure tab.label and l10n.removeTab/l10n.atLeastOneTab exist or adjust as needed for your localization and tab model.

@lollipopkit lollipopkit merged commit e51804f into main Sep 2, 2025
1 check passed
@lollipopkit lollipopkit deleted the lollipopkit/issue887 branch September 2, 2025 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new: custom tabs

2 participants