From 5c5db5fe9a4eca6a7cc0b945c478e8614139d1e6 Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Sat, 26 Oct 2024 11:53:15 +0900 Subject: [PATCH] fix: offset reorder index --- lib/view/page/settings/accounts_page.dart | 9 ++++++--- lib/view/page/settings/tabs_page.dart | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/view/page/settings/accounts_page.dart b/lib/view/page/settings/accounts_page.dart index cabb21ed9..954b37467 100644 --- a/lib/view/page/settings/accounts_page.dart +++ b/lib/view/page/settings/accounts_page.dart @@ -1,3 +1,4 @@ +import 'dart:math'; import 'dart:ui'; import 'package:flutter/material.dart'; @@ -58,9 +59,11 @@ class AccountsPage extends HookConsumerWidget { } }, itemCount: accounts.length + 2, - onReorder: (oldIndex, newIndex) => ref - .read(accountsNotifierProvider.notifier) - .reorder(oldIndex, newIndex), + onReorder: (oldIndex, newIndex) => + ref.read(accountsNotifierProvider.notifier).reorder( + max(0, oldIndex - 1), + min(newIndex - 1, accounts.length), + ), proxyDecorator: (child, _, animation) => AnimatedBuilder( animation: animation, builder: (context, child) { diff --git a/lib/view/page/settings/tabs_page.dart b/lib/view/page/settings/tabs_page.dart index 2bcd401f3..51601e449 100644 --- a/lib/view/page/settings/tabs_page.dart +++ b/lib/view/page/settings/tabs_page.dart @@ -64,9 +64,11 @@ class TabsPage extends HookConsumerWidget { } }, itemCount: tabs.length + 2, - onReorder: (oldIndex, newIndex) => ref - .read(timelineTabsNotifierProvider.notifier) - .reorder(oldIndex, min(newIndex, tabs.length)), + onReorder: (oldIndex, newIndex) => + ref.read(timelineTabsNotifierProvider.notifier).reorder( + max(0, oldIndex - 1), + min(newIndex - 1, tabs.length), + ), proxyDecorator: (child, _, animation) => AnimatedBuilder( animation: animation, builder: (context, child) {