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
8b0b3919
Commit
8b0b3919
authored
Feb 23, 2021
by
Lila NICKLER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exercice 6
parent
6e0d510b
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
124 additions
and
33 deletions
+124
-33
Exercice 3.dart
lib/Exercice 3.dart
+10
-1
Exercice 5.dart
lib/Exercice 5.dart
+13
-8
Exercice 6.dart
lib/Exercice 6.dart
+98
-21
main.dart
lib/main.dart
+1
-2
pubspec.lock
pubspec.lock
+1
-1
pubspec.yaml
pubspec.yaml
+1
-0
No files found.
lib/Exercice 3.dart
View file @
8b0b3919
...
...
@@ -6,6 +6,7 @@ import 'Exercice 1.dart';
import
'Exercice 2.dart'
;
import
'Exercice 4.dart'
;
import
'Exercice 5.dart'
;
import
'Exercice 6.dart'
;
class
DisplayExercice
extends
StatelessWidget
{
@override
...
...
@@ -40,9 +41,17 @@ class DisplayExercice extends StatelessWidget{
ListTile
(
leading:
Icon
(
Icons
.
wb_sunny_outlined
),
title:
Text
(
"Exercice 5"
),
subtitle:
Text
(
"Affichage d'une
tuile a a partir d'une
image"
),
subtitle:
Text
(
"Affichage d'une
grille modulable de tuile a partir d'un
image"
),
onTap:
(){
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)=>
ImageGridViewTile
()));
},)),
Card
(
child:
ListTile
(
leading:
Icon
(
Icons
.
wb_sunny_outlined
),
title:
Text
(
"Exercice 6"
),
subtitle:
Text
(
"Affichage d'une tuile a a partir d'une image"
),
onTap:
(){
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)=>
PositionedTiles
()));
},))
],
...
...
lib/Exercice 5.dart
View file @
8b0b3919
...
...
@@ -68,6 +68,18 @@ class _ImageGridViewTileState extends State<ImageGridViewTile> {
return
lw
;
}
Widget
creatGridView
(
List
<
TileUp
>
_listTile
,
int
value
)
{
return
GridView
.
count
(
children:
createWidgetList
(
_listTile
,
value
),
mainAxisSpacing:
2
,
crossAxisSpacing:
2
,
crossAxisCount:
value
,
scrollDirection:
Axis
.
vertical
,
shrinkWrap:
true
,
);
}
Widget
build
(
BuildContext
context
)
{
var
mediaQueryData
=
MediaQuery
.
of
(
context
);
...
...
@@ -86,14 +98,7 @@ class _ImageGridViewTileState extends State<ImageGridViewTile> {
height:
500
,
width:
400
,
child:
Container
(
child:
GridView
.
count
(
children:
createWidgetList
(
_listTile
,
_currentSliderValue
),
mainAxisSpacing:
2
,
crossAxisSpacing:
2
,
crossAxisCount:
_currentSliderValue
,
scrollDirection:
Axis
.
vertical
,
shrinkWrap:
true
,
),
child:
creatGridView
(
_listTile
,
_currentSliderValue
)
),
),
Container
(
...
...
lib/Exercice 6.dart
View file @
8b0b3919
import
'package:flutter/material.dart'
;
import
'dart:math'
as
math
;
// ==============
// Models
// ==============
...
...
@@ -9,34 +8,36 @@ math.Random random = new math.Random();
class
Tile
{
Color
color
;
int
index
;
Tile
(
this
.
color
,
this
.
index
);
Tile
(
this
.
color
);
Tile
.
randomColor
()
{
Tile
.
randomColor
(
int
index
)
{
this
.
color
=
Color
.
fromARGB
(
255
,
random
.
nextInt
(
255
),
random
.
nextInt
(
255
),
random
.
nextInt
(
255
));
this
.
index
=
index
;
}
}
// ==============
// 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:
Padding
(
padding:
EdgeInsets
.
all
(
70.0
),
));
child:
Align
(
alignment:
Alignment
.
center
,
child:
Text
(
tile
.
index
.
toString
(),
style:
TextStyle
(
fontSize:
20
,
fontWeight:
FontWeight
.
bold
),),
)
);
}
}
...
...
@@ -48,25 +49,101 @@ class PositionedTiles extends StatefulWidget {
}
class
PositionedTilesState
extends
State
<
PositionedTiles
>
{
List
<
Widget
>
tiles
=
List
<
Widget
>.
generate
(
2
,
(
index
)
=>
TileWidget
(
Tile
.
randomColor
()));
int
indexSwap
=
0
;
GridView
createGridView
(
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
(
child:
TileWidget
(
new
Tile
(
Colors
.
white
,
0
)),
);
}
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
)));
@override
Widget
build
(
BuildContext
context
)
{
var
mediaQueryData
=
MediaQuery
.
of
(
context
);
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'Moving Tiles'
),
centerTitle:
true
,
title:
Text
(
'Exercice 6'
),
),
body:
Row
(
children:
tiles
),
floatingActionButton:
FloatingActionButton
(
child:
Icon
(
Icons
.
sentiment_very_satisfied
),
onPressed:
swapTiles
),
body:
ListView
(
scrollDirection:
Axis
.
vertical
,
shrinkWrap:
true
,
children:
[
SizedBox
(
height:
500
,
width:
400
,
child:
Container
(
child:
createGridView
(
tiles
,
_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
();
});
}),)
],)
);
}
swapTiles
()
{
swapTiles
(
int
index1
,
int
emptyIndex
)
{
setState
(()
{
tiles
.
insert
(
1
,
tiles
.
removeAt
(
0
));
print
(
"Button pressed"
);
tiles
.
insert
(
index1
,
tiles
.
removeAt
(
emptyIndex
));
if
(
index1
==
_currentSliderValue
+
emptyIndex
)
{
tiles
.
insert
(
emptyIndex
,
tiles
.
removeAt
(
index1
-
1
));
}
if
(
index1
==
emptyIndex
-
_currentSliderValue
)
{
tiles
.
insert
(
emptyIndex
,
tiles
.
removeAt
(
index1
+
1
));
}
indexSwap
=
index1
;
});
}
}
\ No newline at end of file
lib/main.dart
View file @
8b0b3919
...
...
@@ -11,7 +11,7 @@ class MyApp extends StatelessWidget {
return
MaterialApp
(
title:
'Flutter Demo'
,
theme:
ThemeData
(
primarySwatch:
Colors
.
blu
e
,
primarySwatch:
Colors
.
deepPurpl
e
,
visualDensity:
VisualDensity
.
adaptivePlatformDensity
,
),
home:
MyHomePage
(
title:
'Flutter Demo Home Page'
),
...
...
@@ -36,7 +36,6 @@ class _MyHomePageState extends State<MyHomePage> {
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
widget
.
title
),
),
body:
Center
(
...
...
pubspec.lock
View file @
8b0b3919
...
...
@@ -49,7 +49,7 @@ packages:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.
0
"
version: "1.0.
2
"
fake_async:
dependency: transitive
description:
...
...
pubspec.yaml
View file @
8b0b3919
...
...
@@ -29,6 +29,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons
:
^1.0.0
dev_dependencies
:
flutter_test
:
sdk
:
flutter
...
...
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