From 3e7d9c21b9d622424f763ea6b67dbee13a804690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Thu, 27 May 2021 14:19:47 +0200 Subject: [PATCH] Add drag-drop / swap features on tiles --- android/gradle.properties | 4 ++-- lib/entities/tile.dart | 49 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/android/gradle.properties b/android/gradle.properties index aa51064..135006f 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true -app.versionName=0.0.5 -app.versionCode=5 +app.versionName=0.0.6 +app.versionCode=6 diff --git a/lib/entities/tile.dart b/lib/entities/tile.dart index 9d80d4a..e9919d7 100644 --- a/lib/entities/tile.dart +++ b/lib/entities/tile.dart @@ -17,13 +17,60 @@ class Tile { @required this.originalRow, ); - Container widget() { + Container _tileWidget() { return Container( + decoration: BoxDecoration( + color: Colors.black, + border: Border.all( + color: Colors.black, + width: 1, + ), + ), child: Image( image: this.image.image, width: this.size, height: this.size, fit: BoxFit.fill + ), + ); + } + + Container widget() { + return Container( + child: DragTarget<List<int>>( + builder: ( + BuildContext context, + List<dynamic> accepted, + List<dynamic> rejected, + ) { + return Container( + height: this.size, + width: this.size, + color: Colors.cyan, + child: Draggable<List<int>>( + data: [ + this.currentCol, + this.currentRow, + ], + + // Widget when draggable is stationary + child: this._tileWidget(), + + // Widget when draggable is being dragged + feedback: this._tileWidget(), + + // Widget to display on original place when being dragged + childWhenDragging: Container( + height: this.size, + width: this.size, + color: Colors.pinkAccent, + ), + ), + ); + }, + onAccept: (List<int> data) { + print(data.toString()); + }, ) ); } -- GitLab