Last active
April 20, 2021 11:05
-
-
Save karabanovbs/1884963b3e7a67249c2683607304f64d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() async { | |
runApp( | |
MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Container( | |
color: Color(0xFF15202D), | |
child: SizedBox.expand( | |
child: ListVisited(), | |
), | |
), | |
), | |
), | |
); | |
} | |
class ListVisited extends StatefulWidget { | |
ListVisited() : super(); | |
@override | |
_ListVisitedState createState() => _ListVisitedState(); | |
} | |
class _ListVisitedState extends State<ListVisited> { | |
final List<int> list = Iterable.generate(100, (i) => i).toList(); | |
@override | |
Widget build(BuildContext context) { | |
return SingleChildScrollView( | |
child: Column( | |
children: [ | |
for (var index in list) | |
DragTarget<int>( | |
onWillAccept: (data) { | |
return true; | |
}, | |
onAccept: (data) { | |
setState(() { | |
var newPos = list.indexOf(index); | |
var dragIndex = list.indexOf(data); | |
var tmp = index; | |
list[newPos] = data; | |
list[dragIndex] = tmp; | |
}); | |
}, | |
builder: (context, List<int?> candidate, rejected) { | |
return Draggable<int>( | |
data: index, | |
child: Container( | |
height: 200, | |
width: 300, | |
child: Center(child: Text(index.toString())), | |
color: Colors.blue, | |
), | |
childWhenDragging: Container( | |
height: 200, | |
width: 300, | |
color: Colors.red, | |
), | |
feedback: Container( | |
height: 200, | |
width: 300, | |
color: Colors.green, | |
), | |
); | |
}, | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment