Commit b3d7877e authored by Timothé KOBAK's avatar Timothé KOBAK

travail lundi

parent 46b79fb5
...@@ -62,16 +62,16 @@ class _Exo6 extends State<Exo6> { ...@@ -62,16 +62,16 @@ class _Exo6 extends State<Exo6> {
-1 + 2 * i.toDouble() / (colNb.toDouble() - 1)) -1 + 2 * i.toDouble() / (colNb.toDouble() - 1))
); );
Key k = UniqueKey();
tiles.add( tiles.add(
Flexible(child: Container( Flexible(key: k, child: Container(
margin: EdgeInsets.all(10.0 / colNb), margin: EdgeInsets.all(10.0 / colNb),
child: InkWell( child: InkWell(
child: tile.croppedImageTile(1 / colNb), child: tile.croppedImageTile(1 / colNb),
onTap: () { onTap: () {
setState(() { setState(() {
print(indexcopy); swapTiles(k);
tiles.insert(emptyTileIndex, tiles.removeAt(indexcopy));
emptyTileIndex = indexcopy;
}); });
} }
) )
...@@ -84,6 +84,13 @@ class _Exo6 extends State<Exo6> { ...@@ -84,6 +84,13 @@ class _Exo6 extends State<Exo6> {
} }
} }
void swapTiles(Key k){
var t = tiles.singleWhere((element) => element.key == k);
tiles[emptyTileIndex] = t;
tiles[tiles.indexOf(t)] = Flexible(child: Container(margin: EdgeInsets.all(10.0 / colNb)));
emptyTileIndex = tiles.indexOf(t);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment