Merge pull request #83 from flixcoo/enhance/74-organize-create-game-popups
Updated popups and refactored
This commit is contained in:
@@ -7,6 +7,14 @@ import 'package:cabo_counter/views/active_game_view.dart';
|
|||||||
import 'package:cabo_counter/views/mode_selection_view.dart';
|
import 'package:cabo_counter/views/mode_selection_view.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
|
||||||
|
enum CreateStatus {
|
||||||
|
noGameTitle,
|
||||||
|
noModeSelected,
|
||||||
|
minPlayers,
|
||||||
|
maxPlayers,
|
||||||
|
noPlayerName,
|
||||||
|
}
|
||||||
|
|
||||||
class CreateGameView extends StatefulWidget {
|
class CreateGameView extends StatefulWidget {
|
||||||
final String? gameTitle;
|
final String? gameTitle;
|
||||||
final bool? isPointsLimitEnabled;
|
final bool? isPointsLimitEnabled;
|
||||||
@@ -163,22 +171,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
.add(TextEditingController());
|
.add(TextEditingController());
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
showCupertinoDialog(
|
showFeedbackDialog(CreateStatus.maxPlayers);
|
||||||
context: context,
|
|
||||||
builder: (context) => CupertinoAlertDialog(
|
|
||||||
title: Text(AppLocalizations.of(context)
|
|
||||||
.max_players_title),
|
|
||||||
content: Text(AppLocalizations.of(context)
|
|
||||||
.max_players_message),
|
|
||||||
actions: [
|
|
||||||
CupertinoDialogAction(
|
|
||||||
child:
|
|
||||||
Text(AppLocalizations.of(context).ok),
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -237,73 +230,19 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (_gameTitleTextController.text == '') {
|
if (_gameTitleTextController.text == '') {
|
||||||
showCupertinoDialog(
|
showFeedbackDialog(CreateStatus.noGameTitle);
|
||||||
context: context,
|
|
||||||
builder: (context) => CupertinoAlertDialog(
|
|
||||||
title: Text(
|
|
||||||
AppLocalizations.of(context).no_gameTitle_title),
|
|
||||||
content: Text(
|
|
||||||
AppLocalizations.of(context).no_gameTitle_message),
|
|
||||||
actions: [
|
|
||||||
CupertinoDialogAction(
|
|
||||||
child: Text(AppLocalizations.of(context).ok),
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_isPointsLimitEnabled == null) {
|
if (_isPointsLimitEnabled == null) {
|
||||||
showCupertinoDialog(
|
showFeedbackDialog(CreateStatus.noModeSelected);
|
||||||
context: context,
|
|
||||||
builder: (context) => CupertinoAlertDialog(
|
|
||||||
title: Text(AppLocalizations.of(context).no_mode_title),
|
|
||||||
content:
|
|
||||||
Text(AppLocalizations.of(context).no_mode_message),
|
|
||||||
actions: [
|
|
||||||
CupertinoDialogAction(
|
|
||||||
child: Text(AppLocalizations.of(context).ok),
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_playerNameTextControllers.length < 2) {
|
if (_playerNameTextControllers.length < 2) {
|
||||||
showCupertinoDialog(
|
showFeedbackDialog(CreateStatus.minPlayers);
|
||||||
context: context,
|
|
||||||
builder: (context) => CupertinoAlertDialog(
|
|
||||||
title: Text(
|
|
||||||
AppLocalizations.of(context).min_players_title),
|
|
||||||
content: Text(
|
|
||||||
AppLocalizations.of(context).min_players_message),
|
|
||||||
actions: [
|
|
||||||
CupertinoDialogAction(
|
|
||||||
child: Text(AppLocalizations.of(context).ok),
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!everyPlayerHasAName()) {
|
if (!everyPlayerHasAName()) {
|
||||||
showCupertinoDialog(
|
showFeedbackDialog(CreateStatus.noPlayerName);
|
||||||
context: context,
|
|
||||||
builder: (context) => CupertinoAlertDialog(
|
|
||||||
title: Text(AppLocalizations.of(context).no_name_title),
|
|
||||||
content:
|
|
||||||
Text(AppLocalizations.of(context).no_name_message),
|
|
||||||
actions: [
|
|
||||||
CupertinoDialogAction(
|
|
||||||
child: Text(AppLocalizations.of(context).ok),
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,6 +274,60 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Displays a feedback dialog based on the [CreateStatus].
|
||||||
|
void showFeedbackDialog(CreateStatus status) {
|
||||||
|
final (title, message) = _getDialogContent(status);
|
||||||
|
|
||||||
|
showCupertinoDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return CupertinoAlertDialog(
|
||||||
|
title: Text(title),
|
||||||
|
content: Text(message),
|
||||||
|
actions: [
|
||||||
|
CupertinoDialogAction(
|
||||||
|
child: Text(AppLocalizations.of(context).ok),
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the title and message for the dialog based on the [CreateStatus].
|
||||||
|
(String, String) _getDialogContent(CreateStatus status) {
|
||||||
|
switch (status) {
|
||||||
|
case CreateStatus.noGameTitle:
|
||||||
|
return (
|
||||||
|
AppLocalizations.of(context).no_gameTitle_title,
|
||||||
|
AppLocalizations.of(context).no_gameTitle_message
|
||||||
|
);
|
||||||
|
case CreateStatus.noModeSelected:
|
||||||
|
return (
|
||||||
|
AppLocalizations.of(context).no_mode_title,
|
||||||
|
AppLocalizations.of(context).no_mode_message
|
||||||
|
);
|
||||||
|
|
||||||
|
case CreateStatus.minPlayers:
|
||||||
|
return (
|
||||||
|
AppLocalizations.of(context).min_players_title,
|
||||||
|
AppLocalizations.of(context).min_players_message
|
||||||
|
);
|
||||||
|
case CreateStatus.maxPlayers:
|
||||||
|
return (
|
||||||
|
AppLocalizations.of(context).max_players_title,
|
||||||
|
AppLocalizations.of(context).max_players_message
|
||||||
|
);
|
||||||
|
case CreateStatus.noPlayerName:
|
||||||
|
return (
|
||||||
|
AppLocalizations.of(context).no_name_title,
|
||||||
|
AppLocalizations.of(context).no_name_message
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks if every player has a name.
|
||||||
|
/// Returns true if all players have a name, false otherwise.
|
||||||
bool everyPlayerHasAName() {
|
bool everyPlayerHasAName() {
|
||||||
for (var controller in _playerNameTextControllers) {
|
for (var controller in _playerNameTextControllers) {
|
||||||
if (controller.text == '') {
|
if (controller.text == '') {
|
||||||
|
|||||||
Reference in New Issue
Block a user