Open MiaoShichang opened 5 months ago
Problem: After dragging, scroll to the top
want : After dragging, don't scroll to the top
import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_draggable_gridview/flutter_draggable_gridview.dart'; class TPPinJieHomePage extends StatefulWidget { const TPPinJieHomePage({super.key}); @override State<TPPinJieHomePage> createState() => _TPPinJieHomePageState(); } class _TPPinJieHomePageState extends State<TPPinJieHomePage> { final List<int> _datalist = []; @override void initState() { super.initState(); for (int i = 0; i < 50; i++) { _datalist.add(i); } } @override Widget build(BuildContext context) { return Scaffold( appBar: const CupertinoNavigationBar( middle: Text("drag"), ), body: DraggableGridViewBuilder( gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 4, crossAxisSpacing: 1, mainAxisSpacing: 1, ), dragCompletion: (List<DraggableGridItem> list, int beforeIndex, int afterIndex) { print('onDragAccept: $beforeIndex -> $afterIndex'); int one = _datalist[beforeIndex]; if (afterIndex > beforeIndex) { _datalist.insert(afterIndex + 1, one); _datalist.removeAt(beforeIndex); } else if (afterIndex < beforeIndex) { _datalist.insert(afterIndex, _datalist[beforeIndex]); _datalist.removeAt(beforeIndex + 1); } }, children: _getItems(), dragFeedback: (List<DraggableGridItem> list, int index) { return SizedBox( width: 100, height: 100, child: Container( decoration: BoxDecoration( border: Border.all(color: Colors.red, width: 2), ), child: list[index].child), ); }, )); } List<DraggableGridItem> _getItems() { List<DraggableGridItem> items = []; for (var one in _datalist) { items.add(DraggableGridItem( isDraggable: true, child: Container( color: Colors.orange, padding: const EdgeInsets.all(10), child: Center(child: Text("$one")), ), )); } items.add(DraggableGridItem( child: Container( color: Colors.orange, padding: const EdgeInsets.all(10), child: const Center(child: Text("picker")), ), )); return items; } }
Problem: After dragging, scroll to the top
want : After dragging, don't scroll to the top