Skip to content

applied null safety and updated to latest flutter version 3.13.7 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\Users\ehson\Downloads\flutter_windows_3.7.1-stable\flutter"
export "FLUTTER_APPLICATION_PATH=C:\Users\ehson\StudioProjects\FlutterTicTacToe"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
7 changes: 5 additions & 2 deletions lib/custom_dailog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ class CustomDialog extends StatelessWidget {
title: new Text(title),
content: new Text(content),
actions: <Widget>[
new FlatButton(
new TextButton(
onPressed: callback,
color: Colors.white,
style:ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.white),

),
child: new Text(actionText),
)
],
Expand Down
47 changes: 29 additions & 18 deletions lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class HomePage extends StatefulWidget {
}

class _HomePageState extends State<HomePage> {
List<GameButton> buttonsList;
List<GameButton>? buttonsList;
var player1;
var player2;
var activePlayer;
Expand All @@ -23,8 +23,8 @@ class _HomePageState extends State<HomePage> {
}

List<GameButton> doInit() {
player1 = new List();
player2 = new List();
player1 = [];
player2 = [];
activePlayer = 1;

var gameButtons = <GameButton>[
Expand Down Expand Up @@ -57,7 +57,7 @@ class _HomePageState extends State<HomePage> {
gb.enabled = false;
int winner = checkWinner();
if (winner == -1) {
if (buttonsList.every((p) => p.text != "")) {
if (buttonsList!.every((p) => p.text != "")) {
showDialog(
context: context,
builder: (_) => new CustomDialog("Game Tied",
Expand All @@ -70,7 +70,7 @@ class _HomePageState extends State<HomePage> {
}

void autoPlay() {
var emptyCells = new List();
var emptyCells = [];
var list = new List.generate(9, (i) => i + 1);
for (var cellID in list) {
if (!(player1.contains(cellID) || player2.contains(cellID))) {
Expand All @@ -81,8 +81,8 @@ class _HomePageState extends State<HomePage> {
var r = new Random();
var randIndex = r.nextInt(emptyCells.length-1);
var cellID = emptyCells[randIndex];
int i = buttonsList.indexWhere((p)=> p.id == cellID);
playGame(buttonsList[i]);
int i = buttonsList!.indexWhere((p)=> p.id == cellID);
playGame(buttonsList![i]);

}

Expand Down Expand Up @@ -192,33 +192,44 @@ class _HomePageState extends State<HomePage> {
childAspectRatio: 1.0,
crossAxisSpacing: 9.0,
mainAxisSpacing: 9.0),
itemCount: buttonsList.length,
itemCount: buttonsList!.length,
itemBuilder: (context, i) => new SizedBox(
width: 100.0,
height: 100.0,
child: new RaisedButton(
padding: const EdgeInsets.all(8.0),
onPressed: buttonsList[i].enabled
? () => playGame(buttonsList[i])
child: new ElevatedButton(

style:ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(buttonsList![i].bg),
padding: MaterialStateProperty.all(EdgeInsets.all(10)),
),
//padding: const EdgeInsets.all(8.0),
onPressed: buttonsList![i].enabled
? () => playGame(buttonsList![i])
: null,
child: new Text(
buttonsList[i].text,
buttonsList![i].text,
style: new TextStyle(
color: Colors.white, fontSize: 20.0),

),
color: buttonsList[i].bg,
disabledColor: buttonsList[i].bg,

//disabledColor: buttonsList[i].bg,
),
),
),
),
new RaisedButton(
new ElevatedButton(
child: new Text(
"Reset",
style: new TextStyle(color: Colors.white, fontSize: 20.0),
),
color: Colors.red,
padding: const EdgeInsets.all(20.0),
//color: Colors.red,
//padding: const EdgeInsets.all(20.0),
style:ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.redAccent),

padding: MaterialStateProperty.all(EdgeInsets.all(20)),
),
onPressed: resetGame,
)
],
Expand Down
Loading