Skip to content
Snippets Groups Projects
Commit 5afa9010 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Upgrade flutter framework and dependencies, clean/update code

parent 6e724118
No related branches found
No related tags found
1 merge request!63Resolve "Upgrade flutter framework and dependencies, clean/update code"
Pipeline #2995 passed
import 'dart:async';
import '../entities/cell.dart';
import '../provider/data.dart';
class BoardAnimate {
// Start game animation: blinking tiles
static List createStartGameAnimationPatterns(Data myProvider) {
List<List> patterns = [];
......@@ -74,7 +72,7 @@ class BoardAnimate {
static void startAnimation(Data myProvider, String animationType) {
List patterns = [];
switch(animationType) {
switch (animationType) {
case 'start':
patterns = createStartGameAnimationPatterns(myProvider);
break;
......@@ -89,9 +87,8 @@ class BoardAnimate {
myProvider.updateAnimationInProgress(true);
Timer _timerAnimateBoard;
const interval = const Duration(milliseconds: 200);
_timerAnimateBoard = new Timer.periodic(
new Timer.periodic(
interval,
(Timer timer) {
if (_patternIndex == 0) {
......
......@@ -5,7 +5,6 @@ import '../provider/data.dart';
import '../utils/random_pick_grid.dart';
class BoardUtils {
static printGrid(List cells, List solvedCells) {
String stringValues = '0123456789ABCDEFG';
print('');
......@@ -24,15 +23,13 @@ class BoardUtils {
}
static Future<void> pickGrid(Data myProvider) async {
String grid;
String grid = '';
RandomPickGrid randomPickGrid;
randomPickGrid = RandomPickGrid();
await randomPickGrid.init(myProvider.level, myProvider.size);
await randomPickGrid.init(myProvider.parameterLevel, myProvider.parameterSize);
if (randomPickGrid.grid != null) {
grid = randomPickGrid.grid;
}
grid = randomPickGrid.grid;
int blockSizeHorizontal = myProvider.blockSizeHorizontal;
int blockSizeVertical = myProvider.blockSizeVertical;
......@@ -76,7 +73,7 @@ class BoardUtils {
static List createBoardFromTemplate(String grid, bool isSymetric) {
List cells = [];
int boardSize = int.parse(pow(grid.length, 1/2).toStringAsFixed(0));
int boardSize = int.parse(pow(grid.length, 1 / 2).toStringAsFixed(0));
String stringValues = '0123456789ABCDEFG';
......@@ -106,56 +103,65 @@ class BoardUtils {
print('flip board: ' + flip);
print('rotate board: ' + rotate);
switch(flip) {
case 'horizontal': {
List transformedBoard = createEmptyBoard(boardSize);
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
transformedBoard[rowIndex][colIndex].value = cells[boardSize - rowIndex - 1][colIndex].value;
switch (flip) {
case 'horizontal':
{
List transformedBoard = createEmptyBoard(boardSize);
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
transformedBoard[rowIndex][colIndex].value =
cells[boardSize - rowIndex - 1][colIndex].value;
}
}
cells = transformedBoard;
}
cells = transformedBoard;
}
break;
case 'vertical': {
List transformedBoard = createEmptyBoard(boardSize);
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
transformedBoard[rowIndex][colIndex].value = cells[rowIndex][boardSize - colIndex - 1].value;
break;
case 'vertical':
{
List transformedBoard = createEmptyBoard(boardSize);
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
transformedBoard[rowIndex][colIndex].value =
cells[rowIndex][boardSize - colIndex - 1].value;
}
}
cells = transformedBoard;
}
cells = transformedBoard;
}
break;
break;
}
switch(rotate) {
case 'left': {
List transformedBoard = createEmptyBoard(boardSize);
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
transformedBoard[rowIndex][colIndex].value = cells[colIndex][boardSize - rowIndex - 1].value;
switch (rotate) {
case 'left':
{
List transformedBoard = createEmptyBoard(boardSize);
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
transformedBoard[rowIndex][colIndex].value =
cells[colIndex][boardSize - rowIndex - 1].value;
}
}
cells = transformedBoard;
}
cells = transformedBoard;
}
break;
case 'right': {
List transformedBoard = createEmptyBoard(boardSize);
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
transformedBoard[rowIndex][colIndex].value = cells[boardSize - colIndex - 1][rowIndex].value;
break;
case 'right':
{
List transformedBoard = createEmptyBoard(boardSize);
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
transformedBoard[rowIndex][colIndex].value =
cells[boardSize - colIndex - 1][rowIndex].value;
}
}
cells = transformedBoard;
}
cells = transformedBoard;
}
break;
break;
}
// Fix cells fixed states
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
cells[rowIndex][colIndex].isFixed = (cells[rowIndex][colIndex].value != 0) ? true : false;
cells[rowIndex][colIndex].isFixed =
(cells[rowIndex][colIndex].value != 0) ? true : false;
}
}
......@@ -170,8 +176,6 @@ class BoardUtils {
int boardSize = blockSizeHorizontal * blockSizeVertical;
bool isSolved = true;
// (re)compute conflicts
BoardUtils.computeConflictsInBoard(myProvider);
......@@ -189,8 +193,9 @@ class BoardUtils {
return true;
}
static bool isValueAllowed(List cells, int blockSizeHorizontal, int blockSizeVertical, int candidateCol, int candidateRow, int candidateValue) {
if (candidateValue == 0) {
static bool isValueAllowed(List cells, int blockSizeHorizontal, int blockSizeVertical,
int? candidateCol, int? candidateRow, int candidateValue) {
if ((candidateCol == null) || (candidateRow == null) || (candidateValue == 0)) {
return true;
}
......@@ -336,7 +341,11 @@ class BoardUtils {
List distinctValues = values.toSet().toList();
if (values.length != distinctValues.length) {
print('block [' + blockCol.toString() + ',' + blockRow.toString() + '] contains duplicates');
print('block [' +
blockCol.toString() +
',' +
blockRow.toString() +
'] contains duplicates');
// Add blocks to cells in conflict
for (var rowInBlock = 0; rowInBlock < blockSizeVertical; rowInBlock++) {
for (var colInBlock = 0; colInBlock < blockSizeHorizontal; colInBlock++) {
......@@ -350,13 +359,15 @@ class BoardUtils {
}
}
static List getCellsWithWrongValue(List cells, List cellsSolved, int blockSizeHorizontal, int blockSizeVertical) {
static List getCellsWithWrongValue(
List cells, List cellsSolved, int blockSizeHorizontal, int blockSizeVertical) {
List cellsWithWrongValue = [];
int boardSize = blockSizeHorizontal * blockSizeVertical;
for (var row = 0; row < boardSize; row++) {
for (var col = 0; col < boardSize; col++) {
if (cells[row][col].value != 0 && cells[row][col].value != cellsSolved[row][col].value) {
if (cells[row][col].value != 0 &&
cells[row][col].value != cellsSolved[row][col].value) {
cellsWithWrongValue.add([col, row]);
}
}
......@@ -372,7 +383,9 @@ class BoardUtils {
for (var row = 0; row < boardSize; row++) {
for (var col = 0; col < boardSize; col++) {
if (!cells[row][col].isFixed && cells[row][col].value != 0) {
if (cells[row][col].conflictsCount != 0 && !BoardUtils.isValueAllowed(cells, blockSizeHorizontal, blockSizeVertical, col, row, cells[row][col].value)) {
if (cells[row][col].conflictsCount != 0 &&
!BoardUtils.isValueAllowed(cells, blockSizeHorizontal, blockSizeVertical, col,
row, cells[row][col].value)) {
conflictingCells.add([col, row]);
}
}
......@@ -382,7 +395,8 @@ class BoardUtils {
return conflictingCells;
}
static List getCellsWithUniqueAvailableValue(List cells, int blockSizeHorizontal, int blockSizeVertical) {
static List getCellsWithUniqueAvailableValue(
List cells, int blockSizeHorizontal, int blockSizeVertical) {
List candidateCells = [];
int boardSize = blockSizeHorizontal * blockSizeVertical;
......@@ -392,7 +406,8 @@ class BoardUtils {
int allowedValuesCount = 0;
int candidateValue = 0;
for (var value = 1; value <= boardSize; value++) {
if (BoardUtils.isValueAllowed(cells, blockSizeHorizontal, blockSizeVertical, col, row, value)) {
if (BoardUtils.isValueAllowed(
cells, blockSizeHorizontal, blockSizeVertical, col, row, value)) {
candidateValue = value;
allowedValuesCount++;
}
......@@ -413,7 +428,8 @@ class BoardUtils {
int blockSizeVertical = myProvider.blockSizeVertical;
do {
List cellsWithUniqueAvailableValue = BoardUtils.getCellsWithUniqueAvailableValue(cells, blockSizeHorizontal, blockSizeVertical);
List cellsWithUniqueAvailableValue = BoardUtils.getCellsWithUniqueAvailableValue(
cells, blockSizeHorizontal, blockSizeVertical);
if (cellsWithUniqueAvailableValue.length == 0) {
break;
}
......@@ -427,5 +443,4 @@ class BoardUtils {
return cells;
}
}
import '../provider/data.dart';
import '../utils/board_animate.dart';
import '../utils/board_utils.dart';
import '../utils/game_utils.dart';
class GameUtils {
static Future<void> resetGame(Data myProvider) async {
myProvider.updateGameIsRunning(false);
}
static Future<void> startGame(Data myProvider) async {
myProvider.updateSize(myProvider.size);
myProvider.updateParameterSize(myProvider.parameterSize);
myProvider.updateGameIsRunning(true);
myProvider.resetGivenTipsCount();
myProvider.shuffleCellValues();
myProvider.updateCells(BoardUtils.createEmptyBoard(myProvider.blockSizeHorizontal * myProvider.blockSizeVertical));
myProvider.updateCells(BoardUtils.createEmptyBoard(
myProvider.blockSizeHorizontal * myProvider.blockSizeVertical));
BoardUtils.pickGrid(myProvider);
BoardAnimate.startAnimation(myProvider, 'start');
}
......@@ -36,21 +35,24 @@ class GameUtils {
int blockSizeVertical = myProvider.blockSizeVertical;
// pick one of wrong value cells, if found
List wrongValueCells = BoardUtils.getCellsWithWrongValue(cells, myProvider.cellsSolved, blockSizeHorizontal, blockSizeVertical);
List wrongValueCells = BoardUtils.getCellsWithWrongValue(
cells, myProvider.cellsSolved, blockSizeHorizontal, blockSizeVertical);
if (wrongValueCells.length != 0) {
GameUtils.pickRandomFromList(myProvider, wrongValueCells);
return;
}
// pick one of conflicting cells, if found
List conflictingCells = BoardUtils.getCellsWithUniqueAvailableValue(cells, blockSizeHorizontal, blockSizeVertical);
List conflictingCells = BoardUtils.getCellsWithUniqueAvailableValue(
cells, blockSizeHorizontal, blockSizeVertical);
if (conflictingCells.length != 0) {
GameUtils.pickRandomFromList(myProvider, conflictingCells);
return;
}
// pick one form cells with unique non-conflicting candidate value
List candidateCells = BoardUtils.getCellsWithUniqueAvailableValue(cells, blockSizeHorizontal, blockSizeVertical);
List candidateCells = BoardUtils.getCellsWithUniqueAvailableValue(
cells, blockSizeHorizontal, blockSizeVertical);
if (candidateCells.length != 0) {
GameUtils.pickRandomFromList(myProvider, candidateCells);
return;
......@@ -78,17 +80,18 @@ class GameUtils {
// ensure there is only one eligible value for this cell
int allowedValuesCount = 0;
for (var value = 1; value <= boardSize; value++) {
if (BoardUtils.isValueAllowed(cells, blockSizeHorizontal, blockSizeVertical, myProvider.currentCellCol, myProvider.currentCellRow, value)) {
if (BoardUtils.isValueAllowed(cells, blockSizeHorizontal, blockSizeVertical,
myProvider.currentCellCol, myProvider.currentCellRow, value)) {
allowedValuesCount++;
eligibleValue = value;
}
}
myProvider.updateCellValue(myProvider.currentCellCol, myProvider.currentCellRow, allowedValuesCount == 1 ? eligibleValue : 0);
myProvider.updateCellValue(myProvider.currentCellCol, myProvider.currentCellRow,
allowedValuesCount == 1 ? eligibleValue : 0);
myProvider.selectCell(null, null);
if (BoardUtils.checkBoardIsSolved(myProvider)) {
BoardAnimate.startAnimation(myProvider, 'win');
}
}
}
......@@ -4,27 +4,27 @@ import 'package:flutter/services.dart';
class RandomPickGrid {
RandomPickGrid();
String _grid;
String _grid = '';
init(String difficulty, String size) async {
init(String level, String size) async {
_grid = '';
await gridFromLocalFile(difficulty, size);
await gridFromLocalFile(level, size);
}
Future<void> gridFromLocalFile(String difficulty, String size) async {
Future<void> gridFromLocalFile(String level, String size) async {
// Get global grids list
List grids;
List grids = [];
try {
String jsonString = await rootBundle.loadString('assets/files/templates.json');
final jsonResponse = await json.decode(jsonString);
grids = jsonResponse['templates'][size][difficulty];
grids = jsonResponse['templates'][size][level];
} catch (e) {
print("$e");
}
// Check we have enough grids
if (grids.length < 1) {
print('Not enough grids [' + size + ', ' + difficulty + '] in templates.');
print('Not enough grids [' + size + ', ' + level + '] in templates.');
}
// Randomize grids list
......
......@@ -14,7 +14,7 @@ packages:
name: badges
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.0.3"
boolean_selector:
dependency: transitive
description:
......@@ -63,7 +63,7 @@ packages:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
version: "2.0.1"
file:
dependency: transitive
description:
......@@ -127,7 +127,7 @@ packages:
name: overlay_support
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
version: "2.0.1"
path:
dependency: transitive
description:
......@@ -141,21 +141,21 @@ packages:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.5"
version: "2.1.7"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.4"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
version: "2.1.0"
platform:
dependency: transitive
description:
......@@ -183,42 +183,42 @@ packages:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.2"
version: "6.0.3"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
version: "2.0.15"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
version: "2.0.12"
shared_preferences_ios:
dependency: transitive
description:
name: shared_preferences_ios
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.10"
version: "2.1.1"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
shared_preferences_macos:
dependency: transitive
description:
name: shared_preferences_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.4"
shared_preferences_platform_interface:
dependency: transitive
description:
......@@ -232,14 +232,14 @@ packages:
name: shared_preferences_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.4"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
sky_engine:
dependency: transitive
description: flutter
......@@ -300,7 +300,7 @@ packages:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
version: "2.7.0"
xdg_directories:
dependency: transitive
description:
......@@ -309,5 +309,5 @@ packages:
source: hosted
version: "0.2.0+1"
sdks:
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.8.0"
dart: ">=2.17.0 <3.0.0"
flutter: ">=3.0.0"
......@@ -4,7 +4,7 @@ publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.16.1 <3.0.0"
dependencies:
flutter:
......@@ -12,7 +12,7 @@ dependencies:
provider: ^6.0.2
badges: ^2.0.1
shared_preferences: ^2.0.6
overlay_support: ^1.0.0
overlay_support: ^2.0.1
dev_dependencies:
flutter_test:
......
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:sudoku/main.dart';
void main() {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment