Created
January 15, 2019 06:10
-
-
Save deven98/a8aff24bebec5aef06eae95a4430b384 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GridView.builder( | |
shrinkWrap: true, | |
physics: NeverScrollableScrollPhysics(), | |
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( | |
crossAxisCount: columnCount, | |
), | |
itemBuilder: (context, position) { | |
// Get row and column number of square | |
int rowNumber = (position / columnCount).floor(); | |
int columnNumber = (position % columnCount); | |
Image image; | |
if (openedSquares[position] == false) { | |
if (flaggedSquares[position] == true) { | |
image = getImage(ImageType.flagged); | |
} else { | |
image = getImage(ImageType.facingDown); | |
} | |
} else { | |
if (board[rowNumber][columnNumber].hasBomb) { | |
image = getImage(ImageType.bomb); | |
} else { | |
image = getImage( | |
getImageTypeFromNumber( | |
board[rowNumber][columnNumber].bombsAround), | |
); | |
} | |
} | |
return InkWell( | |
// Opens square | |
onTap: () { | |
if (board[rowNumber][columnNumber].hasBomb) { | |
_handleGameOver(); | |
} | |
if (board[rowNumber][columnNumber].bombsAround == 0) { | |
_handleTap(rowNumber, columnNumber); | |
} else { | |
setState(() { | |
openedSquares[position] = true; | |
squaresLeft = squaresLeft - 1; | |
}); | |
} | |
if(squaresLeft <= bombCount) { | |
_handleWin(); | |
} | |
}, | |
// Flags square | |
onLongPress: () { | |
if (openedSquares[position] == false) { | |
setState(() { | |
flaggedSquares[position] = true; | |
}); | |
} | |
}, | |
splashColor: Colors.grey, | |
child: Container( | |
color: Colors.grey, | |
child: image, | |
), | |
); | |
}, | |
itemCount: rowCount * columnCount, | |
), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment