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
aee7978f
Commit
aee7978f
authored
Feb 15, 2021
by
Benjamin LEROUX
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exo6 taille fixe
parent
21a291b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
133 additions
and
0 deletions
+133
-0
exo6.dart
lib/exo6.dart
+119
-0
main.dart
lib/main.dart
+14
-0
No files found.
lib/exo6.dart
0 → 100644
View file @
aee7978f
import
'package:flutter/material.dart'
;
import
'dart:math'
as
math
;
// ==============
// Models
// ==============
math
.
Random
random
=
new
math
.
Random
();
class
Tile
{
Color
color
;
String
index
;
Tile
(
this
.
index
,
this
.
color
);
}
// ==============
// Widgets
// ==============
class
TileWidget
extends
StatelessWidget
{
final
Tile
tile
;
TileWidget
(
this
.
tile
);
@override
Widget
build
(
BuildContext
context
)
{
return
this
.
coloredBox
();
}
Widget
coloredBox
()
{
return
Container
(
color:
tile
.
color
,
child:
Align
(
child:
Text
(
tile
.
index
.
toString
(),),
alignment:
Alignment
.
center
,
)
);
}
}
int
emptyIndex
=
0
;
int
size
=
4
;
List
<
Widget
>
createTileWidgets
(){
List
<
Widget
>
tiles
=
<
Widget
>[];
int
max
=
size
*
size
;
tiles
.
add
(
TileWidget
(
Tile
(
"Vide"
,
Colors
.
white
)));
for
(
int
i
=
0
;
i
<
max
-
1
;
i
++){
tiles
.
add
(
TileWidget
(
Tile
((
i
+
1
).
toString
(),
Colors
.
grey
)));
}
return
tiles
;
}
String
getIndex
(
TileWidget
w
){
return
w
.
tile
.
index
;
}
void
main
(
)
=>
runApp
(
new
MaterialApp
(
home:
PositionedTiles
()));
class
PositionedTiles
extends
StatefulWidget
{
@override
State
<
StatefulWidget
>
createState
()
=>
PositionedTilesState
();
}
class
PositionedTilesState
extends
State
<
PositionedTiles
>
{
List
<
Widget
>
tiles
=
createTileWidgets
();
Widget
icone
=
Icon
(
Icons
.
sentiment_very_satisfied
);
@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
,
),
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
InkWell
(
child:
tiles
[
index
],
onTap:
(){
swapTiles
(
index
,
emptyIndex
);
},
);
},
),
);
}
swapTiles
(
int
current
,
int
empty
)
{
setState
(()
{
icone
=
Icon
(
Icons
.
favorite
);
print
(
current
);
if
(
current
==
empty
+
1
&&
current
%
size
!=
0
){
emptyIndex
=
current
;
tiles
.
insert
(
empty
,
tiles
.
removeAt
(
current
));
}
else
if
(
current
==
empty
-
1
&&
empty
%
size
!=
0
){
emptyIndex
=
current
;
tiles
.
insert
(
empty
,
tiles
.
removeAt
(
current
));
}
else
if
(
current
==
empty
+
size
){
emptyIndex
=
current
;
tiles
.
insert
(
current
,
tiles
.
removeAt
(
empty
));
tiles
.
insert
(
empty
,
tiles
.
removeAt
(
current
-
1
));
}
else
if
(
current
==
empty
-
size
){
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
lib/main.dart
View file @
aee7978f
...
@@ -4,6 +4,7 @@ import 'package:tp2_taquin/Tile.dart';
...
@@ -4,6 +4,7 @@ import 'package:tp2_taquin/Tile.dart';
import
'exo1.dart'
;
import
'exo1.dart'
;
import
'exo2.dart'
;
import
'exo2.dart'
;
import
'exo6.dart'
;
void
main
(
)
{
void
main
(
)
{
runApp
(
MyApp
());
runApp
(
MyApp
());
...
@@ -94,6 +95,19 @@ class _MyHomePageState extends State<MyHomePage> {
...
@@ -94,6 +95,19 @@ class _MyHomePageState extends State<MyHomePage> {
],
],
),
),
),
),
Card
(
child:
Column
(
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
ListTile
(
trailing:
Icon
(
Icons
.
play_arrow
),
title:
Text
(
'Exercice 6'
),
subtitle:
Text
(
"Animation des tuiles"
),
onTap:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
PositionedTiles
()));},
),
],
),
),
],
],
),
),
),
),
...
...
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