-
Notifications
You must be signed in to change notification settings - Fork 20
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
Comments
test.dart.zip |
Hello @OICQ469 |
test.dart.zip |
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,
),
);
},
),
);
}
}
|
This seems to be a bug combined with |
thank |
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 |
I will do some more tests, so unfortunately the fix will come in the next days. @OICQ469 onReorder: (ReorderedListFunction reorderedListFunction) {
final updatedFruits = reorderedListFunction(
<String>[..._fruits, 'button'],
) as List<String>;
setState(() {
_fruits = updatedFruits..removeLast();
});
}, |
I just published version |
900_1728291219.mp4
Uploading test.dart.zip…
The text was updated successfully, but these errors were encountered: