Skip to content

Commit 3d88756

Browse files
reformat the code
1 parent c11dfe7 commit 3d88756

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

lib/features/grid/view_model/grid_notifier.dart renamed to lib/features/searching/view_model/grid_notifier.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class MazeDirection {
1818
static const right = MazeDirection._(0, 1);
1919
}
2020

21-
class GridNotifierCubit extends StateNotifier<GridNotifierState> {
22-
GridNotifierCubit() : super(GridNotifierState());
23-
final int columnSquares = 20;
21+
class SearchingNotifier extends StateNotifier<GridNotifierState> {
22+
SearchingNotifier() : super(GridNotifierState());
23+
final int columnSquares = 40;
2424
static const Duration scaleAppearDurationForWall = Duration(milliseconds: 700);
2525
static const Duration clearDuration = Duration(microseconds: 1);
2626
static const Duration drawFindingPathDuration = Duration(milliseconds: 2);
@@ -359,8 +359,11 @@ class GridNotifierCubit extends StateNotifier<GridNotifierState> {
359359
final newRow = row + direction.rowDelta * 2;
360360
final newCol = col + direction.colDelta * 2;
361361

362+
final currentGrid = gridData[newRow * state.columnCrossAxisCount + newCol];
362363
if (_isValidCell(newRow, newCol) &&
363-
gridData[newRow * state.columnCrossAxisCount + newCol] == GridStatus.empty) {
364+
currentGrid == GridStatus.empty &&
365+
currentGrid != GridStatus.startPoint &&
366+
currentGrid != GridStatus.targetPoint) {
364367
gridData[(row + direction.rowDelta) * state.columnCrossAxisCount + (col + direction.colDelta)] =
365368
GridStatus.wall;
366369
gridData[newRow * state.columnCrossAxisCount + newCol] = GridStatus.wall;

lib/features/grid/view_model/grid_notifier_state.dart renamed to lib/features/searching/view_model/grid_notifier_state.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ final class GridNotifierState {
4242
List<GridStatus>? gridData,
4343
int? currentTappedIndex,
4444
}) {
45+
4546
return GridNotifierState(
46-
columnCrossAxisCount: columnCrossAxisCount ?? this.columnCrossAxisCount,
47-
rowMainAxisCount: rowMainAxisCount ?? this.rowMainAxisCount,
48-
gridSize: gridSize ?? this.gridSize,
49-
gridCount: gridCount ?? this.gridCount,
50-
screenHeight: screenHeight ?? this.screenHeight,
51-
screenWidth: screenWidth ?? this.screenWidth,
52-
gridData: gridData ?? this.gridData,
53-
currentTappedIndex: currentTappedIndex ?? this.currentTappedIndex,
47+
columnCrossAxisCount: columnCrossAxisCount!=this.columnCrossAxisCount?(columnCrossAxisCount ?? this.columnCrossAxisCount):this.columnCrossAxisCount,
48+
rowMainAxisCount: rowMainAxisCount!=this.rowMainAxisCount?(rowMainAxisCount ?? this.rowMainAxisCount):this.rowMainAxisCount,
49+
gridSize: gridSize!=this.gridSize?(gridSize ?? this.gridSize):this.gridSize,
50+
gridCount: gridCount!=this.gridCount?(gridCount ?? this.gridCount):this.gridCount,
51+
screenHeight: screenHeight!=this.screenHeight?(screenHeight ?? this.screenHeight):this.screenHeight,
52+
screenWidth: screenWidth!=this.screenWidth?(screenWidth ?? this.screenWidth):this.screenWidth,
53+
gridData: gridData!=this.gridData?(gridData ?? this.gridData):this.gridData,
54+
currentTappedIndex: currentTappedIndex!=this.currentTappedIndex?(currentTappedIndex ?? this.currentTappedIndex):this.currentTappedIndex,
5455
);
5556
}
5657
}

0 commit comments

Comments
 (0)