Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • android/org.benoitharrault.puzzlegame
1 result
Show changes
Commits on Source (2)
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.8
app.versionCode=8
app.versionName=0.0.9
app.versionCode=9
......@@ -4,6 +4,9 @@ import '../entities/tile.dart';
class Data extends ChangeNotifier {
// application configuration
int _tilesCount = 3;
// application data
List _images = [];
String _image = '';
......@@ -19,6 +22,13 @@ class Data extends ChangeNotifier {
notifyListeners();
}
int get tilesCount => _tilesCount;
set updateTilesCount(int value) {
_tilesCount = value;
notifyListeners();
}
List get images => _images;
set updateImages(List value) {
......
......@@ -12,9 +12,6 @@ import '../utils/get_images_list.dart';
class Home extends StatelessWidget {
static const String id = 'home';
int _linesCount = 4;
int _columnsCount = 4;
double _selectorImageSize = 200;
double _tipImageSize = 100;
double _tileImageSize = 80;
......@@ -84,6 +81,43 @@ class Home extends StatelessWidget {
);
}
FlatButton _buildTilesetSizeSelectorItem(Data myProvider, int value) {
BoxDecoration border =
myProvider.tilesCount == value
? BoxDecoration(
borderRadius: BorderRadius.circular(4),
border: Border.all(
color: Colors.blue[100],
width: 4,
),
)
: null;
return FlatButton(
child: Container(
padding: EdgeInsets.all(5),
decoration: border,
child: Text(value.toString()+'x'+value.toString()),
),
onPressed: () { myProvider.updateTilesCount = value; },
);
}
Container _buildTilesetSizeSelector(Data myProvider) {
return Container(
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_buildTilesetSizeSelectorItem(myProvider, 3),
_buildTilesetSizeSelectorItem(myProvider, 4),
],
),
),
);
}
Future<List<Tile>> splitImageInTiles(Data myProvider) async {
String imageAsset = getImageAssetName(myProvider.image);
Uint8List imageData = (await rootBundle.load(imageAsset))
......@@ -92,12 +126,12 @@ class Home extends StatelessWidget {
imglib.Image image = imglib.decodeImage(imageData);
int x = 0, y = 0;
int width = (image.width / _linesCount).round();
int height = (image.height / _columnsCount).round();
int width = (image.width / myProvider.tilesCount).round();
int height = (image.height / myProvider.tilesCount).round();
List<Tile> tiles = List<Tile>();
for (int i = 0; i < _linesCount; i++) {
for (int j = 0; j < _columnsCount; j++) {
for (int i = 0; i < myProvider.tilesCount; i++) {
for (int j = 0; j < myProvider.tilesCount; j++) {
tiles.add(
Tile(
Image.memory(
......@@ -136,9 +170,9 @@ class Home extends StatelessWidget {
width: 2,
),
children: [
for (var row = 0; row < _linesCount; row++)
for (var row = 0; row < myProvider.tilesCount; row++)
TableRow(children: [
for (var col = 0; col < _columnsCount; col++)
for (var col = 0; col < myProvider.tilesCount; col++)
Column(children: [tiles[tileIndex++].widget(myProvider)]),
]),
]
......@@ -236,9 +270,11 @@ class Home extends StatelessWidget {
_myProvider.image == ''
? Text('')
: IconButton(
icon: const Icon(Icons.arrow_left_outlined),
onPressed: () => resetGame(_myProvider),
),
icon: const Icon(Icons.arrow_left_outlined),
onPressed: () => resetGame(_myProvider),
)
,
_myProvider.image == '' ? _buildTilesetSizeSelector(_myProvider) : Text(''),
],
),
body: SafeArea(
......