@@ -161,7 +161,10 @@ class GridNotifierCubit extends StateNotifier<GridNotifierState> {
161161 int splitCol = Random ().nextInt (colEnd - colStart - 1 ) + colStart + 1 ;
162162 for (int row = rowStart; row < rowEnd; row++ ) {
163163 if (row == rowStart || row == rowEnd - 1 ) continue ; // Skip the boundary
164- gridData[row * state.columnCrossAxisCount + splitCol] = GridStatus .wall;
164+ final index = row * state.columnCrossAxisCount + splitCol;
165+ final grid = gridData[index];
166+ if (grid == GridStatus .startPoint || grid == GridStatus .targetPoint) return ;
167+ gridData[index] = GridStatus .wall;
165168 state = state.copyWith (gridData: List <GridStatus >.from (gridData));
166169 await Future .delayed (const Duration (milliseconds: 10 )); // Delay for animation
167170 }
@@ -176,7 +179,12 @@ class GridNotifierCubit extends StateNotifier<GridNotifierState> {
176179 int splitRow = Random ().nextInt (rowEnd - rowStart - 1 ) + rowStart + 1 ;
177180 for (int col = colStart; col < colEnd; col++ ) {
178181 if (col == colStart || col == colEnd - 1 ) continue ; // Skip the boundary
179- gridData[splitRow * state.columnCrossAxisCount + col] = GridStatus .wall;
182+
183+ final index = splitRow * state.columnCrossAxisCount + col;
184+ final grid = gridData[index];
185+ if (grid == GridStatus .startPoint || grid == GridStatus .targetPoint) return ;
186+ gridData[index] = GridStatus .wall;
187+
180188 state = state.copyWith (gridData: List <GridStatus >.from (gridData));
181189 await Future .delayed (const Duration (milliseconds: 10 )); // Delay for animation
182190 }
0 commit comments