Adding reordering on game creation
continuous-integration/drone/push Build is passing Details

pull/25/head
Arthur VALIN 2 years ago
parent 316eda5ef6
commit b8b67380c1

@ -266,10 +266,22 @@ class _InGameCardConfigState extends State<InGameCardConfig> {
void onDelete(Player p){ void onDelete(Player p){
setState(() { setState(() {
widget.listPlayer.remove(p); widget.listPlayer.remove(p);
}); });
} }
void onReorder(int oldIndex, int newIndex){
setState(() {
if (oldIndex < newIndex) {
newIndex -= 1;
}
final Player item = widget.listPlayer.removeAt(oldIndex);
widget.listPlayer.insert(newIndex, item);
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -313,7 +325,7 @@ class _InGameCardConfigState extends State<InGameCardConfig> {
], ],
), ),
)), )),
ListUserInGame(listPlayer: widget.listPlayer, onDelete: onDelete), ListUserInGame(listPlayer: widget.listPlayer, onDelete: onDelete, onReorder: onReorder,),
Spacer(), Spacer(),
Image( Image(
image: AssetImage("assets/images/start_sentence.png"), image: AssetImage("assets/images/start_sentence.png"),
@ -354,7 +366,8 @@ class _InGameCardConfigState extends State<InGameCardConfig> {
class ListUserInGame extends StatefulWidget { class ListUserInGame extends StatefulWidget {
final List<Player> listPlayer; final List<Player> listPlayer;
final Function(Player) onDelete; final Function(Player) onDelete;
const ListUserInGame({Key? key, required this.listPlayer, required this.onDelete}) : super(key: key); final Function(int, int) onReorder;
const ListUserInGame({Key? key, required this.listPlayer, required this.onDelete, required this.onReorder}) : super(key: key);
@override @override
State<ListUserInGame> createState() => _ListUserInGameState(); State<ListUserInGame> createState() => _ListUserInGameState();
@ -373,11 +386,13 @@ class _ListUserInGameState extends State<ListUserInGame> {
constraints: new BoxConstraints( constraints: new BoxConstraints(
maxHeight: 170, maxHeight: 170,
), ),
child: ListView.builder( child: ReorderableListView.builder(
itemCount: widget.listPlayer.length, itemCount: widget.listPlayer.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
return UserInGame(player: widget.listPlayer[index], onDelete: widget.onDelete); return UserInGame(key:ValueKey(widget.listPlayer[index]) ,player: widget.listPlayer[index], onDelete: widget.onDelete, index: index);
}), },
onReorder: widget.onReorder,
),
), ),
RichText( RichText(
text: TextSpan( text: TextSpan(
@ -402,7 +417,8 @@ class _ListUserInGameState extends State<ListUserInGame> {
class UserInGame extends StatefulWidget { class UserInGame extends StatefulWidget {
final Player player; final Player player;
final Function(Player) onDelete; final Function(Player) onDelete;
const UserInGame({Key? key, required this.player, required this.onDelete}) : super(key: key); final int index;
const UserInGame({Key? key, required this.player, required this.onDelete, required this.index}) : super(key: key);
@override @override
State<UserInGame> createState() => _UserInGameState(); State<UserInGame> createState() => _UserInGameState();
@ -425,7 +441,9 @@ class _UserInGameState extends State<UserInGame> {
), ),
child: Row( child: Row(
children: [ children: [
Container( ReorderableDragStartListener(
index: widget.index,
child : Container(
width: 30, width: 30,
height: 30, height: 30,
decoration: BoxDecoration( decoration: BoxDecoration(
@ -434,6 +452,7 @@ class _UserInGameState extends State<UserInGame> {
image: AssetImage(widget.player.image), fit: BoxFit.cover), image: AssetImage(widget.player.image), fit: BoxFit.cover),
), ),
), ),
),
SizedBox( SizedBox(
width: 10, width: 10,
), ),

Loading…
Cancel
Save