🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / FLUTTER / Flutter Sortable Drag And Drop ListView sıralabilir liste kullanımı

1-) FLUTTER - Flutter Sortable Drag And Drop ListView sıralabilir liste kullanımı

 

kaynak : https://stackoverflow.com/questions/53908025/flutter-sortable-drag-and-drop-listview

kaynak 2 : https://stackoverflow.com/questions/57805166/all-children-of-this-widget-must-have-a-key-in-reorderable-listview

 

 

1-) EKRAN GÖRÜNTÜSÜ

 

 

enter image description here

 

 

1-) BASİT YAPILIŞI

 

 

 

List<String> _list = ["Apple", "Ball", "Cat", "Dog", "Elephant"];

@override
Widget build(BuildContext context) {
  
return Scaffold(
    appBar:
AppBar(),
    body:
ReorderableListView(
      children:
_list.map((item) => ListTile(key: Key("${item}"), title: Text("${item}"), trailing: Icon(Icons.menu),)).toList(),
      onReorder: (
int start, int current) {
        
// dragging from top to bottom
        
if (start < current) {
          
int end = current - 1;
          
String startItem = _list[start];
          
int i = 0;
          
int local = start;
          
do {
            
_list[local] = _list[++local];
            
i++;
          }
while (i < end - start);
          
_list[end] = startItem;
        }
        
// dragging from bottom to top
        
else if (start > current) {
          
String startItem = _list[start];
          
for (int i = start; i > current; i--) {
            
_list[i] = _list[i - 1];
          }
          
_list[current] = startItem;
        }
        setState(() {});
      },
    ),
  );
}

 

 

 

 

 

2-) KENDİ YAPTIĞIM KESİT

 

 

Widget gridviewContent() {
  
return ReorderableListView(
    scrollDirection:
Axis.vertical,
    shrinkWrap:
true,

    scrollController: ScrollController(),

    onReorder: (int start, int current) {
      
if (start < current) {
        
int end = current - 1;
        
TumBankaModel startItem = gelenModel[start];
        
int i = 0;
        
int local = start;
        
do {
          
gelenModel[local] = gelenModel[++local];
          
i++;
        }
while (i < end - start);
        
gelenModel[end] = startItem;
      }
      
// dragging from bottom to top
      
else if (start > current) {
        
TumBankaModel startItem = gelenModel[start];
        
for (int i = start; i > current; i--) {
          
gelenModel[i] = gelenModel[i - 1];
        }
        
gelenModel[current] = startItem;
      }
      setState(() {});
    },
    children: bodyContent(),
  );
}

List<Widget> bodyContent() {
  
List<Widget> list = [];

  
gelenModel.forEach((element) {
    
list.add(bodyAltContent(element));
  });

  
return list;
}
Padding bodyAltContent(TumBankaModel model) {
  
return Padding(
    padding:
EdgeInsets.only(top: 5),
    key:
ValueKey(model),
    child:
Material(
      
//elevation: 10,
      
elevation: 3,
      shape:
RoundedRectangleBorder(
          borderRadius:
BorderRadius.all(
            
Radius.circular(15.0),
          )),
      child:
InkWell(
        onTap: () {},
        child:
Padding(
          padding:
EdgeInsets.all(2),
          child:
Container(
            child: getColumnItem(model),
          ),
        ),
      ),
    ),
  );
}

 

 

 

 2022 Kasım 10 Perşembe
 296