Commit 8b0b3919 authored by Lila NICKLER's avatar Lila NICKLER

Exercice 6

parent 6e0d510b
......@@ -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()));
},))
],
......
......@@ -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(
......
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
......@@ -11,7 +11,7 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
primarySwatch: Colors.deepPurple,
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(
......
......@@ -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:
......
......@@ -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
......
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