Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Amse_Tp2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lila NICKLER
Amse_Tp2
Commits
fe141d90
Commit
fe141d90
authored
Feb 25, 2021
by
Lila NICKLER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exercice 7 affichage + mouvement + melange
parent
8b0b3919
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
229 additions
and
8 deletions
+229
-8
Exercice 3.dart
lib/Exercice 3.dart
+9
-0
Exercice 6.dart
lib/Exercice 6.dart
+6
-8
Exercice 7.dart
lib/Exercice 7.dart
+214
-0
No files found.
lib/Exercice 3.dart
View file @
fe141d90
...
...
@@ -7,6 +7,7 @@ import 'Exercice 2.dart';
import
'Exercice 4.dart'
;
import
'Exercice 5.dart'
;
import
'Exercice 6.dart'
;
import
'Exercice 7.dart'
;
class
DisplayExercice
extends
StatelessWidget
{
@override
...
...
@@ -52,6 +53,14 @@ class DisplayExercice extends StatelessWidget{
subtitle:
Text
(
"Affichage d'une tuile a a partir d'une image"
),
onTap:
(){
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)=>
PositionedTiles
()));
},)),
Card
(
child:
ListTile
(
leading:
Icon
(
Icons
.
wb_sunny_outlined
),
title:
Text
(
"Exercice 7"
),
subtitle:
Text
(
"Affichage d'une tuile a a partir d'une image"
),
onTap:
(){
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)=>
ImageGridViewTileSwap
()));
},))
],
...
...
lib/Exercice 6.dart
View file @
fe141d90
...
...
@@ -66,27 +66,25 @@ class PositionedTilesState extends State<PositionedTiles> {
child:
TileWidget
(
new
Tile
(
Colors
.
white
,
0
)),
);
}
else
}
else
{
return
Container
(
child:
InkWell
(
child:
_listTile
[
index
],
onTap:
()
{
if
(
index
==
indexSwap
-
1
||
index
==
indexSwap
+
1
||
index
==
indexSwap
-
_currentSliderValue
||
index
==
indexSwap
+
_currentSliderValue
)
{
swapTiles
(
index
,
indexSwap
);
}
},
)
},
)
);
}
});
}
);
}
int
_currentSliderValue
=
3
;
List
<
Widget
>
tiles
=
List
<
Widget
>.
generate
(
10
*
10
,
(
index
)
=>
TileWidget
(
Tile
.
randomColor
(
index
)));
...
...
lib/Exercice 7.dart
0 → 100644
View file @
fe141d90
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/material.dart'
;
import
'dart:math'
;
class
TileUp
{
String
imageURL
;
Alignment
alignment
;
int
index
;
TileUp
({
this
.
imageURL
,
this
.
alignment
,
this
.
index
});
int
getIndex
()
{
return
this
.
index
;
}
Widget
croppedImageTile
(
int
size
)
{
return
FittedBox
(
fit:
BoxFit
.
fill
,
child:
ClipRect
(
child:
Container
(
child:
Align
(
alignment:
this
.
alignment
,
widthFactor:
1
/
size
,
heightFactor:
1
/
size
,
child:
Image
.
network
(
this
.
imageURL
),
),
),
),
);
}
}
List
<
TileUp
>
createListTile
(
int
value
,
String
imageURL
)
{
double
pas
=
(
2
/((
value
-
1
)));
List
<
TileUp
>
_listTile
=
<
TileUp
>[];
double
i
;
double
j
;
int
index
=
0
;
for
(
i
=
-
1
;
i
<=
1
;
i
+=
pas
)
{
for
(
j
=-
1
;
j
<=
1
;
j
+=
pas
)
{
_listTile
.
add
(
new
TileUp
(
imageURL:
imageURL
,
alignment:
Alignment
(
j
,
i
),
index:
index
));
index
++;
}
}
return
_listTile
;
}
Widget
createTileUpWidgetFrom
(
TileUp
tile
,
int
size
)
{
return
InkWell
(
child:
tile
.
croppedImageTile
(
size
),
);
}
List
<
Widget
>
createWidgetList
(
List
<
TileUp
>
lt
,
int
size
){
List
<
Widget
>
lw
=<
Widget
>[];
for
(
int
i
=
0
;
i
<
lt
.
length
;
i
++){
lw
.
add
(
createTileUpWidgetFrom
(
lt
[
i
],
size
));
}
return
lw
;
}
class
ImageGridViewTileSwap
extends
StatefulWidget
{
@override
_ImageGridViewTileSwapState
createState
()
=>
_ImageGridViewTileSwapState
();
}
class
_ImageGridViewTileSwapState
extends
State
<
ImageGridViewTileSwap
>
{
int
_currentSliderValue
=
3
;
String
imageURL
=
"https://picsum.photos/512"
;
List
<
Widget
>
_listTile
=
createWidgetList
(
createListTile
(
3
,
"https://picsum.photos/512"
),
3
);
int
indexSwap
=
0
;
GridView
creatGridView
(
List
<
Widget
>
_listTile
,
int
value
)
{
return
GridView
.
builder
(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount
(
crossAxisCount:
value
,
crossAxisSpacing:
2.0
,
mainAxisSpacing:
2.0
),
itemCount:
value
*
value
,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
if
(
index
==
indexSwap
)
{
return
Container
(
decoration:
BoxDecoration
(
border:
Border
.
all
(
color:
Colors
.
black
,
width:
2
)
),
child:
Container
(
color:
Colors
.
white
,
)
);
}
else
{
return
Container
(
child:
InkWell
(
child:
_listTile
[
index
],
onTap:
()
{
if
(
index
==
indexSwap
-
1
||
index
==
indexSwap
+
1
||
index
==
indexSwap
-
_currentSliderValue
||
index
==
indexSwap
+
_currentSliderValue
)
{
swapTiles
(
index
,
indexSwap
);
}
},
)
);
}
}
);
}
Widget
build
(
BuildContext
context
)
{
var
mediaQueryData
=
MediaQuery
.
of
(
context
);
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
"Exercice 7 - Jeu du taquin"
),
),
body:
Center
(
child:
ListView
(
scrollDirection:
Axis
.
vertical
,
shrinkWrap:
true
,
children:
[
SizedBox
(
height:
500
,
width:
400
,
child:
Container
(
child:
creatGridView
(
_listTile
,
_currentSliderValue
)
),
),
Container
(
width:
mediaQueryData
.
size
.
width
*
(
7
/
8
),
child:
Slider
(
value:
_currentSliderValue
.
toDouble
(),
min:
2
,
max:
10
,
divisions:
9
,
label:
_currentSliderValue
.
round
().
toString
(),
onChanged:
(
double
value
)
{
setState
(()
{
indexSwap
=
0
;
_currentSliderValue
=
value
.
toInt
();
_listTile
=
createWidgetList
(
createListTile
(
_currentSliderValue
,
"https://picsum.photos/512"
),
_currentSliderValue
);
});
}),)
],
)
),
floatingActionButton:
FloatingActionButton
(
onPressed:
()
{
mixTiles
(
100
);
},
child:
Icon
(
Icons
.
play_arrow_rounded
),
backgroundColor:
Colors
.
deepPurple
,
),
floatingActionButtonLocation:
FloatingActionButtonLocation
.
centerDocked
);
}
swapTiles
(
int
index1
,
int
emptyIndex
)
{
setState
(()
{
print
(
"Button pressed"
);
_listTile
.
insert
(
index1
,
_listTile
.
removeAt
(
emptyIndex
));
if
(
index1
==
_currentSliderValue
+
emptyIndex
)
{
_listTile
.
insert
(
emptyIndex
,
_listTile
.
removeAt
(
index1
-
1
));
}
if
(
index1
==
emptyIndex
-
_currentSliderValue
)
{
_listTile
.
insert
(
emptyIndex
,
_listTile
.
removeAt
(
index1
+
1
));
}
indexSwap
=
index1
;
});
}
mixTiles
(
int
mixMouvement
)
{
Random
random
=
new
Random
();
int
rng
=
random
.
nextInt
(
3
);
int
mouvement
;
indexSwap
=
random
.
nextInt
(
_currentSliderValue
);
for
(
int
i
=
0
;
i
<
mixMouvement
;
i
++)
{
rng
=
random
.
nextInt
(
3
);
switch
(
rng
){
case
0
:
mouvement
=
indexSwap
+
1
;
break
;
case
1
:
mouvement
=
indexSwap
-
1
;
break
;
case
2
:
mouvement
=
indexSwap
-
_currentSliderValue
;
break
;
case
3
:
mouvement
=
indexSwap
+
_currentSliderValue
;
}
if
(
mouvement
>
(
_currentSliderValue
*
_currentSliderValue
)-
1
||
mouvement
<
0
)
{
mouvement
=
indexSwap
;
}
print
(
mouvement
);
print
(
indexSwap
);
swapTiles
(
mouvement
,
indexSwap
);
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment