Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug:ReorderableBuilder子项 添加项目按钮在里面固定,拖动会导致错误 #135

Closed
OICQ469 opened this issue Oct 7, 2024 · 9 comments · Fixed by #136
Closed
Labels
bug Something isn't working

Comments

@OICQ469
Copy link

OICQ469 commented Oct 7, 2024

900_1728291219.mp4

Uploading test.dart.zip…

@OICQ469
Copy link
Author

OICQ469 commented Oct 7, 2024

test.dart.zip
This is the project file

@OICQ469 OICQ469 changed the title ReorderableBuilder children An Add item button is fixed inside,Dragging will cause bugs Bug:ReorderableBuilder子项 添加项目按钮在里面固定,拖动会导致错误 Oct 7, 2024
@karvulf
Copy link
Owner

karvulf commented Oct 7, 2024

Hello @OICQ469
Thanks for opening the issue, can you just paste the code from your widget that is using this package? Then I could immediately check if I see the issue

@karvulf karvulf added the Waiting for response Waiting for an answer of the person who opened the issue label Oct 7, 2024
@OICQ469
Copy link
Author

OICQ469 commented Oct 7, 2024

你好@OICQ469感谢您打开这个问题,您能从此软件包的小部件中粘贴代码吗?我可以立即检查我是否看到了问题

test.dart.zip
This is a zip of the code

@OICQ469
Copy link
Author

OICQ469 commented Oct 7, 2024

@karvulf

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_reorderable_grid_view/widgets/widgets.dart';

void main() {
  runApp(const MaterialApp(home: MyApp()));
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _scrollController = ScrollController();
  var index = 1;
  var _fruits = <String>[];

  @override
  Widget build(BuildContext context) {
    final generatedChildren = List.generate(_fruits.length + 1, (index) {
      if (index == _fruits.length)
        // Add button
        return GestureDetector(
            key: Key("button"),
            onTap: () {
              _fruits.add("value${index++}");
              setState(() {});
            },
            child: Container(
              color: Colors.lightBlue,
              child: Text("Button"),
            ));
      else {
        // Item
        return Container(
            key: Key(_fruits.elementAt(index)),
            color: Colors.lightBlue,
            child: Text(_fruits.elementAt(index)));
      }
    });

    return Scaffold(
      body: ReorderableBuilder(
        children: generatedChildren,
        scrollController: _scrollController,
        longPressDelay: Duration(milliseconds: 300),
        lockedIndices: [_fruits.length],
        dragChildBoxDecoration:
            BoxDecoration(color: CupertinoColors.transparent),
        onReorder: (ReorderedListFunction reorderedListFunction) {
          setState(() {
            _fruits = reorderedListFunction(_fruits) as List<String>;
          });
        },
        builder: (children) {
          return GridView(
            controller: _scrollController,
            children: children,
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 4,
              mainAxisSpacing: 4,
              crossAxisSpacing: 8,
            ),
          );
        },
      ),
    );
  }
}

@karvulf
Copy link
Owner

karvulf commented Oct 7, 2024

This seems to be a bug combined with lockedIndices on the last item.
I will try to fix this this evening, thanks for reporting it @OICQ469

@karvulf karvulf added bug Something isn't working and removed Waiting for response Waiting for an answer of the person who opened the issue labels Oct 7, 2024
@OICQ469
Copy link
Author

OICQ469 commented Oct 7, 2024

这似乎是最后一个项目上与lockedIndices结合的错误。我今晚会试着解决这个问题,谢谢你的报告@OICQ469

thank

@karvulf
Copy link
Owner

karvulf commented Oct 7, 2024

I found a fix in the code. It should also fix the issue when new items are appearing. Before, the animation also didn't work. I will release this fix with version 5.3.2. @OICQ469

@karvulf
Copy link
Owner

karvulf commented Oct 7, 2024

I will do some more tests, so unfortunately the fix will come in the next days. @OICQ469
When you are updating, you have to update the code in onReorder because there would be still a bug:

        onReorder: (ReorderedListFunction reorderedListFunction) {
          final updatedFruits = reorderedListFunction(
            <String>[..._fruits, 'button'],
          ) as List<String>;
          setState(() {
            _fruits = updatedFruits..removeLast();
          });
        },

@karvulf
Copy link
Owner

karvulf commented Oct 10, 2024

I just published version 5.3.2 and this should fix the issue @OICQ469 Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants