Commit 7c849a6c authored by Benjamin LEROUX's avatar Benjamin LEROUX

exo6 taille variable

parent aee7978f
......@@ -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=size*size;
int max=slide.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%size!=0){
}else if(current==empty-1 && empty%_currentSlideValue!=0){
emptyIndex=current;
tiles.insert(empty, tiles.removeAt(current));
}
else if(current==empty+size){
else if(current==empty+_currentSlideValue){
emptyIndex=current;
tiles.insert(current, tiles.removeAt(empty));
tiles.insert(empty, tiles.removeAt(current-1));
}else if(current==empty-size){
}else if(current==empty-_currentSlideValue){
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
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