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
Select Git revision

Target

Select target project
  • android/org.benoitharrault.sudoku
1 result
Select Git revision
Show changes
Commits on Source (8)
Showing
with 200 additions and 207 deletions
image: ghcr.io/cirruslabs/flutter:latest image: ghcr.io/cirruslabs/flutter:latest
stages: stages:
- update
- build-debug - build-debug
- build-release - build-release
- release - release
- deploy - deploy
update:
stage: update
except:
- tags
script:
- flutter packages get
- flutter packages upgrade
interruptible: true
android:build-debug: android:build-debug:
stage: build-debug stage: build-debug
except: except:
- tags - tags
- master
script: script:
# Flutter local configuration # Flutter local configuration
- echo flutter.sdk=$FLUTTER_PATH > android/local.properties - echo flutter.sdk=$FLUTTER_PATH > android/local.properties
...@@ -49,8 +40,6 @@ android:build-release: ...@@ -49,8 +40,6 @@ android:build-release:
- master - master
except: except:
- tags - tags
dependencies:
- android:build-debug
script: script:
# Flutter local configuration # Flutter local configuration
- echo flutter.sdk=$FLUTTER_PATH > android/local.properties - echo flutter.sdk=$FLUTTER_PATH > android/local.properties
...@@ -121,4 +110,4 @@ android:deploy: ...@@ -121,4 +110,4 @@ android:deploy:
dependencies: dependencies:
- application:release - application:release
script: script:
- curl "${REPOSITORY_UPDATE_WEBHOOK}?token=${REPOSITORY_TOKEN}" - curl "${REPOSITORY_UPDATE_WEBHOOK}?token=${REPOSITORY_TOKEN}" --fail
include: package:flutter_lints/flutter.yaml
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}
def localProperties = new Properties() def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties') def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) { if (localPropertiesFile.exists()) {
...@@ -14,11 +20,6 @@ if (gradlePropertiesFile.exists()) { ...@@ -14,11 +20,6 @@ if (gradlePropertiesFile.exists()) {
} }
} }
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def appVersionCode = gradleProperties.getProperty('app.versionCode') def appVersionCode = gradleProperties.getProperty('app.versionCode')
if (appVersionCode == null) { if (appVersionCode == null) {
appVersionCode = '1' appVersionCode = '1'
...@@ -29,9 +30,6 @@ if (appVersionName == null) { ...@@ -29,9 +30,6 @@ if (appVersionName == null) {
appVersionName = '1.0' appVersionName = '1.0'
} }
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties() def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties') def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) { if (keystorePropertiesFile.exists()) {
...@@ -44,7 +42,7 @@ android { ...@@ -44,7 +42,7 @@ android {
defaultConfig { defaultConfig {
applicationId "org.benoitharrault.sudoku" applicationId "org.benoitharrault.sudoku"
minSdkVersion 16 minSdkVersion flutter.minSdkVersion
targetSdkVersion 30 targetSdkVersion 30
versionCode appVersionCode.toInteger() versionCode appVersionCode.toInteger()
versionName appVersionName versionName appVersionName
......
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
}
}
allprojects { allprojects {
repositories { repositories {
google() google()
jcenter() mavenCentral()
} }
} }
......
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.1.12 app.versionName=0.1.16
app.versionCode=61 app.versionCode=65
include ':app' pluginManagement {
def flutterSdkPath = {
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties() def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
def flutterSdkPath = properties.getProperty("flutter.sdk") def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties" assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" return flutterSdkPath
}
settings.ext.flutterSdkPath = flutterSdkPath()
includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.2.2" apply false
id "org.jetbrains.kotlin.android" version "1.9.22" apply false
}
include ":app"
Add automatic flutter linter. Apply code lints. Update dependencies.
Update flutter gradle plugin.
Avoid print calls in production code.
Improve CI/CD, remove "update" step, disable "build-debug" in master branch.
Ajout d'un correcteur automatique de code. Application des corrections. Mise à jour des dépendances.
Mise à jour du plugin gradle pour flutter.
Supprime les appels à print dans le code de production.
Amélioration de la CI/CD. Suppression de "update" et désactivation de "build-debug" sur master.
...@@ -5,15 +5,15 @@ import sys ...@@ -5,15 +5,15 @@ import sys
from random import randint, shuffle from random import randint, shuffle
if (len(sys.argv) != 3): if (len(sys.argv) != 3):
print('Usage: generate.py block-size difficulty') printlog('Usage: generate.py block-size difficulty')
print('block-size: [2x2|3x2|3x3|4x4]') printlog('block-size: [2x2|3x2|3x3|4x4]')
print('difficulty: [easy|medium|hard|nightmare]') printlog('difficulty: [easy|medium|hard|nightmare]')
exit() exit()
blocksize, difficulty = sys.argv[1], sys.argv[2] blocksize, difficulty = sys.argv[1], sys.argv[2]
if blocksize not in ['2x2', '3x2', '3x3', '4x4']: if blocksize not in ['2x2', '3x2', '3x3', '4x4']:
print('wrong size given') printlog('wrong size given')
exit() exit()
splitted_blocksize = blocksize.split('x') splitted_blocksize = blocksize.split('x')
...@@ -23,7 +23,7 @@ size_vertical = int(splitted_blocksize[1]) ...@@ -23,7 +23,7 @@ size_vertical = int(splitted_blocksize[1])
boardSize = size_horizontal * size_vertical boardSize = size_horizontal * size_vertical
if difficulty not in ['easy', 'medium', 'hard', 'nightmare']: if difficulty not in ['easy', 'medium', 'hard', 'nightmare']:
print('wrong difficulty given') printlog('wrong difficulty given')
exit() exit()
debugFillGrid = False debugFillGrid = False
......
...@@ -14,14 +14,14 @@ ...@@ -14,14 +14,14 @@
import sys import sys
if (len(sys.argv) != 3): if (len(sys.argv) != 3):
print('Usage: solve.py block-size grid') printlog('Usage: solve.py block-size grid')
print('block-size: [2x2|3x2|3x3|4x4]') printlog('block-size: [2x2|3x2|3x3|4x4]')
exit() exit()
blocksize, gridTemplate = sys.argv[1], sys.argv[2] blocksize, gridTemplate = sys.argv[1], sys.argv[2]
if blocksize not in ['2x2', '3x2', '3x3', '4x4']: if blocksize not in ['2x2', '3x2', '3x3', '4x4']:
print('wrong size given') printlog('wrong size given')
exit() exit()
splitted_blocksize = blocksize.split('x') splitted_blocksize = blocksize.split('x')
...@@ -31,7 +31,7 @@ size_vertical = int(splitted_blocksize[1]) ...@@ -31,7 +31,7 @@ size_vertical = int(splitted_blocksize[1])
boardSize = size_horizontal * size_vertical boardSize = size_horizontal * size_vertical
if (len(gridTemplate) != boardSize * boardSize): if (len(gridTemplate) != boardSize * boardSize):
print('wrong grid length (should be ' + str(boardSize * boardSize) + ')') printlog('wrong grid length (should be ' + str(boardSize * boardSize) + ')')
exit() exit()
debugSolveGrid = False debugSolveGrid = False
...@@ -112,7 +112,7 @@ def hasConflict(grid, size_horizontal, size_vertical): ...@@ -112,7 +112,7 @@ def hasConflict(grid, size_horizontal, size_vertical):
if value != 0: if value != 0:
values.append(value) values.append(value)
if containsDuplicates(values): if containsDuplicates(values):
# print('Horizontal conflict found') # printlog('Horizontal conflict found')
return True return True
# Check vertical conflicts # Check vertical conflicts
...@@ -123,7 +123,7 @@ def hasConflict(grid, size_horizontal, size_vertical): ...@@ -123,7 +123,7 @@ def hasConflict(grid, size_horizontal, size_vertical):
if value != 0: if value != 0:
values.append(value) values.append(value)
if containsDuplicates(values): if containsDuplicates(values):
# print('Vertical conflict found') # printlog('Vertical conflict found')
return True return True
# Check sub-blocks conflicts # Check sub-blocks conflicts
...@@ -139,7 +139,7 @@ def hasConflict(grid, size_horizontal, size_vertical): ...@@ -139,7 +139,7 @@ def hasConflict(grid, size_horizontal, size_vertical):
if value != 0: if value != 0:
values.append(value) values.append(value)
if containsDuplicates(values): if containsDuplicates(values):
# print('Sub-block conflict found') # printlog('Sub-block conflict found')
return True return True
return False return False
...@@ -176,18 +176,18 @@ def solve(grid, size_horizontal, size_vertical): ...@@ -176,18 +176,18 @@ def solve(grid, size_horizontal, size_vertical):
break break
if debugSolveGrid: if debugSolveGrid:
print('===================================') printlog('===================================')
print('Iteration: ' + str(iterations)) printlog('Iteration: ' + str(iterations))
# Get first/next cell with only one allowed value # Get first/next cell with only one allowed value
candidates = [] candidates = []
if debugSolveGrid: if debugSolveGrid:
print('Searching for empty cells...') printlog('Searching for empty cells...')
for row in range(len(grid)): for row in range(len(grid)):
for col in range(len(grid[row])): for col in range(len(grid[row])):
if grid[row][col] == 0: if grid[row][col] == 0:
if debugSolveGrid: if debugSolveGrid:
print( printlog(
'Found empty cell [' + str(col) + ',' + str(row) + ']') 'Found empty cell [' + str(col) + ',' + str(row) + ']')
candidates.append([row, col]) candidates.append([row, col])
...@@ -198,16 +198,16 @@ def solve(grid, size_horizontal, size_vertical): ...@@ -198,16 +198,16 @@ def solve(grid, size_horizontal, size_vertical):
allowedValues = findAllowedValuesForCell( allowedValues = findAllowedValuesForCell(
grid, size_horizontal, size_vertical, candidateRow, candidateCol) grid, size_horizontal, size_vertical, candidateRow, candidateCol)
if debugSolveGrid: if debugSolveGrid:
print('Allowed values for cell [' + str(candidateCol) + ',' + str( printlog('Allowed values for cell [' + str(candidateCol) + ',' + str(
candidateRow) + ']: ' + str(allowedValues)) candidateRow) + ']: ' + str(allowedValues))
if len(allowedValues) != 1: if len(allowedValues) != 1:
if debugSolveGrid: if debugSolveGrid:
print(' Non unique allowed value for cell. Skip to next cell') printlog(' Non unique allowed value for cell. Skip to next cell')
else: else:
value = allowedValues[0] value = allowedValues[0]
grid[candidateRow][candidateCol] = value grid[candidateRow][candidateCol] = value
if debugSolveGrid: if debugSolveGrid:
print(' Found unique allowed value for cell [' + str( printlog(' Found unique allowed value for cell [' + str(
candidateCol) + ',' + str(candidateRow) + ']: ' + str(value)) candidateCol) + ',' + str(candidateRow) + ']: ' + str(value))
drawGrid(grid) drawGrid(grid)
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../provider/data.dart'; import 'package:sudoku/provider/data.dart';
import '../utils/board_animate.dart'; import 'package:sudoku/utils/board_animate.dart';
import '../utils/board_utils.dart'; import 'package:sudoku/utils/board_utils.dart';
class Cell { class Cell {
int value; int value;
...@@ -20,18 +20,18 @@ class Cell { ...@@ -20,18 +20,18 @@ class Cell {
* Build widget for board cell, with interactions * Build widget for board cell, with interactions
*/ */
Container widget(Data myProvider, int row, int col) { Container widget(Data myProvider, int row, int col) {
String imageAsset = this.getImageAssetName(myProvider); final String imageAsset = getImageAssetName(myProvider);
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: this.getBackgroundColor(myProvider), color: getBackgroundColor(myProvider),
border: this.getCellBorders(myProvider, row, col), border: getCellBorders(myProvider, row, col),
), ),
child: GestureDetector( child: GestureDetector(
child: AnimatedSwitcher( child: AnimatedSwitcher(
duration: const Duration(milliseconds: 100), duration: const Duration(milliseconds: 100),
transitionBuilder: (Widget child, Animation<double> animation) { transitionBuilder: (Widget child, Animation<double> animation) {
return ScaleTransition(child: child, scale: animation); return ScaleTransition(scale: animation, child: child);
}, },
child: Image( child: Image(
image: AssetImage(imageAsset), image: AssetImage(imageAsset),
...@@ -54,22 +54,22 @@ class Cell { ...@@ -54,22 +54,22 @@ class Cell {
* Build widget for select/update value cell, with interactions * Build widget for select/update value cell, with interactions
*/ */
Container widgetUpdateValue(Data myProvider) { Container widgetUpdateValue(Data myProvider) {
if (this.value < 0) { if (value < 0) {
return Container(); return Container();
} }
String imageAsset = this.getImageAssetName(myProvider); final String imageAsset = getImageAssetName(myProvider);
Color backgroundColor = Colors.grey.shade200; Color backgroundColor = Colors.grey.shade200;
if (myProvider.showConflicts && if (myProvider.showConflicts &&
myProvider.currentCellCol != null && myProvider.currentCellCol != null &&
myProvider.currentCellRow != null) { myProvider.currentCellRow != null) {
List cells = myProvider.cells; final List<List<Cell>> cells = myProvider.cells;
int blockSizeHorizontal = myProvider.blockSizeHorizontal; final int blockSizeHorizontal = myProvider.blockSizeHorizontal;
int blockSizeVertical = myProvider.blockSizeVertical; final int blockSizeVertical = myProvider.blockSizeVertical;
if (!BoardUtils.isValueAllowed(cells, blockSizeHorizontal, blockSizeVertical, if (!BoardUtils.isValueAllowed(cells, blockSizeHorizontal, blockSizeVertical,
myProvider.currentCellCol, myProvider.currentCellRow, this.value)) { myProvider.currentCellCol, myProvider.currentCellRow, value)) {
backgroundColor = Colors.pink.shade100; backgroundColor = Colors.pink.shade100;
} }
} }
...@@ -87,7 +87,7 @@ class Cell { ...@@ -87,7 +87,7 @@ class Cell {
onTap: () { onTap: () {
if (myProvider.currentCellCol != null && myProvider.currentCellRow != null) { if (myProvider.currentCellCol != null && myProvider.currentCellRow != null) {
myProvider.updateCellValue( myProvider.updateCellValue(
myProvider.currentCellCol, myProvider.currentCellRow, this.value); myProvider.currentCellCol, myProvider.currentCellRow, value);
} }
myProvider.selectCell(null, null); myProvider.selectCell(null, null);
if (BoardUtils.checkBoardIsSolved(myProvider)) { if (BoardUtils.checkBoardIsSolved(myProvider)) {
...@@ -101,51 +101,49 @@ class Cell { ...@@ -101,51 +101,49 @@ class Cell {
* Compute image asset name, from skin and cell value/state * Compute image asset name, from skin and cell value/state
*/ */
String getImageAssetName(Data myProvider) { String getImageAssetName(Data myProvider) {
String imageAsset = 'assets/icons/cell_empty.png'; if (value > 0) {
if (this.value > 0) { int cellValue = myProvider.getTranslatedValueForDisplay(value);
int cellValue = myProvider.getTranslatedValueForDisplay(this.value); return 'assets/skins/${myProvider.parameterSkin}_$cellValue.png';
imageAsset =
'assets/skins/' + myProvider.parameterSkin + '_' + cellValue.toString() + '.png';
} }
return imageAsset; return 'assets/icons/cell_empty.png';
} }
// Compute cell background color, from cell state // Compute cell background color, from cell state
Color getBackgroundColor(Data myProvider) { Color getBackgroundColor(Data myProvider) {
Color editableCellColor = Colors.grey.shade100; final Color editableCellColor = Colors.grey.shade100;
Color editableCellColorConflict = Colors.pink.shade100; final Color editableCellColorConflict = Colors.pink.shade100;
Color fixedCellColor = Colors.grey.shade300; final Color fixedCellColor = Colors.grey.shade300;
Color fixedCellColorConflict = Colors.pink.shade200; final Color fixedCellColorConflict = Colors.pink.shade200;
Color editableSelectedValueColor = Colors.green.shade100; final Color editableSelectedValueColor = Colors.green.shade100;
Color fixedSelectedValueColor = Colors.green.shade300; final Color fixedSelectedValueColor = Colors.green.shade300;
Color editableAnimated = Colors.green.shade200; final Color editableAnimated = Colors.green.shade200;
Color fixedAnimated = Colors.green.shade300; final Color fixedAnimated = Colors.green.shade300;
Color backgroundColor = editableCellColor; Color backgroundColor = editableCellColor;
if (this.isFixed) { if (isFixed) {
backgroundColor = fixedCellColor; backgroundColor = fixedCellColor;
} }
if (myProvider.showConflicts && (this.conflictsCount != 0)) { if (myProvider.showConflicts && (conflictsCount != 0)) {
if (this.isFixed) { if (isFixed) {
backgroundColor = fixedCellColorConflict; backgroundColor = fixedCellColorConflict;
} else { } else {
backgroundColor = editableCellColorConflict; backgroundColor = editableCellColorConflict;
} }
} }
if (myProvider.showConflicts && (this.value == myProvider.currentCellValue)) { if (myProvider.showConflicts && (value == myProvider.currentCellValue)) {
if (this.isFixed) { if (isFixed) {
backgroundColor = fixedSelectedValueColor; backgroundColor = fixedSelectedValueColor;
} else { } else {
backgroundColor = editableSelectedValueColor; backgroundColor = editableSelectedValueColor;
} }
} }
if (this.isAnimated) { if (isAnimated) {
if (this.isFixed) { if (isFixed) {
backgroundColor = fixedAnimated; backgroundColor = fixedAnimated;
} else { } else {
backgroundColor = editableAnimated; backgroundColor = editableAnimated;
...@@ -157,18 +155,18 @@ class Cell { ...@@ -157,18 +155,18 @@ class Cell {
// Compute cell borders, from board size and cell state // Compute cell borders, from board size and cell state
Border getCellBorders(Data myProvider, int row, int col) { Border getCellBorders(Data myProvider, int row, int col) {
int blockSizeHorizontal = myProvider.blockSizeHorizontal; final int blockSizeHorizontal = myProvider.blockSizeHorizontal;
int blockSizeVertical = myProvider.blockSizeVertical; final int blockSizeVertical = myProvider.blockSizeVertical;
Color cellBorderDarkColor = Colors.black; const Color cellBorderDarkColor = Colors.black;
Color cellBorderLightColor = Colors.grey; const Color cellBorderLightColor = Colors.grey;
Color cellBorderSelectedColor = Colors.red; const Color cellBorderSelectedColor = Colors.red;
Color cellBorderColor = cellBorderSelectedColor; Color cellBorderColor = cellBorderSelectedColor;
double cellBorderWidth = 4; double cellBorderWidth = 4;
// Reduce cell border width on big boards // Reduce cell border width on big boards
int boardSize = blockSizeVertical * blockSizeHorizontal; final int boardSize = blockSizeVertical * blockSizeHorizontal;
if (boardSize > 8) { if (boardSize > 8) {
cellBorderWidth = 2; cellBorderWidth = 2;
if (boardSize > 10) { if (boardSize > 10) {
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../provider/data.dart'; import 'package:sudoku/entities/cell.dart';
import 'package:sudoku/provider/data.dart';
class Board { class Board {
static Container buildGameBoard(Data myProvider) { static Container buildGameBoard(Data myProvider) {
Color borderColor = Colors.black; const Color borderColor = Colors.black;
return Container( return Container(
margin: EdgeInsets.all(2), margin: const EdgeInsets.all(2),
padding: EdgeInsets.all(2), padding: const EdgeInsets.all(2),
decoration: BoxDecoration( decoration: BoxDecoration(
color: borderColor, color: borderColor,
borderRadius: BorderRadius.circular(2), borderRadius: BorderRadius.circular(2),
...@@ -25,14 +26,14 @@ class Board { ...@@ -25,14 +26,14 @@ class Board {
); );
} }
static Table buildGameTileset(Data myProvider) { static Widget buildGameTileset(Data myProvider) {
int boardSize = myProvider.blockSizeHorizontal * myProvider.blockSizeVertical; final int boardSize = myProvider.blockSizeHorizontal * myProvider.blockSizeVertical;
List cells = myProvider.cells; final List<List<Cell>> cells = myProvider.cells;
return Table(defaultColumnWidth: IntrinsicColumnWidth(), children: [ return Table(defaultColumnWidth: const IntrinsicColumnWidth(), children: [
for (var row = 0; row < boardSize; row++) for (int row = 0; row < boardSize; row++)
TableRow(children: [ TableRow(children: [
for (var col = 0; col < boardSize; col++) for (int col = 0; col < boardSize; col++)
Column(children: [cells[row][col].widget(myProvider, row, col)]), Column(children: [cells[row][col].widget(myProvider, row, col)]),
]), ]),
]); ]);
......
...@@ -2,55 +2,53 @@ import 'dart:math'; ...@@ -2,55 +2,53 @@ import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../entities/cell.dart'; import 'package:sudoku/entities/cell.dart';
import '../layout/board.dart'; import 'package:sudoku/layout/board.dart';
import '../provider/data.dart'; import 'package:sudoku/provider/data.dart';
import '../utils/board_utils.dart'; import 'package:sudoku/utils/board_utils.dart';
import '../utils/game_utils.dart'; import 'package:sudoku/utils/game_utils.dart';
class Game { class Game {
static Container buildGameWidget(Data myProvider) { static Widget buildGameWidget(Data myProvider) {
bool gameIsFinished = BoardUtils.checkBoardIsSolved(myProvider); final bool gameIsFinished = BoardUtils.checkBoardIsSolved(myProvider);
return Container( return Column(
child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Board.buildGameBoard(myProvider), Board.buildGameBoard(myProvider),
SizedBox(height: 2), const SizedBox(height: 2),
gameIsFinished gameIsFinished
? Game.buildEndGameMessage(myProvider) ? Game.buildEndGameMessage(myProvider)
: Game.buildSelectCellValueBar(myProvider), : Game.buildSelectCellValueBar(myProvider),
], ],
),
); );
} }
static Container buildSelectCellValueBar(Data myProvider) { static Container buildSelectCellValueBar(Data myProvider) {
List cells = myProvider.cells; final List<List<Cell>> cells = myProvider.cells;
bool isCellSelected = final bool isCellSelected =
(myProvider.currentCellCol != null && myProvider.currentCellRow != null); (myProvider.currentCellCol != null && myProvider.currentCellRow != null);
bool isUpdatableCellSelected = isCellSelected final bool isUpdatableCellSelected = isCellSelected
? !cells[myProvider.currentCellRow ?? 0][myProvider.currentCellCol ?? 0].isFixed ? !cells[myProvider.currentCellRow ?? 0][myProvider.currentCellCol ?? 0].isFixed
: false; : false;
int maxValue = myProvider.blockSizeHorizontal * myProvider.blockSizeVertical; final int maxValue = myProvider.blockSizeHorizontal * myProvider.blockSizeVertical;
int maxItemsPerLine = 10; const int maxItemsPerLine = 10;
int linesCount = (maxValue / maxItemsPerLine).floor() + 1; final int linesCount = (maxValue / maxItemsPerLine).floor() + 1;
int itemsCountPerLine = min(maxItemsPerLine, maxValue + 1); final int itemsCountPerLine = min(maxItemsPerLine, maxValue + 1);
return Container( return Container(
margin: EdgeInsets.all(2), margin: const EdgeInsets.all(2),
padding: EdgeInsets.all(2), padding: const EdgeInsets.all(2),
child: Table( child: Table(
defaultColumnWidth: IntrinsicColumnWidth(), defaultColumnWidth: const IntrinsicColumnWidth(),
children: [ children: [
for (var lineIndex = 0; lineIndex < linesCount; lineIndex++) for (int lineIndex = 0; lineIndex < linesCount; lineIndex++)
TableRow( TableRow(
children: [ children: [
for (var value = lineIndex * itemsCountPerLine; for (int value = lineIndex * itemsCountPerLine;
value < (lineIndex + 1) * itemsCountPerLine; value < (lineIndex + 1) * itemsCountPerLine;
value++) value++)
Column( Column(
...@@ -67,33 +65,31 @@ class Game { ...@@ -67,33 +65,31 @@ class Game {
); );
} }
static TextButton buildRestartGameButton(Data myProvider) { static Widget buildRestartGameButton(Data myProvider) {
return TextButton( return TextButton(
child: Container( child: const Image(
child: Image(
image: AssetImage('assets/icons/button_back.png'), image: AssetImage('assets/icons/button_back.png'),
fit: BoxFit.fill, fit: BoxFit.fill,
), ),
),
onPressed: () => GameUtils.quitGame(myProvider), onPressed: () => GameUtils.quitGame(myProvider),
); );
} }
static Container buildEndGameMessage(Data myProvider) { static Container buildEndGameMessage(Data myProvider) {
Image decorationImage = Image( const Image decorationImage = Image(
image: AssetImage('assets/icons/game_win.png'), image: AssetImage('assets/icons/game_win.png'),
fit: BoxFit.fill, fit: BoxFit.fill,
); );
return Container( return Container(
margin: EdgeInsets.all(2), margin: const EdgeInsets.all(2),
padding: EdgeInsets.all(2), padding: const EdgeInsets.all(2),
child: Table( child: Table(
defaultColumnWidth: IntrinsicColumnWidth(), defaultColumnWidth: const IntrinsicColumnWidth(),
children: [ children: [
TableRow( TableRow(
children: [ children: [
Column( const Column(
children: [decorationImage], children: [decorationImage],
), ),
Column( Column(
...@@ -103,7 +99,7 @@ class Game { ...@@ -103,7 +99,7 @@ class Game {
: buildRestartGameButton(myProvider) : buildRestartGameButton(myProvider)
], ],
), ),
Column( const Column(
children: [decorationImage], children: [decorationImage],
), ),
], ],
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../provider/data.dart'; import 'package:sudoku/provider/data.dart';
import '../utils/game_utils.dart'; import 'package:sudoku/utils/game_utils.dart';
class Parameters { class Parameters {
static double separatorHeight = 2.0; static const double separatorHeight = 2.0;
static double blockMargin = 3.0; static const double blockMargin = 3.0;
static double blockPadding = 2.0; static const double blockPadding = 2.0;
static Color buttonBackgroundColor = Colors.white; static const Color buttonBackgroundColor = Colors.white;
static Color buttonBorderColorActive = Colors.blue; static const Color buttonBorderColorActive = Colors.blue;
static Color buttonBorderColorInactive = Colors.white; static const Color buttonBorderColorInactive = Colors.white;
static double buttonBorderWidth = 10.0; static const double buttonBorderWidth = 10.0;
static double buttonBorderRadius = 8.0; static const double buttonBorderRadius = 8.0;
static double buttonPadding = 0.0; static const double buttonPadding = 0.0;
static double buttonMargin = 0.0; static const double buttonMargin = 0.0;
static Container buildParametersSelector(Data myProvider) { static Widget buildParametersSelector(Data myProvider) {
List<Widget> lines = []; List<Widget> lines = [];
List parameters = myProvider.availableParameters; List<String> parameters = myProvider.availableParameters;
for (var index = 0; index < parameters.length; index++) { for (int index = 0; index < parameters.length; index++) {
lines.add(buildParameterSelector(myProvider, parameters[index])); lines.add(buildParameterSelector(myProvider, parameters[index]));
lines.add(SizedBox(height: separatorHeight)); lines.add(const SizedBox(height: separatorHeight));
} }
myProvider.loadCurrentSavedState(); myProvider.loadCurrentSavedState();
...@@ -29,12 +29,11 @@ class Parameters { ...@@ -29,12 +29,11 @@ class Parameters {
? buildResumeGameButton(myProvider) ? buildResumeGameButton(myProvider)
: buildStartNewGameButton(myProvider); : buildStartNewGameButton(myProvider);
return Container( return Column(
child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
SizedBox(height: separatorHeight), const SizedBox(height: separatorHeight),
Expanded( Expanded(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
...@@ -42,18 +41,17 @@ class Parameters { ...@@ -42,18 +41,17 @@ class Parameters {
children: lines, children: lines,
), ),
), ),
SizedBox(height: separatorHeight), const SizedBox(height: separatorHeight),
Container( Container(
child: buttonsBlock, child: buttonsBlock,
), ),
], ],
),
); );
} }
static Image buildImageWidget(String imageAssetCode) { static Image buildImageWidget(String imageAssetCode) {
return Image( return Image(
image: AssetImage('assets/icons/' + imageAssetCode + '.png'), image: AssetImage('assets/icons/$imageAssetCode.png'),
fit: BoxFit.fill, fit: BoxFit.fill,
); );
} }
...@@ -69,7 +67,7 @@ class Parameters { ...@@ -69,7 +67,7 @@ class Parameters {
children: [ children: [
TextButton( TextButton(
child: buildImageContainerWidget('placeholder'), child: buildImageContainerWidget('placeholder'),
onPressed: () => null, onPressed: () {},
), ),
], ],
); );
...@@ -77,10 +75,10 @@ class Parameters { ...@@ -77,10 +75,10 @@ class Parameters {
static Container buildStartNewGameButton(Data myProvider) { static Container buildStartNewGameButton(Data myProvider) {
return Container( return Container(
margin: EdgeInsets.all(blockMargin), margin: const EdgeInsets.all(blockMargin),
padding: EdgeInsets.all(blockPadding), padding: const EdgeInsets.all(blockPadding),
child: Table( child: Table(
defaultColumnWidth: IntrinsicColumnWidth(), defaultColumnWidth: const IntrinsicColumnWidth(),
children: [ children: [
TableRow( TableRow(
children: [ children: [
...@@ -103,10 +101,10 @@ class Parameters { ...@@ -103,10 +101,10 @@ class Parameters {
static Container buildResumeGameButton(Data myProvider) { static Container buildResumeGameButton(Data myProvider) {
return Container( return Container(
margin: EdgeInsets.all(blockMargin), margin: const EdgeInsets.all(blockMargin),
padding: EdgeInsets.all(blockPadding), padding: const EdgeInsets.all(blockPadding),
child: Table( child: Table(
defaultColumnWidth: IntrinsicColumnWidth(), defaultColumnWidth: const IntrinsicColumnWidth(),
children: [ children: [
TableRow( TableRow(
children: [ children: [
...@@ -135,18 +133,18 @@ class Parameters { ...@@ -135,18 +133,18 @@ class Parameters {
} }
static Widget buildParameterSelector(Data myProvider, String parameterCode) { static Widget buildParameterSelector(Data myProvider, String parameterCode) {
List availableValues = myProvider.getParameterAvailableValues(parameterCode); List<String> availableValues = myProvider.getParameterAvailableValues(parameterCode);
if (availableValues.length == 1) { if (availableValues.length == 1) {
return SizedBox(height: 0.0); return const SizedBox(height: 0.0);
} }
return Table( return Table(
defaultColumnWidth: IntrinsicColumnWidth(), defaultColumnWidth: const IntrinsicColumnWidth(),
children: [ children: [
TableRow( TableRow(
children: [ children: [
for (var index = 0; index < availableValues.length; index++) for (int index = 0; index < availableValues.length; index++)
Column( Column(
children: [ children: [
_buildParameterButton(myProvider, parameterCode, availableValues[index]) _buildParameterButton(myProvider, parameterCode, availableValues[index])
...@@ -163,12 +161,12 @@ class Parameters { ...@@ -163,12 +161,12 @@ class Parameters {
String currentValue = myProvider.getParameterValue(parameterCode).toString(); String currentValue = myProvider.getParameterValue(parameterCode).toString();
bool isActive = (parameterValue == currentValue); bool isActive = (parameterValue == currentValue);
String imageAsset = parameterCode + '_' + parameterValue; String imageAsset = '${parameterCode}_$parameterValue';
return TextButton( return TextButton(
child: Container( child: Container(
margin: EdgeInsets.all(buttonMargin), margin: const EdgeInsets.all(buttonMargin),
padding: EdgeInsets.all(buttonPadding), padding: const EdgeInsets.all(buttonPadding),
decoration: BoxDecoration( decoration: BoxDecoration(
color: buttonBackgroundColor, color: buttonBackgroundColor,
borderRadius: BorderRadius.circular(buttonBorderRadius), borderRadius: BorderRadius.circular(buttonBorderRadius),
......