Refactoring & dispose updated
This commit is contained in:
@@ -33,11 +33,11 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
final int maxPlayers = 5;
|
final int maxPlayers = 5;
|
||||||
|
|
||||||
/// Variable to store the selected game mode.
|
/// Variable to store the selected game mode.
|
||||||
bool? selectedMode;
|
bool? _isPointsLimitEnabled;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
selectedMode = widget.isPointsLimitEnabled;
|
_isPointsLimitEnabled = widget.isPointsLimitEnabled;
|
||||||
_gameTitleTextController.text = widget.gameTitle ?? '';
|
_gameTitleTextController.text = widget.gameTitle ?? '';
|
||||||
if (widget.players != null) {
|
if (widget.players != null) {
|
||||||
_playerNameTextControllers = [];
|
_playerNameTextControllers = [];
|
||||||
@@ -91,9 +91,9 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
suffix: Row(
|
suffix: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
selectedMode == null
|
_isPointsLimitEnabled == null
|
||||||
? AppLocalizations.of(context).select_mode
|
? AppLocalizations.of(context).select_mode
|
||||||
: (selectedMode!
|
: (_isPointsLimitEnabled!
|
||||||
? '${Globals.pointLimit} ${AppLocalizations.of(context).points}'
|
? '${Globals.pointLimit} ${AppLocalizations.of(context).points}'
|
||||||
: AppLocalizations.of(context).unlimited),
|
: AppLocalizations.of(context).unlimited),
|
||||||
),
|
),
|
||||||
@@ -102,7 +102,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final selected = await Navigator.push(
|
final selectedMode = await Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (context) => ModeSelectionMenu(
|
builder: (context) => ModeSelectionMenu(
|
||||||
@@ -111,9 +111,9 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (selected != null) {
|
if (selectedMode != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
selectedMode = selected;
|
_isPointsLimitEnabled = selectedMode;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -252,7 +252,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (selectedMode == null) {
|
if (_isPointsLimitEnabled == null) {
|
||||||
showCupertinoDialog(
|
showCupertinoDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => CupertinoAlertDialog(
|
builder: (context) => CupertinoAlertDialog(
|
||||||
@@ -315,7 +315,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
players: players,
|
players: players,
|
||||||
pointLimit: Globals.pointLimit,
|
pointLimit: Globals.pointLimit,
|
||||||
caboPenalty: Globals.caboPenalty,
|
caboPenalty: Globals.caboPenalty,
|
||||||
isPointsLimitEnabled: selectedMode!,
|
isPointsLimitEnabled: _isPointsLimitEnabled!,
|
||||||
);
|
);
|
||||||
final index = await gameManager.addGameSession(gameSession);
|
final index = await gameManager.addGameSession(gameSession);
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
@@ -343,6 +343,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
_gameTitleTextController.dispose();
|
||||||
for (var controller in _playerNameTextControllers) {
|
for (var controller in _playerNameTextControllers) {
|
||||||
controller.dispose();
|
controller.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user