Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
JeuDeTaquin
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
Benjamin LEROUX
JeuDeTaquin
Commits
7c849a6c
Commit
7c849a6c
authored
Feb 16, 2021
by
Benjamin LEROUX
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exo6 taille variable
parent
aee7978f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
33 deletions
+51
-33
exo6.dart
lib/exo6.dart
+51
-33
No files found.
lib/exo6.dart
View file @
7c849a6c
...
...
@@ -40,11 +40,10 @@ class TileWidget extends StatelessWidget {
}
int
emptyIndex
=
0
;
int
size
=
4
;
List
<
Widget
>
createTileWidgets
(){
List
<
Widget
>
createTileWidgets
(
double
slide
){
List
<
Widget
>
tiles
=
<
Widget
>[];
int
max
=
s
ize
*
size
;
int
max
=
s
lide
.
toInt
()*
slide
.
toInt
()
;
tiles
.
add
(
TileWidget
(
Tile
(
"Vide"
,
Colors
.
white
)));
for
(
int
i
=
0
;
i
<
max
-
1
;
i
++){
tiles
.
add
(
TileWidget
(
Tile
((
i
+
1
).
toString
(),
Colors
.
grey
)));
...
...
@@ -52,9 +51,6 @@ List<Widget>createTileWidgets(){
return
tiles
;
}
String
getIndex
(
TileWidget
w
){
return
w
.
tile
.
index
;
}
void
main
(
)
=>
runApp
(
new
MaterialApp
(
home:
PositionedTiles
()));
...
...
@@ -64,56 +60,78 @@ class PositionedTiles extends StatefulWidget {
}
class
PositionedTilesState
extends
State
<
PositionedTiles
>
{
List
<
Widget
>
tiles
=
createTileWidgets
();
Widget
icone
=
Icon
(
Icons
.
sentiment_very_satisfied
);
TextStyle
textStyle
=
TextStyle
(
fontSize:
16
,
fontWeight:
FontWeight
.
bold
,);
var
appBar
=
AppBar
(
title:
Text
(
'Exo 6'
),);
double
_currentSlideValue
=
4
;
List
<
Widget
>
tiles
=
createTileWidgets
(
4
);
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'Moving Tiles'
),
centerTitle:
true
,
),
body:
GridView
.
builder
(
padding:
const
EdgeInsets
.
all
(
10
),
itemCount:
size
*
size
,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount
(
crossAxisCount:
size
,
crossAxisSpacing:
5.0
,
mainAxisSpacing:
5.0
,
appBar:
appBar
,
body:
ListView
(
children:
[
Container
(
height:
((
MediaQuery
.
of
(
context
).
size
.
height
)*
0.7
),
child:
GridView
.
builder
(
padding:
const
EdgeInsets
.
all
(
10
),
itemCount:
_currentSlideValue
.
toInt
()*
_currentSlideValue
.
toInt
(),
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount
(
crossAxisCount:
_currentSlideValue
.
toInt
(),
crossAxisSpacing:
5.0
,
mainAxisSpacing:
5.0
,
),
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
InkWell
(
child:
tiles
[
index
],
onTap:
(){
swapTiles
(
index
,
emptyIndex
);
},
);
},
),
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
InkWell
(
child:
tiles
[
index
],
onTap:
(){
swapTiles
(
index
,
emptyIndex
);
},
);
},
),
Row
(
children:
<
Widget
>[
Container
(
width:
90
,
child:
Text
(
'Taille:'
,
style:
textStyle
,
textAlign:
TextAlign
.
center
,),
padding:
EdgeInsets
.
fromLTRB
(
8
,
0
,
0
,
0
),),
Container
(
height:
((
MediaQuery
.
of
(
context
).
size
.
height
)/
7
)-
appBar
.
preferredSize
.
height
,
width:
MediaQuery
.
of
(
context
).
size
.
width
-
90
,
child:
Slider
(
value:
_currentSlideValue
,
min:
2
,
max:
7
,
divisions:
5
,
label:
_currentSlideValue
.
round
().
toString
(),
onChanged:
(
double
value
)
{
setState
(()
{
_currentSlideValue
=
value
;
tiles
=
createTileWidgets
(
_currentSlideValue
);
//initialSize=_currentSlideValue;
});
}
),
),
]
),
],
)
);
}
swapTiles
(
int
current
,
int
empty
)
{
setState
(()
{
icone
=
Icon
(
Icons
.
favorite
);
print
(
current
);
if
(
current
==
empty
+
1
&&
current
%
size
!=
0
){
//print(current);
if
(
current
==
empty
+
1
&&
current
%
_currentSlideValue
!=
0
){
emptyIndex
=
current
;
tiles
.
insert
(
empty
,
tiles
.
removeAt
(
current
));
}
else
if
(
current
==
empty
-
1
&&
empty
%
siz
e
!=
0
){
}
else
if
(
current
==
empty
-
1
&&
empty
%
_currentSlideValu
e
!=
0
){
emptyIndex
=
current
;
tiles
.
insert
(
empty
,
tiles
.
removeAt
(
current
));
}
else
if
(
current
==
empty
+
siz
e
){
else
if
(
current
==
empty
+
_currentSlideValu
e
){
emptyIndex
=
current
;
tiles
.
insert
(
current
,
tiles
.
removeAt
(
empty
));
tiles
.
insert
(
empty
,
tiles
.
removeAt
(
current
-
1
));
}
else
if
(
current
==
empty
-
siz
e
){
}
else
if
(
current
==
empty
-
_currentSlideValu
e
){
emptyIndex
=
current
;
tiles
.
insert
(
current
,
tiles
.
removeAt
(
empty
));
tiles
.
insert
(
empty
,
tiles
.
removeAt
(
current
+
1
));
}
else
print
(
"Can't move this"
);
});
}
}
\ 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