Skip to content

Fix analysis errors#1176

Closed
GT-610 wants to merge 1 commit into
mainfrom
fix-analysis
Closed

Fix analysis errors#1176
GT-610 wants to merge 1 commit into
mainfrom
fix-analysis

Conversation

@GT-610
Copy link
Copy Markdown
Collaborator

@GT-610 GT-610 commented May 21, 2026

Summary by CodeRabbit

  • Refactor
    • Updated internal component implementations across server settings pages (tabs, ordering, functions, and virtual keys) and connection monitoring to align with current framework API standards.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

📝 Walkthrough

Walkthrough

This PR updates Flutter list view widget APIs across six files. The connection_stats.dart file migrates from the legacy cacheExtent parameter to the new ScrollCacheExtent.pixels(200) API on ListView.builder, adding an import for package:flutter/rendering.dart. Additionally, five settings pages—home_tabs.dart, srv_detail_seq.dart, srv_func_seq.dart, srv_seq.dart, and virt_key.dart—migrate their ReorderableListView.builder callbacks from the deprecated onReorder parameter to onReorderItem, keeping the handler implementations unchanged.

Possibly related PRs

Suggested reviewers

  • lollipopkit
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Fix analysis errors' is vague and generic, using non-descriptive language that does not convey meaningful information about the specific changes made (Flutter rendering imports and ReorderableListView parameter updates). Consider a more specific title such as 'Update ReorderableListView callbacks and rendering imports' to better reflect the actual changes made across multiple files.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-analysis

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot requested a review from lollipopkit May 21, 2026 01:44
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/view/page/setting/entries/home_tabs.dart`:
- Line 51: The _onReorder handler is still applying the legacy "if oldIndex <
newIndex then newIndex -= 1" adjustment even though onReorderItem supplies an
already-corrected newIndex; remove that decrement logic from the _onReorder
implementation (referencing _onReorder and the onReorderItem callback
assignment) and simply use the provided newIndex (optionally clamp it to valid
range) when moving the item so downward drags are not mispositioned.

In `@lib/view/page/setting/seq/srv_seq.dart`:
- Line 57: The onReorderItem handler currently applies an extra manual index
adjustment (the if (targetIndex > oldIndex) { targetIndex -= 1; } logic) which
causes off-by-one moves; remove that manual correction so the handler uses the
provided target index directly (i.e., stop mutating targetIndex based on
oldIndex) within the onReorderItem callback to ensure items move to the intended
position.

In `@lib/view/page/setting/seq/virt_key.dart`:
- Line 78: The _handleReorder function is double-normalizing indices: when used
as the callback for onReorderItem it should not manually adjust targetIndex;
remove the conditional block that does "if (targetIndex > oldIndex) targetIndex
-= 1" (or any equivalent decrement) inside _handleReorder so the method uses the
indices provided by onReorderItem directly and reorders the backing list
accordingly (keep references to _handleReorder and onReorderItem to locate the
code).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 26f36268-e608-43f6-a869-79df8a4ed568

📥 Commits

Reviewing files that changed from the base of the PR and between c57be23 and f871320.

⛔ Files ignored due to path filters (1)
  • pubspec.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • lib/view/page/server/connection_stats.dart
  • lib/view/page/setting/entries/home_tabs.dart
  • lib/view/page/setting/seq/srv_detail_seq.dart
  • lib/view/page/setting/seq/srv_func_seq.dart
  • lib/view/page/setting/seq/srv_seq.dart
  • lib/view/page/setting/seq/virt_key.dart

child: ReorderableListView.builder(
itemCount: _selectedTabs.length,
onReorder: _onReorder,
onReorderItem: _onReorder,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

In Flutter ReorderableListView.builder, does onReorderItem already provide a corrected newIndex (without needing oldIndex < newIndex => newIndex -= 1)?

💡 Result:

No. In Flutter’s ReorderableListView.builder, the older callback onReorder passes a newIndex that still requires the “if oldIndex < newIndex then newIndex -= 1” correction. Flutter deprecated onReorder specifically because it needed that manual adjustment, and introduced onReorderItem to automatically adjust newIndex for you. Evidence: Flutter’s release notes state that the onReorder callback required a manual correction for newIndex when oldIndex is before newIndex, and that onReorderItem “solves this problem by doing the correction automatically” [1]. The ReorderableListView.builder docs also note that onReorderItem adjusts the newIndex parameter and that onReorder is deprecated in favor of it [2]. So: - Using onReorder: you generally need the adjustment (e.g., if oldIndex < newIndex then newIndex -= 1) [1]. - Using onReorderItem: you do not need that adjustment; newIndex is already corrected [1][2].

Citations:


Remove legacy newIndex correction when using onReorderItem.

onReorderItem already provides an adjusted newIndex, and Flutter deprecated onReorder specifically because it required the manual “if oldIndex < newIndex then newIndex -= 1” correction. Keeping the decrement in _onReorder will misplace items while dragging downward.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/view/page/setting/entries/home_tabs.dart` at line 51, The _onReorder
handler is still applying the legacy "if oldIndex < newIndex then newIndex -= 1"
adjustment even though onReorderItem supplies an already-corrected newIndex;
remove that decrement logic from the _onReorder implementation (referencing
_onReorder and the onReorderItem callback assignment) and simply use the
provided newIndex (optionally clamp it to valid range) when moving the item so
downward drags are not mispositioned.

return ReorderableListView.builder(
footer: const SizedBox(height: 77),
onReorder: (oldIndex, newIndex) {
onReorderItem: (oldIndex, newIndex) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

After migrating ReorderableListView from onReorder to onReorderItem, is old logic if (targetIndex > oldIndex) targetIndex -= 1 still valid?

💡 Result:

No, the logic if (targetIndex > oldIndex) targetIndex -= 1 is no longer valid and should be removed when migrating to onReorderItem [1][2]. The onReorder callback was deprecated precisely because it provided raw indices that required manual correction to account for the list's length shrinking after an item was removed [1][2]. The new onReorderItem callback handles this adjustment automatically, providing the expected newIndex directly [2]. If you keep the old adjustment logic after switching to onReorderItem, your reordering will behave incorrectly, likely causing items to be inserted at the wrong positions [2]. Migration Summary: - Old Callback (onReorder): Required manual if (newIndex > oldIndex) newIndex -= 1;. - New Callback (onReorderItem): Requires no index adjustment [2]. Example of the migration: // Before onReorder: (int oldIndex, int newIndex) { if (oldIndex < newIndex) { newIndex -= 1; } // update list... } // After onReorderItem: (int oldIndex, int newIndex) { // update list directly using newIndex... } [2]

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="lib/view/page/setting/seq/srv_seq.dart"

echo "== File =="
ls -la "$FILE"

echo
echo "== Relevant snippet (around onReorderItem) =="
rg -n "onReorderItem\s*:" "$FILE"
# Print a small window around the match
LINE=$(rg -n "onReorderItem\s*:" "$FILE" | head -n1 | cut -d: -f1)
START=$((LINE-10))
END=$((LINE+30))
sed -n "${START},${END}p" "$FILE" | nl -ba | sed 's/^/ /'

echo
echo "== Any targetIndex adjustment logic nearby =="
rg -n "targetIndex|newIndex|oldIndex" "$FILE" | head -n 50

Repository: lollipopkit/flutter_server_box

Length of output: 329


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="lib/view/page/setting/seq/srv_seq.dart"

echo "== Relevant region (lines 45-90) =="
sed -n '45,90p' "$FILE" | cat -n

echo
echo "== Search for targetIndex / adjustment logic =="
rg -n "targetIndex|newIndex\s*-=|if\s*\(.*newIndex.*>\s*.*oldIndex|oldIndex.*targetIndex" "$FILE" || true

Repository: lollipopkit/flutter_server_box

Length of output: 1959


Fix off-by-one index handling in onReorderItem
Remove the manual if (targetIndex > oldIndex) { targetIndex -= 1; } adjustment inside onReorderItem; onReorderItem already provides the correct target index, and keeping the old onReorder correction will misplace items (notably on downward moves).

Suggested fix
       onReorderItem: (oldIndex, newIndex) {
-        var targetIndex = newIndex;
-        if (targetIndex > oldIndex) {
-          targetIndex -= 1;
-        }
+        final targetIndex = newIndex;
         if (targetIndex == oldIndex) {
           return;
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onReorderItem: (oldIndex, newIndex) {
onReorderItem: (oldIndex, newIndex) {
final targetIndex = newIndex;
if (targetIndex == oldIndex) {
return;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/view/page/setting/seq/srv_seq.dart` at line 57, The onReorderItem handler
currently applies an extra manual index adjustment (the if (targetIndex >
oldIndex) { targetIndex -= 1; } logic) which causes off-by-one moves; remove
that manual correction so the handler uses the provided target index directly
(i.e., stop mutating targetIndex based on oldIndex) within the onReorderItem
callback to ensure items move to the intended position.

proxyDecorator: reorderProxyDecorator,
itemBuilder: (_, idx) => _buildListItem(_order[idx], idx),
onReorder: _handleReorder,
onReorderItem: _handleReorder,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does Flutter's onReorderItem callback already normalize newIndex so handlers should not manually decrement it when newIndex > oldIndex?

💡 Result:

Yes—but only if you’re using Flutter’s newer onReorderItem callback (not the deprecated onReorder). When using the deprecated onReorder callback, you must account for the fact that when oldIndex < newIndex, removing the item at oldIndex shortens the list by 1; therefore implementations typically decrement newIndex by 1 before inserting. This is explicitly documented in ReorderCallback’s example and description: “If oldIndex is before newIndex… reducing the list’s length by one… account for this when inserting before newIndex,” with sample code that does if (oldIndex < newIndex) newIndex -= 1. [1] Flutter then introduced onReorderItem to “automatically handle index adjustments” so you should not apply that manual correction when items are moved downward. The Flutter breaking-changes documentation states: “The onReorder callback… required a manual correction for… newIndex… The new callback, onReorderItem, solves this problem by doing the correction automatically,” and shows migrating by removing the manual newIndex -= 1 logic. [2] So the rule is: - onReorderItem: don’t manually decrement newIndex. - onReorder: do manually decrement newIndex when oldIndex < newIndex (i.e., when moving downward). [1]

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show the relevant area around _handleReorder in the specified file
FILE="lib/view/page/setting/seq/virt_key.dart"
if [ ! -f "$FILE" ]; then
  echo "Missing file: $FILE"
  exit 1
fi

# Print line numbers around the snippet region (approx based on review comment)
nl -ba "$FILE" | sed -n '60,170p'

Repository: lollipopkit/flutter_server_box

Length of output: 118


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="lib/view/page/setting/seq/virt_key.dart"
awk '{printf "%d\t%s\n", NR, $0}' "$FILE" | sed -n '60,170p'

Repository: lollipopkit/flutter_server_box

Length of output: 3090


Remove manual index decrement in _handleReorder when using onReorderItem in virt_key.dart.
_handleReorder still does if (targetIndex > oldIndex) targetIndex -= 1 (lines ~131-134) even though the list uses onReorderItem: _handleReorder, which already applies the needed index normalization—this will misplace reordered items.

Suggested fix
   void _handleReorder(int oldIndex, int newIndex) {
-    var targetIndex = newIndex;
-    if (targetIndex > oldIndex) {
-      targetIndex -= 1;
-    }
+    final targetIndex = newIndex;
     if (targetIndex == oldIndex) {
       return;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/view/page/setting/seq/virt_key.dart` at line 78, The _handleReorder
function is double-normalizing indices: when used as the callback for
onReorderItem it should not manually adjust targetIndex; remove the conditional
block that does "if (targetIndex > oldIndex) targetIndex -= 1" (or any
equivalent decrement) inside _handleReorder so the method uses the indices
provided by onReorderItem directly and reorders the backing list accordingly
(keep references to _handleReorder and onReorderItem to locate the code).

@GT-610 GT-610 closed this May 22, 2026
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.

1 participant